I have a class which looks like this:
public class Field
{
public string FieldName;
public string FieldType;
}
And an object List<Field> with values:
{"EmployeeID","int"},
{"EmployeeName","String"},
{"Designation","String"}
I want to create a class that looks like this:
Class DynamicClass
{
int EmployeeID,
String EmployeeName,
String Designation
}
Is there any way to do this?
I want this to be generated at runtime. I don’t want a physical CS file residing in my filesystem.
Yes, you can use
System.Reflection.Emitnamespace for this. It is not straight forward if you have no experience with it, but it is certainly possible.Edit: This code might be flawed, but it will give you the general idea and hopefully off to a good start towards the goal.