Reputation: 86937
I have the following properties in a class...
public IObjectSet<Foo> Foos { get; set; }
public IObjectSet<Baa> Baas { get; set; }
public IObjectSet<PewPew> Pew^2 { get; set; }
I wish to return the value of one of those properties, based upon how a pre-determined generic type.
eg.
public IObjectSet<T> Set<T>() where T : class
{
// THIS CODE DOESN'T COMPILE.
if (T is User)
{
return Users as IObjectSet<T>;
}
else if (T is Clan)
{
return Clans as IObjectSet<T>;
}
}
So when i have a particular type .. i need to retrieve the correct type data.
eg.
return TheClass.Set<Foo>().AsQueryable();
Is this possible?
Upvotes: 1
Views: 102
Reputation: 16018
Is
is used when you have an instance, you need to use
if (typeof(T) == typeof(User)) ..
Upvotes: 2