I would like to create a dynamic class doing with the following:
I have a dictionary where the keys are integers and the values are strings.
Dictionary<int, string> PropertyNames = new Dictionary<int, string>(); PropertyNames.Add(2, "PropertyName1"); PropertyNames.Add(3, "PropertyName2"); PropertyNames.Add(5, "PropertyName3"); PropertyNames.Add(7, "PropertyName4"); PropertyNames.Add(11,"PropertyName5");
I would like to pass this dictionary into a class constructor which builds Properties into the class instance. And suppose I would like to have both get and set functionality for each of these properties. e.g.:
MyDynamicClass Props = new MyDynamicClass( PropertyNames ); Console.WriteLine(Props.PropertyName1); Console.WriteLine(Props.PropertyName2); Console.WriteLine(Props.PropertyName3); Props.PropertyName4 = 13; Props.PropertyName5 = new byte[17];
I am having trouble understanding DLR.