Beispiel #1
0
        public MethodBody(MethodBase method, bool loadDebugInfo)
        {
            method.AssertNotNull();

            if (method is MethodBuilder)
            {
                Initialize(method.AssertCast <MethodBuilder>(), loadDebugInfo);
            }
            else if (method is ConstructorBuilder)
            {
                Initialize(method.AssertCast <ConstructorBuilder>(), loadDebugInfo);
            }
            else if (method is DynamicMethod)
            {
                // todo. implement reading dynamic IL
                throw AssertionHelper.Fail();
            }
            else if (method is MethodInfo)
            {
                Initialize(method.AssertCast <MethodInfo>(), loadDebugInfo);
            }
            else if (method is ConstructorInfo)
            {
                Initialize(method.AssertCast <ConstructorInfo>(), loadDebugInfo);
            }
            else
            {
                throw AssertionHelper.Fail();
            }
        }
Beispiel #2
0
        public static ILGenerator newobj(this ILGenerator il, MethodBase ctor)
        {
            if (ctor == null)
            {
                throw new ArgumentNullException("ctor");
            }

            // todo. use hackarounds (see the Hackarounds namespace nearby)!
            il.Emit(OpCodes.Newobj, ctor.AssertCast <ConstructorInfo>());
            return(il);
        }
Beispiel #3
0
        public static ILGenerator ldtoken(this ILGenerator il, MethodBase methodBase)
        {
            if (methodBase == null)
            {
                throw new ArgumentNullException("methodBase");
            }

            // todo. use hackarounds (see the Hackarounds namespace nearby)!
            il.Emit(OpCodes.Ldtoken, methodBase.AssertCast <MethodInfo>());
            return(il);
        }
Beispiel #4
0
        public static ILGenerator ld_method_info(this ILGenerator il, MethodBase methodBase)
        {
            if (methodBase == null)
            {
                throw new ArgumentNullException("methodBase");
            }

            // todo. use hackarounds (see the Hackarounds namespace nearby)!
            il.Emit(OpCodes.Ldtoken, methodBase.AssertCast <MethodInfo>());
            il.Emit(OpCodes.Ldtoken, methodBase.DeclaringType);
            il.EmitCall(OpCodes.Call, typeof(MethodBase).GetMethod("GetMethodFromHandle", new[] { typeof(RuntimeMethodHandle), typeof(RuntimeTypeHandle) }), null);

            return(il);
        }
Beispiel #5
0
 public static Type Ret(this MethodBase mi)
 {
     if (mi == null)
     {
         return(null);
     }
     if (mi is MethodInfo || mi is MethodBuilder || mi is DynamicMethod)
     {
         return(mi.AssertCast <MethodInfo>().ReturnType);
     }
     else if (mi is ConstructorBuilder || mi is ConstructorInfo)
     {
         return(typeof(void));
     }
     else
     {
         throw AssertionHelper.Fail();
     }
 }
Beispiel #6
0
 public static ILGenerator ldftn(this ILGenerator il, MethodBase mb)
 {
     il.Emit(OpCodes.Ldftn, mb.AssertCast <MethodInfo>());
     return(il);
 }