- Timestamp:
- 05/25/09 18:04:44 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableAttribute.cs
r1852 r1893 20 20 BindingFlags.DeclaredOnly; 21 21 22 private static Dictionary<KeyValuePair<Type, bool>, IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>>> memberCache = 23 new Dictionary<KeyValuePair<Type, bool>, IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>>>(); 24 22 25 public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> GetStorableMembers(Type type) { 23 26 return GetStorableMembers(type, true); … … 26 29 public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> 27 30 GetStorableMembers(Type type, bool inherited) { 31 var query = new KeyValuePair<Type, bool>(type, inherited); 32 if (memberCache.ContainsKey(query)) 33 return memberCache[query]; 34 IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> storablesMembers = GenerateStorableMembers(type, inherited); 35 memberCache[query] = storablesMembers; 36 return storablesMembers; 37 } 38 39 public static IEnumerable<KeyValuePair<StorableAttribute, MemberInfo>> 40 GenerateStorableMembers(Type type, bool inherited) { 41 List<KeyValuePair<StorableAttribute, MemberInfo>> storableMembers = 42 new List<KeyValuePair<StorableAttribute, MemberInfo>>(); 28 43 if (inherited && type.BaseType != null) 29 foreach (var pair in GetStorableMembers(type.BaseType)) 30 yield return pair; 44 storableMembers.AddRange(GenerateStorableMembers(type.BaseType, true)); 31 45 foreach (MemberInfo memberInfo in type.GetMembers(instanceMembers)) { 32 46 foreach (object attribute in memberInfo.GetCustomAttributes(false)) { … … 34 48 attribute as StorableAttribute; 35 49 if (storableAttribute != null) { 36 yield return new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo);50 storableMembers.Add(new KeyValuePair<StorableAttribute, MemberInfo>(storableAttribute, memberInfo)); 37 51 } 38 52 } 39 53 } 54 return storableMembers; 40 55 } 41 56
Note: See TracChangeset
for help on using the changeset viewer.