What is the proper way to implement an interface that has its own interface members? (am I saying that correctly?) Here’s what I mean:
public Interface IFoo
{
string Forty { get; set; }
string Two { get; set; }
}
public Interface IBar
{
// other stuff...
IFoo Answer { get; set; }
}
public class Foo : IFoo
{
public string Forty { get; set; }
public string Two { get; set; }
}
public class Bar : IBar
{
// other stuff
public Foo Answer { get; set; } //why doesnt' this work?
}
I’ve gotten around my problem using explicit interface implementation, but I’m wondering if there is a better way?
You’ll need to use generics to be able to do what you want.
This will allow you to provide an interface that says something like, “to implement this interface you must have a property with a public getter/setter of a type that implements
IFoo.” Without generics you are simply saying that the class has a property with a type of exactlyIFoo, rather than anything that implementsIFoo.