jeudi 23 novembre 2017

How can I set my class properties values Using Reflection

Good Day,

Lets say this is my class:

public class MyClass {

    public bool boolProp { get; set; }
    public string stringProp { get; set; }
}

this is my IDictionary:

IDictionary<string, string> myDict= 
        new IDictionary<string, string>();

myDict.Add("boolProp", "true");
myDict.Add("stringProp", "teststring");

So I want to update my class properties using Reflection where my dictionary keys matches the name of property then set its value by creating a method, how is that?

Method parameter should be like this:

public void UpdateProperties(IDictionary<string, string> myDict) {

Thanks





Aucun commentaire:

Enregistrer un commentaire