I used a modified version of this answer: How to dynamically create a class in C#? to create a dynamic object that represents a typed class.
public static object CreateNewObject(string[] columnNames)
{
var myType = CompileResultType(columnNames);
return Activator.CreateInstance(myType) as IQueryable;
}
Then in the main app:
var obj = MyTypeBuilder.CreateNewObject(rs.ColumnNames);
I need to somehow convert that to an IQueryable
so I can do some Linq calls off it, such as .where()
, .select()
ect. Naturally, I am not currently able to because my app doesn't know what is exactly in that object, or what that object is.
So what I need is:
var obj = MyTypeBuilder.CreateNewObject(rs.ColumnNames);
List<obj> aListICanFill = new List<obj>();
..
aListICanFill.where(x => x.Equals("")).take(3);
I've blindly tried different casts, and even failed to try an iterate through the object - and now I'm completley stuck.
Is there any way to do this?
http://msdn.microsoft.com/en-us/library/bb882637.aspx seems to be something I should hook onto.
What my object looks like: