I am trying to set the value of a property in a class using a string. For example, my class has the following properties:
myClass.Name myClass.Address myClass.PhoneNumber myClass.FaxNumber
All fields have a string type, so I know in advance that this is always a string. Now I want to be able to set properties using a string, as you could do with a DataSet . Something like that:
myClass["Name"] = "John" myClass["Address"] = "1112 River St., Boulder, CO"
Ideally, I want to just assign a variable and then set the property using the name of this string from a variable:
string propName = "Name" myClass[propName] = "John"
I read about reflection and maybe that was the way to do it, but I'm not sure how to set it up while keeping access to the property in the class intact. I want to still be able to use:
myClass.Name = "John"
Any code examples would be really good.
set reflection c # properties get
Patratacus Apr 23 2018-12-12T00: 00Z
source share