private static object CreateDictionary(Type dictionaryType) { Type keyType = dictionaryType.GetTypeInfo().GenericTypeArguments[0]; Type valueType = dictionaryType.GetTypeInfo().GenericTypeArguments[1]; var type = typeof(Dictionary <,>).MakeGenericType(keyType, valueType); return(DelegateFactory.CreateCtor(type)()); }
public ConstructorMap(ConstructorInfo ctor, IEnumerable <ConstructorParameterMap> ctorParams) { Ctor = ctor; CtorParams = ctorParams; _runtimeCtor = LazyFactory.Create(() => DelegateFactory.CreateCtor(ctor, CtorParams)); }
public static object CreateObject(Type type) { return(type.IsArray ? CreateArray(type.GetElementType(), 0) : type == typeof(string) ? null : DelegateFactory.CreateCtor(type)()); }
public ObjectCreator(Type type) { _objectActivator = DelegateFactory.CreateCtor(type); _setters = type .GetTypeInfo() .GetProperties() .ToDictionary(x => x.Name, x => DelegateFactory.CreatePropertySetter(x), StringComparer.OrdinalIgnoreCase); }
public void Create_ctor_should_throw_when_default_constructor_is_missing() { var type = typeof(NoDefaultConstructor); new Action(() => DelegateFactory.CreateCtor(type)()).ShouldThrowException <ArgumentException>(ex => { ex.Message.ShouldStartWith(type.FullName); }); }
public void Test_with_value_object_create_ctor() { var sourceType = typeof(ValueSource); LateBoundCtor ctor = DelegateFactory.CreateCtor(sourceType); var target = ctor(); target.ShouldBeType <ValueSource>(); }
public void Test_with_create_ctor() { var sourceType = typeof(Source); Func <object> ctor = DelegateFactory.CreateCtor(sourceType); var target = ctor(); target.ShouldBeOfType <Source>(); }
public void Test_with_create_ctor() { var sourceType = typeof(Source); LateBoundCtor ctor = DelegateFactory.CreateCtor(sourceType); var target = ctor(); target.ShouldBeInstanceOf <Source>(); }
public static object CreateObject(Type type) { return(DelegateFactory.CreateCtor(type)()); }
public static Exception Type <TException>() where TException : Exception, new() { return(DelegateFactory.CreateCtor <TException>()()); }
public void CreateCtor_StringBuilder_Ok() { ObjectActivator ctor = DelegateFactory.CreateCtor(typeof(StringBuilder)); Assert.IsType <StringBuilder>(ctor()); }
public void CreateCtor_Null_ThrowException() { Assert.Throws(typeof(ArgumentNullException), () => DelegateFactory.CreateCtor(null)); }