I have a struct with several properties of varying types. I need a way to set all of them to values using a string to address the properties, I know I could use a Switch-Case statement but I was wondering if there is a faster/more elegant way to do it?
public struct ExampleStruct
{
public string exampleProperty1 {get; set; }
public int exampleProperty2 {get; set; }
}
public class ExampleClass
{
ExampleStruct e = new ExampleStruct();
string s = "exampleProperty1";
//
// Is there a way to set exampleProperty1, using s to address it?
// Something like e[s] = "foo"
//
}