Skip to content

Commit 13f83ec

Browse files
committed
Moved duplicate exception to InsertItem()
By overriding `InsertItem()` we ensure that the same `ArgumentException` error is thrown _anytime_ an item is added using e.g. `Add()`, `Insert()`, &c. without needing to add guard conditions to each instance, or worry about members being added independent of construction. The latter isn't an expected use case, but even without that, it prevents the need to duplicate the guard condition for both constructors.
1 parent 4e47c59 commit 13f83ec

7 files changed

Lines changed: 28 additions & 18 deletions

File tree

Ignia.Topics.Data.Caching/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1745.0")]
25-
[assembly: AssemblyFileVersion("3.5.1777.0")]
24+
[assembly: AssemblyVersion("3.5.1749.0")]
25+
[assembly: AssemblyFileVersion("3.5.1781.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("206b7f91-ca25-4e9d-9576-60d2e54a2c0a")]
2828

Ignia.Topics.Tests/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1765.0")]
25-
[assembly: AssemblyFileVersion("3.5.1813.0")]
24+
[assembly: AssemblyVersion("3.5.1769.0")]
25+
[assembly: AssemblyFileVersion("3.5.1817.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("27632801-bfe3-41d9-8678-3c4bbe45e6c9")]

Ignia.Topics.ViewModels/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1746.0")]
25-
[assembly: AssemblyFileVersion("3.5.1777.0")]
24+
[assembly: AssemblyVersion("3.5.1750.0")]
25+
[assembly: AssemblyFileVersion("3.5.1781.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("e52fc633-b4c5-4a2b-8caf-30e756d7a6a7")]
2828

Ignia.Topics.Web.Mvc/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1750.0")]
25-
[assembly: AssemblyFileVersion("3.5.1782.0")]
24+
[assembly: AssemblyVersion("3.5.1754.0")]
25+
[assembly: AssemblyFileVersion("3.5.1786.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("3b3ce34d-b5e5-47ca-bfef-e6740650f378")]

Ignia.Topics.Web/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[assembly: AssemblyTrademark("")]
2222
[assembly: AssemblyCulture("")]
2323
[assembly: ComVisible(false)]
24-
[assembly: AssemblyVersion("3.5.1744.0")]
25-
[assembly: AssemblyFileVersion("3.5.1768.0")]
24+
[assembly: AssemblyVersion("3.5.1748.0")]
25+
[assembly: AssemblyFileVersion("3.5.1772.0")]
2626
[assembly: CLSCompliant(true)]
2727
[assembly: Guid("c98f7b48-a085-4394-b820-c244f23868ce")]

Ignia.Topics/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
[assembly: AssemblyTrademark("")]
2323
[assembly: AssemblyCulture("")]
2424
[assembly: ComVisible(false)]
25-
[assembly: AssemblyVersion("3.5.1745.0")]
26-
[assembly: AssemblyFileVersion("3.5.1777.0")]
25+
[assembly: AssemblyVersion("3.5.1749.0")]
26+
[assembly: AssemblyFileVersion("3.5.1781.0")]
2727
[assembly: InternalsVisibleTo("Ignia.Topics.Tests")]
2828
[assembly: CLSCompliant(true)]
2929
[assembly: GuidAttribute("3CA9F6CB-B45A-4E74-AAA4-0C87CAA2704F")]

Ignia.Topics/Reflection/MemberInfoCollection{T}.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ in type.GetMembers(
4040
BindingFlags.Public
4141
).Where(m => typeof(T).IsAssignableFrom(m.GetType()))
4242
) {
43-
if (!Contains(member.Name)) {
44-
Add((T)member);
45-
}
46-
else {
47-
throw new ArgumentException("The Type '" + type.Name + "' already contains the MemberInfo '" + member.Name + "'");
48-
}
43+
Add((T)member);
4944
}
5045
}
5146

@@ -66,6 +61,21 @@ internal MemberInfoCollection(Type type, IEnumerable<T> members) : base(StringCo
6661
}
6762
}
6863

64+
/*==========================================================================================================================
65+
| OVERRIDE: INSERT ITEM
66+
\-------------------------------------------------------------------------------------------------------------------------*/
67+
/// <summary>
68+
/// Returns the type associated with this collection.
69+
/// </summary>
70+
protected override void InsertItem(int index, T item) {
71+
if (!Contains(item.Name)) {
72+
base.InsertItem(index, item);
73+
}
74+
else {
75+
throw new ArgumentException("The Type '" + Type.Name + "' already contains the MemberInfo '" + item.Name + "'");
76+
}
77+
}
78+
6979
/*==========================================================================================================================
7080
| PROPERTY: TYPE
7181
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)