Пример #1
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()) + ")");
 }
Пример #2
0
 public Type[] GetInterfaces()
 {
     return(SubstituteGenericParameters(ReflectionExtensions.GetInterfaces(m_type), m_type.GetGenericArguments(), m_inst));
 }
Пример #3
0
 public static string Format(ConstructorInfo constructor)
 {
     return(Format(constructor.ReflectedType) + ".ctor" + "(" + string.Join(", ", ReflectionExtensions.GetParameterTypes(constructor).Select(Format).ToArray()) + ")");
 }
Пример #4
0
 private static int GetOccurrenceCount(this Type[] ax, Type ty)
 {
     return(Array.FindAll(ax, x => Array.Exists(ReflectionExtensions.GetInterfaces(x), tx => ReflectionExtensions.Equal(tx, ty))).Length);
 }
Пример #5
0
 private static Type[] Subtract(this Type[] ax, Type[] ay)
 {
     return(Array.FindAll(ax, x => false == Array.Exists(ay, y => ReflectionExtensions.Equal(x, y))));
 }
Пример #6
0
//
//        public static Type FindEqualTypeWith(this Type type1, Type type2)
//        {
//            var baseClass = type2.FindBaseClassWith(type1);
//            var interfaze = type2.FindInterfaceWith(type1);
//
//            if(interfaze == null)
//                return baseClass;
//            if(baseClass == null || baseClass == typeof(object) || baseClass.IsAbstract)
//                return interfaze;
//            return baseClass;
//        }

        public static Type[] Intersect(this Type[] ax, Type[] ay)
        {
            return(Array.FindAll(ax, x => Array.Exists(ay, y => ReflectionExtensions.Equal(x, y))));
        }
Пример #7
0
        public static T EmitDynamicMethod <T, TTarget>(string name, Module m, Action <GroboIL> emitCode, TTarget target) where T : class
        {
            var delegateType = typeof(T);
            //HACK
            var methodInfo = delegateType.GetMethod("Invoke", BindingFlags.Public | BindingFlags.Instance);

            if (methodInfo == null)
            {
                throw new ArgumentException($"Type {delegateType} is not a Delegate");
            }

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

            using (var il = new GroboIL(dynamicMethod))
                emitCode(il);
            return(CreateDelegate <T>(dynamicMethod, target));
        }