internal static T CreateDynamicFrom <T>(Type type, IDefaultData defaultData, ObjectCreationStrategy objectCreationStrategy) { if (type.IsIEnumerable()) { var enumerable = EnumerableCreator.Create <T>(type, defaultData, objectCreationStrategy); if (enumerable != null) { return(enumerable); } } if (type.IsIEnumerator()) { var enumerator = EnumeratorCreator.Create <T>(type, defaultData, objectCreationStrategy); if (enumerator != null) { return(enumerator); } } var expectedObject = CreateDynamic <T>(type, defaultData, objectCreationStrategy); if (expectedObject == null) { return(default(T)); } return(InitObject(defaultData, objectCreationStrategy, expectedObject)); }
//private static readonly Func<Type, object> ForFunc = genericType => Substitute.For(new Type[] { genericType }, new object[] { }); internal static T Create <T>(Type type, IDefaultData defaultData, ObjectCreationStrategy objectCreationStrategy) { if (!type.IsInterface) { return(default(T)); } if (type.IsIEnumerable()) { var result = EnumerableCreator.Create <T>(type, defaultData, objectCreationStrategy); if (result != null) { return(result); } } if (type.IsIEnumerator()) { var result = EnumeratorCreator.Create <T>(type, defaultData, objectCreationStrategy); if (result != null) { return(result); } } return(CreateProxy <T>(type, defaultData, objectCreationStrategy)); }