Exemple #1
0
        public static void CreateInstance_ConstructorWithPrimitive_PerformsPrimitiveWidening()
        {
            // Primitive widening is allowed by the binder, but not by Dynamic.DelegateInvoke().
            Choice1 c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { (short)-2 }));

            Assert.Equal(2, c.I);
        }
Exemple #2
0
        public static void CreateInstance()
        {
            // Passing null args is equivalent to an empty array of args.
            Choice1 c = (Choice1)(Activator.CreateInstance(typeof(Choice1), null));

            Assert.Equal(1, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { }));
            Assert.Equal(1, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { 42 }));
            Assert.Equal(2, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { "Hello" }));
            Assert.Equal(3, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { 5.1, "Hello" }));
            Assert.Equal(4, c.I);

            Activator.CreateInstance(typeof(StructTypeWithoutReflectionMetadata));

            StructWithPublicDefaultConstructor s = (StructWithPublicDefaultConstructor)Activator.CreateInstance(typeof(StructWithPublicDefaultConstructor));

            Assert.True(s.ConstructorInvoked);
        }
Exemple #3
0
        public static void CreateInstance_Generic()
        {
            Choice1 c = Activator.CreateInstance <Choice1>();

            Assert.Equal(1, c.I);

            Activator.CreateInstance <DateTime>();
            Activator.CreateInstance <StructTypeWithoutReflectionMetadata>();
        }
Exemple #4
0
 void Start()
 {
     Choice1.SetActive(false);
     Choice2.SetActive(false);
     ContinueButton.SetActive(false);
     Button1.onClick.AddListener(ChooseOption1);
     Button2.onClick.AddListener(ChooseOption2);
     ContButton.onClick.AddListener(Continue);
 }
 void Start()
 {
     Globals.HadTomBreadConversation = true;
     Choice1.SetActive(false);
     Choice2.SetActive(false);
     ContinueButton.SetActive(false);
     Button1.onClick.AddListener(ChooseOption1);
     Button2.onClick.AddListener(ChooseOption2);
     ContButton.onClick.AddListener(Continue);
 }
Exemple #6
0
    public static void TestCreateInstance()
    {
        // Passing null args is equivilent to an empty array of args.
        Choice1 c = (Choice1)(Activator.CreateInstance(typeof(Choice1), null));

        Assert.Equal(1, c.I);

        c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { }));
        Assert.Equal(1, c.I);

        c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { 42 }));
        Assert.Equal(2, c.I);

        c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { "Hello" }));
        Assert.Equal(3, c.I);

        c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { 5.1, "Hello" }));
        Assert.Equal(4, c.I);

        Activator.CreateInstance(typeof(StructTypeWithoutReflectionMetadata));
    }
Exemple #7
0
        public static void CreateInstance_ConstructorWithParamsParameter()
        {
            // C# params arguments are honored by Activator.CreateInstance()
            Choice1 c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarArgs() }));

            Assert.Equal(5, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarArgs(), "P1" }));
            Assert.Equal(5, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarArgs(), "P1", "P2" }));
            Assert.Equal(5, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarStringArgs() }));
            Assert.Equal(6, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarStringArgs(), "P1" }));
            Assert.Equal(6, c.I);

            c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarStringArgs(), "P1", "P2" }));
            Assert.Equal(6, c.I);
        }
Exemple #8
0
 public void Start1(Choice1 choice)
 {
     StartChoice = (int)choice;
 }
 public void Start1(Choice1 choice)
 {
     StartChoice = (int)choice;
 }