Esempio n. 1
0
 public string MyMethod2(MyClass2 myObj)
 {
     return(myObj.ToString());
 }
Esempio n. 2
0
 public string MyMethod3(string myStr, MyClass2 myObj, int myInt)
 {
     return(string.Format("myStr: {0} myObj: {1}, myInt: {2}", myStr, myObj, myInt));
 }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            MyClass1 c1 = new MyClass1();
            MyClass2 c2 = new MyClass2 {
                MyInt = 2, MyString = "MyString2"
            };

            Console.WriteLine(c1.MyMethod1("MyString1", 2));
            Console.WriteLine(c1.MyMethod2(c2));
            Console.WriteLine(c1.MyMethod3("MyString2", c2, 3));
            Console.WriteLine(c1.MyMethod4(DateTime.Now));

            NameValueCollection kvp1 = new NameValueCollection();

            kvp1.Add("myStr", "MyString From String");
            kvp1.Add("myInt", "20");

            NameValueCollection kvp2 = new NameValueCollection();

            kvp2.Add("myObj.MyString", "MyString From String");
            kvp2.Add("myObj.MyInt", "20");

            NameValueCollection kvp3 = new NameValueCollection();

            kvp3.Add("myObj.MyString", "MyString From String");
            kvp3.Add("myObj.MyInt", "20");
            kvp3.Add("myStr", "MyString From String");
            kvp3.Add("myInt", "20");

            NameValueCollection kvp4 = new NameValueCollection();

            kvp4.Add("myDt", "01/02/2003");

            NameValueCollection kvp5 = new NameValueCollection();

            kvp5.Add("myStrArr[0]", "myStr1");
            kvp5.Add("myStrArr[1]", "myStr2");
            kvp5.Add("myStrArr[2]", "myStr3");
            kvp5.Add("myStrArr[3]", "myStr4");

            NameValueCollection kvp6 = new NameValueCollection();

            kvp6.Add("myClass2Arr[0].MyString", "MyString1 From String");
            kvp6.Add("myClass2Arr[0].MyInt", "20");
            kvp6.Add("myClass2Arr[1].MyString", "MyString2 From String");
            kvp6.Add("myClass2Arr[1].MyInt", "30");
            kvp6.Add("myClass2Arr[2].MyString", "MyString3 From String");
            kvp6.Add("myClass2Arr[2].MyInt", "40");

            Type myClass1Type = typeof(MyClass1);

            MethodInfo mi1 = myClass1Type.GetMethod("MyMethod1");
            MethodInfo mi2 = myClass1Type.GetMethod("MyMethod2");
            MethodInfo mi3 = myClass1Type.GetMethod("MyMethod3");
            MethodInfo mi4 = myClass1Type.GetMethod("MyMethod4");
            MethodInfo mi5 = myClass1Type.GetMethod("MyMethod5");
            MethodInfo mi6 = myClass1Type.GetMethod("MyMethod6");

            object[] objArr1 = GetParametersAsObjectArray(mi1, kvp1);
            object[] objArr2 = GetParametersAsObjectArray(mi2, kvp2);
            object[] objArr3 = GetParametersAsObjectArray(mi3, kvp3);
            object[] objArr4 = GetParametersAsObjectArray(mi4, kvp4);
            object[] objArr5 = GetParametersAsObjectArray(mi5, kvp5);
            object[] objArr6 = GetParametersAsObjectArray(mi6, kvp6);

            object mi1Return = mi1.Invoke(c1, objArr1);

            Console.WriteLine(mi1Return);
            object mi2Return = mi2.Invoke(c1, objArr2);

            Console.WriteLine(mi2Return);
            object mi3Return = mi3.Invoke(c1, objArr3);

            Console.WriteLine(mi3Return);
            object mi4Return = mi4.Invoke(c1, objArr4);

            Console.WriteLine(mi4Return);
            object mi5Return = mi5.Invoke(c1, objArr5);

            Console.WriteLine(mi5Return);
            object mi6Return = mi6.Invoke(c1, objArr6);

            Console.WriteLine(mi6Return);
        }