Example #1
0
        public static void Main()
        {
            Activator.CreateInstance(typeof(Test1));
            Activator.CreateInstance(typeof(Test2), true);
            Activator.CreateInstance(typeof(Test3), BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);
            Activator.CreateInstance(typeof(Test4), GetBindingFlags(), null, GetArgs(), null);
            Activator.CreateInstance(typeof(Test5), new object[] { 1, "ss" });

            var p = new ActivatorCreateInstance();

            // Direct call to static method with a parameter
            FromParameterOnStaticMethod(typeof(FromParameterOnStaticMethodType));

            // Value comes from multiple sources - each must be marked appropriately
            Type fromParameterOnStaticMethodType = p == null ?
                                                   typeof(FromParameterOnStaticMethodTypeA) :
                                                   typeof(FromParameterOnStaticMethodTypeB);

            FromParameterOnStaticMethod(fromParameterOnStaticMethodType);

            // Direct call to instance method with a parameter
            p.FromParameterOnInstanceMethod(typeof(FromParameterOnInstanceMethodType));

            // Non-public constructors required
            FromParameterWithNonPublicConstructors(typeof(FromParameterWithNonPublicConstructorsType));

            // Public contructors required
            FromParameterWithPublicConstructors(typeof(FromParameterWithPublicConstructorsType));

            WithAssemblyName();
            WithAssemblyPath();

            AppDomainCreateInstance();

            UnsupportedCreateInstance();

            TestCreateInstanceOfTWithConcreteType();
            TestCreateInstanceOfTWithNewConstraint <TestCreateInstanceOfTWithNewConstraintType> ();
            TestCreateInstanceOfTWithNoConstraint <TestCreateInstanceOfTWithNoConstraintType> ();

            TestCreateInstanceOfTWithDataflow <TestCreateInstanceOfTWithDataflowType> ();

            TestNullArgsOnKnownType();
            TestNullArgsOnAnnotatedType(typeof(TestType));
            TestNullArgsNonPublicOnly(typeof(TestType));
            TestNullArgsNonPublicWithNonPublicAnnotation(typeof(TestType));

            TestNullType();
            TestNoValue();

            CreateInstanceWithGetTypeFromHierarchy.Test();
        }
        public static void Main()
        {
            Activator.CreateInstance(typeof(Test1));
            Activator.CreateInstance(typeof(Test2), true);
            Activator.CreateInstance(typeof(Test3), BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);
            Activator.CreateInstance(typeof(Test4), new object[] { 1, "ss" });

            var p = new ActivatorCreateInstance();

            // Direct call to static method with a parameter
            FromParameterOnStaticMethod(typeof(FromParameterOnStaticMethodType));

            // Value comes from multiple sources - each must be marked appropriately
            Type fromParameterOnStaticMethodType = p == null ?
                                                   typeof(FromParameterOnStaticMethodTypeA) :
                                                   typeof(FromParameterOnStaticMethodTypeB);

            FromParameterOnStaticMethod(fromParameterOnStaticMethodType);

            // Direct call to instance method with a parameter
            p.FromParameterOnInstanceMethod(typeof(FromParameterOnInstanceMethodType));

            // All constructors required
            FromParameterWithConstructors(typeof(FromParameterWithConstructorsType));

            // Public contructors required
            FromParameterWithPublicConstructors(typeof(FromParameterWithPublicConstructorsType));

            WithAssemblyName();
            WithAssemblyPath();

            AppDomainCreateInstance();

            UnsupportedCreateInstance();

            TestCreateInstanceOfTWithNewConstraint <TestCreateInstanceOfTWithNewConstraintType> ();
            TestCreateInstanceOfTWithNoConstraint <TestCreateInstanceOfTWithNoConstraintType> ();
        }