Пример #1
0
        public static object CreateGeneric(Type genericTypeDefinition, IList <Type> innerTypes, Func <Type, IList <object>, object> instanceCreator, params object[] args)
        {
            ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition");
            ValidationUtils.ArgumentNotNullOrEmpty <Type>(innerTypes, "innerTypes");
            ValidationUtils.ArgumentNotNull(instanceCreator, "createInstance");
            Type type = ReflectionUtils.MakeGenericType(genericTypeDefinition, innerTypes.ToArray <Type>());

            return(instanceCreator(type, args));
        }
Пример #2
0
    public static object CreateGeneric(Type genericTypeDefinition, IList<Type> innerTypes, params object[] args)
    {
      ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition");
      ValidationUtils.ArgumentNotNullOrEmpty(innerTypes, "innerTypes");

      Type specificType = MakeGenericType(genericTypeDefinition, CollectionUtils.CreateArray(innerTypes));

      return Activator.CreateInstance(specificType, args);
    }
 public static Type MakeGenericType(Type genericTypeDefinition, params Type[] innerTypes)
 {
     ValidationUtils.ArgumentNotNull(genericTypeDefinition, "genericTypeDefinition");
     ValidationUtils.ArgumentNotNullOrEmpty <Type>(innerTypes, "innerTypes");
     ValidationUtils.ArgumentConditionTrue(genericTypeDefinition.get_IsGenericTypeDefinition(), "genericTypeDefinition", "Type {0} is not a generic type definition.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
     {
         genericTypeDefinition
     }));
     return(genericTypeDefinition.MakeGenericType(innerTypes));
 }
Пример #4
0
 public static void ArgumentNotNullOrEmptyOrWhitespace(string value, string parameterName)
 {
     ValidationUtils.ArgumentNotNullOrEmpty(value, parameterName);
     if (StringUtils.IsWhiteSpace(value))
     {
         throw new ArgumentException("'{0}' cannot only be whitespace.".FormatWith(CultureInfo.InvariantCulture, new object[]
         {
             parameterName
         }), parameterName);
     }
 }
 public static void ArgumentNotNullOrEmpty(ICollection collection, string parameterName)
 {
     ValidationUtils.ArgumentNotNullOrEmpty(collection, parameterName, "Collection '{0}' cannot be empty.".FormatWith(CultureInfo.InvariantCulture, new object[] { parameterName }));
 }
Пример #6
0
 public static void ArgumentNotNullOrEmpty <T>(ICollection <T> collection, string parameterName)
 {
     ValidationUtils.ArgumentNotNullOrEmpty <T>(collection, parameterName, StringUtils.FormatWith("Collection '{0}' cannot be empty.", (IFormatProvider)CultureInfo.InvariantCulture, (object)parameterName));
 }