Possible Duplicate:
C# -Generics Help
Let’s start with this interface IBar as below.
public interface IBar<T> : IQueryable<T>, IEnumerable<T> where T : class
{
}
I have following 3 classes Bar1, Bar2 and Bar3.
public class Bar1
{
}
public class Bar2
{
}
public class Bar3
{
}
Then I have another interface called IFoo which contains generic IBar for each of above three classes as shown below.
public interface IFoo
{
IBar<Bar1> Bar1 { get; set; }
IBar<Bar2> Bar2 { get; set; }
IBar<Bar3> Bar3 { get; set; }
}
Finally I have three classes Foo1Sample, Foo2Sample and Foo3Sample. Each of this class contains an instance of IFace interface and also has a Data property that returns IQueryable as shown below.
public class Foo1Sample
{
IFoo foo;
public IQueryable<Bar1> Data
{
get { return foo.Bar1; }
}
}
public class Foo2Sample
{
IFoo foo;
public IQueryable<Bar2> Data
{
get { return foo.Bar2; }
}
}
public class Foo3Sample
{
IFoo foo;
public IQueryable<Bar3> Data
{
get { return foo.Bar3; }
}
}
I was just wondering if I can create a base class that could be used for Foo1Sample, Foo2Sample and Foo3Sample such that Data property can return appropriate type from that IFoo interface.