Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/10 17:12:52 (15 years ago)
Author:
epitzer
Message:

Cleanup and speed improvement of storable hooks during serialization (#1138)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs

    r3913 r3917  
    4040      BindingFlags.DeclaredOnly;
    4141
    42     private delegate void HookWrapper<T>(T o);
    4342    public delegate void Hook(object o);
    4443
     
    6766    }
    6867
    69     public static bool IsEmptyOrStorableType(Type type, bool recursive) {     
     68    public static bool IsEmptyOrStorableType(Type type, bool recursive) {
    7069      if (!HasStorableClassAttribute(type) && !IsEmptyType(type, false)) return false;
    7170      return !recursive || type.BaseType == null || IsEmptyOrStorableType(type.BaseType, true);
     
    7372
    7473    private static object[] emptyArgs = new object[0];
    75     private static Type[] objectArg = new[] { typeof(object) };
    7674
    7775    public static IEnumerable<Hook> CollectHooks(HookType hookType, Type type) {
    7876      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            }
    9287          }
    9388        }
    9489      }
     90    }
     91
     92    private static Hook CreateHook(MethodInfo methodInfo) {
     93      return new Hook((o) => methodInfo.Invoke(o, emptyArgs));
    9594    }
    9695
     
    179178    }
    180179
    181     private static Dictionary<Type, StorableClassAttribute> storableClassCache = 
     180    private static Dictionary<Type, StorableClassAttribute> storableClassCache =
    182181      new Dictionary<Type, StorableClassAttribute>();
    183182
Note: See TracChangeset for help on using the changeset viewer.