dimanche 26 juin 2016

Invoke Method with reflection pass through parameters and receive a return value

Hello as the question describes im trying to invoke a method through reflection, which is fine and all if it was a void type. but string, bool, etc is not working. also with a return type. i haven't been able to find any useful references.

i have a Test Class which i used to call some test methods. all the void ones had worked fine. but the others were not calling at all.

internal class Test
{
    public static void Print()
    {
        Console.WriteLine("Test");
        Console.WriteLine("Testing an invoke method");
    }

    public static void CalcData()
    {
        Console.WriteLine("Test");
    }

    public static void DoSomething(int c, float f)
    {
        Console.WriteLine("Test");
    }

    public static string TestString(string s, int p, char f)
    {
        return "Happy Days";
    }
}

in my Main Method i would call t.GetMethod("Print").Invoke(t, null);

but i am unsure how i would call to pass in a parameter or even obtain a return type.

some insight on this would be greatly appreciated.





Aucun commentaire:

Enregistrer un commentaire