jeudi 2 juin 2016

Problems with Reflection on winforms

I have a winforms application.

In the class Form 1 I have several variables and I am trying to use reflection to get one by name. I need the variable itself, but I decided to test if it works by getting its value, first. Otherwise I need to pass it as an argument to another method.

The variable's name is "Button_Width".

I have tried

    object ob = new Form1();
    var damnsin = typeof(Form1).GetProperty("Button_Width").GetValue(ob);

and

        object ob = new Form1();
        var damnsin = typeof(Form1).GetField("Button_Width").GetValue(ob);

Since I do not understand reflection all that well I am not sure what object I should use in "GetValue", so I impovised. The problem is both of these cause my program to crash with a "stackoverflow".





Aucun commentaire:

Enregistrer un commentaire