mercredi 8 juillet 2015

Reflection: object is typed assigned

How can I get the fields out of the parameter variable of the Doit-method()? I cannot change the signature of the Doit method and I cannot use the SomeObject in the Doit method.

 static void Main(string[] args)
    {
        Doit(typeof(SomeObject));
    }

    private static string Doit(object parameter)
    {
        var field = parameter.GetType().GetField("MyString");
        return field.GetValue("MyString").ToString();
    }





Aucun commentaire:

Enregistrer un commentaire