9using System.Collections.Generic;
19 internal class PropertyComparer : Comparer<IPropertyInfo>
21 public override int Compare(IPropertyInfo x, IPropertyInfo y)
23 return StringComparer.InvariantCulture.Compare(x.Name, y.Name);
30 public static class PropertyInfoManager
32 private static object _cacheLock =
new object();
33 private static Dictionary<Type, PropertyInfoList> _propertyInfoCache;
35 private static Dictionary<Type, PropertyInfoList> PropertyInfoCache
39 if (_propertyInfoCache ==
null)
43 if (_propertyInfoCache ==
null)
44 _propertyInfoCache =
new Dictionary<Type, PropertyInfoList>();
47 return _propertyInfoCache;
51 internal static PropertyInfoList GetPropertyListCache(Type objectType)
53 var cache = PropertyInfoCache;
54 var found = cache.TryGetValue(objectType, out PropertyInfoList list);
59 found = cache.TryGetValue(objectType, out list);
62 list =
new PropertyInfoList();
63 cache.Add(objectType, list);
64 FieldDataManager.ForceStaticFieldInit(objectType);
87 internal static PropertyInfo<T> RegisterProperty<T>(Type objectType, PropertyInfo<T> info)
89 var list = GetPropertyListCache(objectType);
105 var index = list.BinarySearch(info,
new PropertyComparer());
111 list.Insert(~index, info);
129 public static PropertyInfoList GetRegisteredProperties(Type objectType)
133 var list = GetPropertyListCache(objectType);
135 return new PropertyInfoList(list);
144 public static IPropertyInfo GetRegisteredProperty(Type objectType,
string propertyName)
146 return GetRegisteredProperties(objectType).FirstOrDefault(p => p.Name == propertyName);
A strongly-typed resource class, for looking up localized strings, etc.
static string PropertyRegisterDuplicateNotAllowed
Looks up a localized string similar to Cannot register property {0}, a PropertyInfo with the same nam...
static string PropertyRegisterNotAllowed
Looks up a localized string similar to Cannot register property {0} after containing type ({1}) has b...