public static object CreateInstance( CachedType type, Func<CachedType, object[], object> factory = null, params object[] dependencies) { if (type.IsSimpleType) throw new SimpleTypeInstantiationNotSupportedException(type); try { if (type.IsArray) return type.CreateArray(); if (type.IsInterface) { if (type.IsGenericListInterface) return type.CreateGenericListInstance(); if (type.IsListInterface) return new List<object>(); if (type.IsGenericDictionaryInterface) return type.CreateGenericDictionaryInstance(); if (type.IsDictionaryInterface) return new Dictionary<object, object>(); if (type.IsGenericEnumerableInterface) return type.CreateGenericListInstance(); if (type.IsEnumerableInterface) return new List<object>(); } return (factory ?? DefaultFactory)(type, dependencies.Where(x => x != null).ToArray()); } catch (Exception exception) { throw new ObjectCreationException(type, exception); } }
public static object CreateInstance( CachedType type, Func <CachedType, object[], object> factory = null, params object[] dependencies) { if (type.IsSimpleType) { throw new SimpleTypeInstantiationNotSupportedException(type); } try { if (type.IsArray) { return(type.CreateArray()); } if (type.IsInterface) { if (type.IsGenericListInterface) { return(type.CreateGenericListInstance()); } if (type.IsListInterface) { return(new List <object>()); } if (type.IsGenericDictionaryInterface) { return(type.CreateGenericDictionaryInstance()); } if (type.IsDictionaryInterface) { return(new Dictionary <object, object>()); } if (type.IsGenericEnumerableInterface) { return(type.CreateGenericListInstance()); } if (type.IsEnumerableInterface) { return(new List <object>()); } } return((factory ?? DefaultFactory)(type, dependencies.Where(x => x != null).ToArray())); } catch (Exception exception) { throw new ObjectCreationException(type, exception); } }