コード例 #1
0
ファイル: EmitHelpers.cs プロジェクト: tralivali1234/gremit
        public static T EmitDynamicMethod <T>(string name, Module m, Action <GroboIL> emitCode) where T : class
        {
            var delegateType = typeof(T);
            //HACK
            var methodInfo = delegateType.GetMethod("Invoke", BindingFlags.Public | BindingFlags.Instance);

            if (methodInfo == null)
            {
                throw new ArgumentException(String.Format("Type {0} is not a Delegate", delegateType));
            }

            var dynamicMethod = new DynamicMethod(name, methodInfo.ReturnType, ReflectionExtensions.GetParameterTypes(methodInfo), m, true);

            using (var il = new GroboIL(dynamicMethod))
                emitCode(il);
            return(CreateDelegate <T>(dynamicMethod));
        }
コード例 #2
0
 public static string Format(MethodInfo method)
 {
     if (ReferenceEquals(method.ReflectedType, null))
     {
         return(Format(ReflectionExtensions.GetReturnType(method)) + " " + FormatMethodWithoutParameters(method) + "(" + string.Join(", ", ReflectionExtensions.GetParameterTypes(method).Select(Format).ToArray()) + ")");
     }
     return(Format(ReflectionExtensions.GetReturnType(method)) + " " + Format(method.ReflectedType) + "." + FormatMethodWithoutParameters(method) + "(" + string.Join(", ", ReflectionExtensions.GetParameterTypes(method).Select(Format).ToArray()) + ")");
 }
コード例 #3
0
 public static string Format(ConstructorInfo constructor)
 {
     return(Format(constructor.ReflectedType) + ".ctor" + "(" + string.Join(", ", ReflectionExtensions.GetParameterTypes(constructor).Select(Format).ToArray()) + ")");
 }