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)());
        }
示例#2
0
        public ConstructorMap(ConstructorInfo ctor, IEnumerable <ConstructorParameterMap> ctorParams)
        {
            Ctor       = ctor;
            CtorParams = ctorParams;

            _runtimeCtor = LazyFactory.Create(() => DelegateFactory.CreateCtor(ctor, CtorParams));
        }
示例#3
0
 public static object CreateObject(Type type)
 {
     return(type.IsArray
         ? CreateArray(type.GetElementType(), 0)
         : type == typeof(string)
             ? null
             : DelegateFactory.CreateCtor(type)());
 }
示例#4
0
 public ObjectCreator(Type type)
 {
     _objectActivator = DelegateFactory.CreateCtor(type);
     _setters         = type
                        .GetTypeInfo()
                        .GetProperties()
                        .ToDictionary(x => x.Name, x => DelegateFactory.CreatePropertySetter(x), StringComparer.OrdinalIgnoreCase);
 }
示例#5
0
        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>();
        }
示例#7
0
        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>();
        }
示例#9
0
 public static object CreateObject(Type type)
 {
     return(DelegateFactory.CreateCtor(type)());
 }
示例#10
0
 public static Exception Type <TException>()
     where TException : Exception, new()
 {
     return(DelegateFactory.CreateCtor <TException>()());
 }
示例#11
0
        public void CreateCtor_StringBuilder_Ok()
        {
            ObjectActivator ctor = DelegateFactory.CreateCtor(typeof(StringBuilder));

            Assert.IsType <StringBuilder>(ctor());
        }
示例#12
0
 public void CreateCtor_Null_ThrowException()
 {
     Assert.Throws(typeof(ArgumentNullException), () => DelegateFactory.CreateCtor(null));
 }