From b1905b87743cf402d1db6d6e29fb025fa8226274 Mon Sep 17 00:00:00 2001 From: Tony THONG Date: Thu, 30 Mar 2017 23:49:30 +0200 Subject: [PATCH] Repare reflection example --- NConcern/NConcern.Example.Reflection/Program.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/NConcern/NConcern.Example.Reflection/Program.cs b/NConcern/NConcern.Example.Reflection/Program.cs index 9ac897c..6e5cc49 100644 --- a/NConcern/NConcern.Example.Reflection/Program.cs +++ b/NConcern/NConcern.Example.Reflection/Program.cs @@ -20,7 +20,8 @@ public IEnumerable Advise(MethodBase method) { var _exception = _ILGenerator.DeclareLocal(Metadata.Type); var _trace = _ILGenerator.DeclareLocal(Metadata.Type); - _ILGenerator.Emit(OpCodes.Ldtoken, method); + if (method is ConstructorInfo) { _ILGenerator.Emit(OpCodes.Ldtoken, method as ConstructorInfo); } + else { _ILGenerator.Emit(OpCodes.Ldtoken, method as MethodInfo); } _ILGenerator.Emit(OpCodes.Ldtoken, method.ReflectedType); _ILGenerator.Emit(OpCodes.Call, Metadata.Method(() => MethodBase.GetMethodFromHandle(Argument.Value, Argument.Value))); _ILGenerator.Emit(OpCodes.Ldc_I4, _parameters.Length); @@ -59,7 +60,8 @@ public IEnumerable Advise(MethodBase method) var _exception = _ILGenerator.DeclareLocal(Metadata.Type); var _trace = _ILGenerator.DeclareLocal(Metadata.Type); var _return = _ILGenerator.DeclareLocal(_type); - _ILGenerator.Emit(OpCodes.Ldtoken, method); + if (method is ConstructorInfo) { _ILGenerator.Emit(OpCodes.Ldtoken, method as ConstructorInfo); } + else { _ILGenerator.Emit(OpCodes.Ldtoken, method as MethodInfo); } _ILGenerator.Emit(OpCodes.Ldtoken, method.ReflectedType); _ILGenerator.Emit(OpCodes.Call, Metadata.Method(() => MethodBase.GetMethodFromHandle(Argument.Value, Argument.Value))); _ILGenerator.Emit(OpCodes.Ldc_I4, _parameters.Length);