I'm stumped. Please help! I've googled till my fingers hurt!
I have an instance of a type (created through reflection) and need to use it's type in the declaration of a generic class. Emample:
dim myObject as Foo
dim myGeneric as SomeGenericClass.GetAll(of myObject.getType)()
dim myGeneric as SomeGenericClass.GetAll(of Foo)()
I won't know the the class type during design time. It's loaded from a database at runtime. I'm using reflection to find and create an instance of the correct class, but I can't use it's type in the generic declaration. Is this even possible? I'd hate to resort to a Select statement as the class has over a hundred possibilities and we plan on the list of classes changing often.
For anyone curious as to the endgame, the program is connecting to SQL Server, reading one database using the Entity Framework, and then moving that data to a CRM Webapp using the CRM SDK (which is very similar to the entity framework in the way queries are created).
For clarification: I am using the entity framework to get data from an SQL database and the CRM SDK to connect to our CRM project to put the data from the SQL database in. We made a class based on IRepository. The Entity Framework generates classes and properties based on the tables in our database. This data is held in the repository. So if my SQL database had a table called "Employee" with two columns "ID" and "Name", I would use the following to get information on that employee. In this example, our repository is called "SQLdata".
dim emps as list(of Employee) = SQLdata.GetAll(of Employee)()
for each curEmp as Employee in emps
console.writeLine("ID: " & curEmp.ID & " Name: " & curEmp.Name)
That works fine. Now imagine that you don't know that you need the employee's information. There's a list of strings that contains "Employee.Name", "Supervisor.Name", "Project.ID", etc. I have to load this list, figure out which entity framework class is a match, and get the data for it. Using reflection I've been able to get the class. But I can't use it in the GetAll() method of the repository. This is what I want to do:
dim myType as System.Type = myTypeDictionary("Employee")
dim emps as list(of myType) = SQLdata.GetAll(of myType)()
The above code says "'myType' is not defined."
Please save me Code Project! I trust in your awesomeness!!