示例#1
0
        public void Invoke_OneParameter()
        {
            ConstructorInfo[]      constructors = GetConstructors(typeof(ClassWith3Constructors));
            ClassWith3Constructors obj          = (ClassWith3Constructors)constructors[1].Invoke(new object[] { 100 });

            Assert.Equal(100, obj.intValue);
        }
示例#2
0
        public void Invoke()
        {
            ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
            Assert.Equal(3, constructors.Length);
            ClassWith3Constructors obj = (ClassWith3Constructors)constructors[0].Invoke(null);

            Assert.NotNull(obj);
        }
示例#3
0
        public void Invoke_TwoParameters()
        {
            ConstructorInfo[]      constructors = GetConstructors(typeof(ClassWith3Constructors));
            ClassWith3Constructors obj          = (ClassWith3Constructors)constructors[2].Invoke(new object[] { 101, "hello" });

            Assert.Equal(101, obj.intValue);
            Assert.Equal("hello", obj.stringValue);
        }
示例#4
0
        public void Invoke_ExistingInstance()
        {
            // Should not produce a second object.
            ConstructorInfo[]      constructors = GetConstructors(typeof(ClassWith3Constructors));
            ClassWith3Constructors obj1         = new ClassWith3Constructors(100, "hello");
            ClassWith3Constructors obj2         = (ClassWith3Constructors)constructors[2].Invoke(obj1, new object[] { 999, "initialized" });

            Assert.Null(obj2);
            Assert.Equal(999, obj1.intValue);
            Assert.Equal("initialized", obj1.stringValue);
        }
示例#5
0
        public void Invoke_TwoParameters_CustomBinder_IncorrectTypeArgument()
        {
            ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));

            var args = new object[] { "101", "hello" };
            ClassWith3Constructors obj = (ClassWith3Constructors)constructors[2].Invoke(BindingFlags.Default, new ConvertStringToIntBinder(), args, null);

            Assert.Equal(101, obj.intValue);
            Assert.Equal("hello", obj.stringValue);
            Assert.True(args[0] is int);
            Assert.True(args[1] is string);
        }
示例#6
0
 public void Invoke_ExistingInstance()
 {
     // Should not prouce a second object.
     ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors));
     ClassWith3Constructors obj1 = new ClassWith3Constructors(100, "hello");
     ClassWith3Constructors obj2 = (ClassWith3Constructors)constructors[2].Invoke(obj1, new object[] { 999, "initialized" });
     Assert.Null(obj2);
     Assert.Equal(obj1.intValue, 999);
     Assert.Equal(obj1.stringValue, "initialized");
 }