Changeset 3553 for trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
- Timestamp:
- 04/28/10 11:33:38 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableReflection.cs
r3205 r3553 7 7 using HeuristicLab.Persistence.Auxiliary; 8 8 using System.Text; 9 using System.Reflection.Emit; 9 10 10 11 namespace HeuristicLab.Persistence.Default.CompositeSerializers.Storable { … … 18 19 BindingFlags.DeclaredOnly; 19 20 20 public static IEnumerable<StorableMemberInfo> GenerateStorableMembers(Type type, bool inherited) { 21 private delegate void HookWrapper<T>(T o); 22 public delegate void Hook(object o); 23 24 public static IEnumerable<StorableMemberInfo> GenerateStorableMembers(Type type) { 21 25 var storableMembers = new List<StorableMemberInfo>(); 22 if ( inherited &&type.BaseType != null)23 storableMembers.AddRange(GenerateStorableMembers(type.BaseType , true));26 if (type.BaseType != null) 27 storableMembers.AddRange(GenerateStorableMembers(type.BaseType)); 24 28 25 29 var storableClassAttribute = GetStorableClassAttribute(type); … … 47 51 } 48 52 49 public static IEnumerable< MethodInfo> CollectHooks(HookType hookType, Type type) {53 public static IEnumerable<Hook> CollectHooks(HookType hookType, Type type) { 50 54 if (type.BaseType != null) 51 55 foreach (var mi in CollectHooks(hookType, type.BaseType)) … … 56 60 MethodInfo methodInfo = memberInfo as MethodInfo; 57 61 if (memberInfo.MemberType != MemberTypes.Method || memberInfo == null) 58 throw new ArgumentException("Storable hooks must be methods"); 59 yield return methodInfo; 62 throw new ArgumentException("Storable hooks must be methods"); 63 DynamicMethod dm = new DynamicMethod("", null, new[] { typeof(object) }, type); 64 ILGenerator ilgen = dm.GetILGenerator(); 65 ilgen.Emit(OpCodes.Ldarg_1); 66 ilgen.Emit(OpCodes.Call, methodInfo); 67 ilgen.Emit(OpCodes.Ret); 68 yield return (Hook)dm.CreateDelegate(typeof(Hook)); 60 69 } 61 70 }
Note: See TracChangeset
for help on using the changeset viewer.