Changeset 3917 for trunk/sources
- Timestamp:
- 06/11/10 17:12:52 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
r3913 r3917 40 40 BindingFlags.DeclaredOnly; 41 41 42 private delegate void HookWrapper<T>(T o);43 42 public delegate void Hook(object o); 44 43 … … 67 66 } 68 67 69 public static bool IsEmptyOrStorableType(Type type, bool recursive) { 68 public static bool IsEmptyOrStorableType(Type type, bool recursive) { 70 69 if (!HasStorableClassAttribute(type) && !IsEmptyType(type, false)) return false; 71 70 return !recursive || type.BaseType == null || IsEmptyOrStorableType(type.BaseType, true); … … 73 72 74 73 private static object[] emptyArgs = new object[0]; 75 private static Type[] objectArg = new[] { typeof(object) };76 74 77 75 public static IEnumerable<Hook> CollectHooks(HookType hookType, Type type) { 78 76 if (type.BaseType != null) 79 foreach (var mi in CollectHooks(hookType, type.BaseType)) 80 yield return mi; 81 foreach (MemberInfo memberInfo in type.GetMembers(DECLARED_INSTANCE_MEMBERS)) { 82 if (memberInfo.MemberType != MemberTypes.Method) 83 continue; 84 MethodInfo methodInfo = memberInfo as MethodInfo; 85 if (methodInfo.ReturnType != typeof(void)) 86 continue; 87 if (methodInfo.GetParameters().Length > 0) 88 continue; 89 foreach (StorableHookAttribute hook in memberInfo.GetCustomAttributes(typeof(StorableHookAttribute), false)) { 90 if (hook != null && hook.HookType == hookType) { 91 yield return new Hook((o) => methodInfo.Invoke(o, emptyArgs)); 77 foreach (var hook in CollectHooks(hookType, type.BaseType)) 78 yield return hook; 79 if (HasStorableClassAttribute(type)) { 80 foreach (MethodInfo methodInfo in type.GetMethods(DECLARED_INSTANCE_MEMBERS)) { 81 if (methodInfo.ReturnType == typeof(void) && methodInfo.GetParameters().Length == 0) { 82 foreach (StorableHookAttribute hook in methodInfo.GetCustomAttributes(typeof(StorableHookAttribute), false)) { 83 if (hook != null && hook.HookType == hookType) { 84 yield return CreateHook(methodInfo); 85 } 86 } 92 87 } 93 88 } 94 89 } 90 } 91 92 private static Hook CreateHook(MethodInfo methodInfo) { 93 return new Hook((o) => methodInfo.Invoke(o, emptyArgs)); 95 94 } 96 95 … … 179 178 } 180 179 181 private static Dictionary<Type, StorableClassAttribute> storableClassCache = 180 private static Dictionary<Type, StorableClassAttribute> storableClassCache = 182 181 new Dictionary<Type, StorableClassAttribute>(); 183 182
Note: See TracChangeset
for help on using the changeset viewer.