Ejemplo n.º 1
0
        private static MethodInfo MakeGenericMethod(MethodInfo genericMethodDefinition, Type[] genericArguments)
        {
            ArgumentChecker.Not(!genericMethodDefinition.IsStatic, "genericMethodDefinition");
            ArgumentChecker.Not(!genericMethodDefinition.IsGenericMethodDefinition, "genericMethodDefinition");

            return(genericMethodDefinition.MakeGenericMethod(genericArguments));
        }
Ejemplo n.º 2
0
 private static Type[] GetGenericArgs(Type genericTypeDefinition, Type genericType)
 {
     ArgumentChecker.NotNull(genericType, "genericType");
     if (genericType == typeof(object))
     {
         throw new ArgumentException(string.Format("{0} doesn't provide {1}", genericType, genericTypeDefinition), "genericType");
     }
     if (genericType.IsGenericType && genericType.GetGenericTypeDefinition() == genericTypeDefinition)
     {
         return(genericType.GetGenericArguments());
     }
     foreach (var i in genericType.GetInterfaces().Concat(new[] { genericType.BaseType }))
     {
         if (i == genericType)
         {
             continue;
         }
         try
         {
             Type[] args = GetGenericArgs(genericTypeDefinition, i);
             return(args);
         }
         catch (ArgumentException)
         {
         }
     }
     throw new ArgumentException(string.Format("{0} doesn't provide {1}", genericType, genericTypeDefinition), "genericType");
 }
Ejemplo n.º 3
0
        public static object Call(MethodInfo genericMethodDefinition, Type genericTypeDefinition, params object[] args)
        {
            ArgumentChecker.Not(!genericTypeDefinition.IsGenericTypeDefinition, "genericTypeDefinition");
            ArgumentChecker.NotEmpty(args, "args");
            var genericType      = args[0].GetType();
            var genericArguments = GenericArgs.Get(genericTypeDefinition, genericType);

            return(Call(genericMethodDefinition, genericArguments, args));
        }