diff --git a/Source/TypeHelper.cs b/Source/TypeHelper.cs
index 6592f73..a38c4b5 100644
--- a/Source/TypeHelper.cs
+++ b/Source/TypeHelper.cs
@@ -27,39 +27,39 @@ namespace Nuclex.Support {
/// Helper methods for the reflection Type class
public static class TypeHelper {
-#if !(XBOX360 || WINDOWS_PHONE)
-
- #region class MemberInfoComparer
+ #region class FieldInfoComparer
/// Determines whether member informations relate to the same member
- private class MemberInfoComparer : IEqualityComparer {
+ private class FieldInfoComparer : IEqualityComparer {
/// Default instance of the comparer
- public static readonly MemberInfoComparer Default = new MemberInfoComparer();
+ public static readonly FieldInfoComparer Default = new FieldInfoComparer();
/// Checks whether two member informations are equal
/// Informations about the left member in the comaprison
/// Informations about the right member in the comparison
/// True if the two member informations relate to the same member
- public bool Equals(MemberInfo left, MemberInfo right) {
+ public bool Equals(FieldInfo left, FieldInfo right) {
return
(left.DeclaringType == right.DeclaringType) &&
(left.Name == right.Name);
}
/// Determines the hash code of the specified member informations
- ///
+ ///
/// Member informations whose hash code will be determined
///
/// The hash code of the specified member informations
- public int GetHashCode(MemberInfo memberInfo) {
- return (memberInfo.DeclaringType.GetHashCode() ^ memberInfo.Name.GetHashCode());
+ public int GetHashCode(FieldInfo FieldInfo) {
+ return (FieldInfo.DeclaringType.GetHashCode() ^ FieldInfo.Name.GetHashCode());
}
}
#endregion // class MemberInfoComparer
+#if !(XBOX360 || WINDOWS_PHONE)
+
///
/// Returns all the fields of a type, including those defined in the type's base classes
///
@@ -104,9 +104,9 @@ namespace Nuclex.Support {
// If this class doesn't have a base, don't waste any time
if(type.BaseType != typeof(object)) {
- var fieldInfoList = new List(fieldInfos.Length * 2);
+ var fieldInfoSet = new Dictionary(FieldInfoComparer.Default);
for(int index = 0; index < fieldInfos.Length; ++index) {
- fieldInfoList.Add(fieldInfos[index]);
+ fieldInfoSet.Add(fieldInfos[index], null);
}
while(type.BaseType != typeof(object)) {
@@ -114,11 +114,12 @@ namespace Nuclex.Support {
fieldInfos = type.GetFields(bindingFlags);
for(int index = 0; index < fieldInfos.Length; ++index) {
- addIfNotExists(fieldInfoList, fieldInfos[index]);
+ addIfNotExists(fieldInfoSet, fieldInfos[index]);
}
}
- fieldInfos = fieldInfoList.ToArray();
+ fieldInfos = new FieldInfo[fieldInfoSet.Count];
+ fieldInfoSet.Keys.CopyTo(fieldInfos, 0);
}
return fieldInfos;
@@ -129,23 +130,11 @@ namespace Nuclex.Support {
///
/// List the field informations will be added to
/// Field informations that will be added to the list
- private static void addIfNotExists(IList fieldInfos, FieldInfo fieldInfo) {
- bool matchFound = false;
-
- for(int index = 0; index < fieldInfos.Count; ++index) {
- FieldInfo current = fieldInfos[index];
-
- matchFound =
- (current.DeclaringType == fieldInfo.DeclaringType) &&
- (current.Name == fieldInfo.Name);
-
- if(matchFound) {
- break;
- }
- }
-
- if(!matchFound) {
- fieldInfos.Add(fieldInfo);
+ private static void addIfNotExists(
+ IDictionary fieldInfos, FieldInfo fieldInfo
+ ) {
+ if(!fieldInfos.ContainsKey(fieldInfo)) {
+ fieldInfos.Add(fieldInfo, null);
}
}