Skip to content

Commit 4e47c59

Browse files
committed
Throw error on duplicate
Under expected circumstances, a duplicate `MemberInfo` key should not exist. This will happen, however, if the `new` keyword is used on a member of the _current_ class (as opposed to a _derived_ class). In that case, an error will occur. This should not happen; if it does, the developer is warned about the duplicate key with a specific error message.
1 parent fb1625f commit 4e47c59

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ in type.GetMembers(
4040
BindingFlags.Public
4141
).Where(m => typeof(T).IsAssignableFrom(m.GetType()))
4242
) {
43-
Add((T)member);
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+
}
4449
}
4550
}
4651

0 commit comments

Comments
 (0)