I have one base class
public Enum TestType{
A,
B
}
public abstract class Base{
public int ID{ get;set;}
}
and a derived class
public class Derived1 : Base{
public string Prop1 {get;set;}
}
public class Derived2 : Base{
public string Prop2 {get;set;}
}
then I have a function that returns Base
public IQueryable<Base> GetData(TestType type){
switch(type){
case A:
return new IQueryable<Derived1>();
case B:
return new IQueryable<Derived2>();
}
}
Now sadly one of the tools I'm working with needs the actual type and cannot get away with passing in the base type.
How do I convert the return result from GetData to it's actual type and not Base. I was thinking using expressions and cast but I cannot figure it out.
Idealy the GetData is a factory that get's the data, I don't expect there to be IQueryable< Base> to contain a list of mixed classes. I DO NOT KNOW THE TYPE AT COMPILE TIME! I'd like to have a function from base to derived at run time without having to check the underlying type then doing a cast( IE a bunch of if statements)
EDIT: added some underlying code to help. Now the control I'm using says it can't find property Prop1 on base( if I pass in the result set of GetData that returns IQueryable) but if I convert it, it works fine. the problem is I do not know the exact type at compile time I just know that one of the classes will be there.