Hi,
i am not sure if this is at all possible, and i have tried myself but cannot seem to get anywhere with it:
i have several sub classes that perform a bunch of sql statements and hold values in sub classes, one downside to this is that i have to have to setup properties under each class to hold the values.
My thoughts where to create a class that can be inherited or something to the parent class that i could pass an enum (enum contains all the field names and ordinal), the child class would then create a dictionary of that enumeration and string to hold the values.
By creating the dictionary as such i can use one generic class to hold all the parameters without having to write out the properties and the class in each class that i have, just trying to avoid repeated code all over the place (pet hate)
why write something 20 times when you can write an adaptable class to serve your needs! :)
So, just to clarify. I am looking to pass a bunch of different enums to the same class instantiation method and then convert this to a dictionary of the passed enum and string but due to different enums being passed it has to be done on the fly if that makes sense? So once the dictionary is populated, and i use
Dictionary[]
it then brings me the list of enum members?
As it statnds the 'EnumObj'
this.objDict = new Dictionary<EnumObj, String>();
highlights witht his error message
The type or namespace name 'EnumObj' could not be found (are you missing a using directive or an assembly reference?)
Here is the base example code i am working with
class ParentClass
{
public ChildClass Properties;
public ParentClass()
{
this.Properties = new ChildClass(typeof(MyEnum));
}
enum MyEnum
{
col1 = 1,
col2 = 2,
col3 = 3
}
}
public class ChildClass
{
private Object objDict;
public ChildClass(Type EnumObj)
{
this.objDict = new Dictionary<EnumObj, String>();
}
public ChildClass(Object EnumObj)
{
this.objDict = new Dictionary<typeof(EnumObj), String>();
}
}
What I have tried:
Different Variations on passing the method, i have trying passing the enum as an object rather than a type and then convert it.