I am trying to strongly type an object property that has been defined as an interface in an interface. Here is my sample
// interfaces
public interface IMyInterfaceA
{
string A { get; set; }
IMyInterfaceB B { get; set; }
}
public interface IMyInterfaceB
{
string B { get; set; }
}
// POCOs
public class pocoOneB : IMyInterfaceB
{
public B { get; set; }
public C { get; set; } // extending the poco with a non-interfaced property
}
public class pocoOneA : IMyInterfaceA
{
string A { get; set; }
pocoOneB B { get; set; } // fails, can I strongly type an interface??
}
public class pocoTwoB : IMyInterfaceB
{
public B { get; set; }
public D { get; set; } // extending the poco with a non-interfaced property
}
public class pocoTwoA : IMyInterfaceA
{
string A { get; set; }
pocoTwoB B { get; set; } // fails, can I strongly type an interface??
}
The problem is I can’t do
pocoOneB B { get; set; } // fails, can I strongly type an interface??
or
pocoTwoB B { get; set; } // fails, can I strongly type an interface??
even though they are implementations of the interface, the compiler says I didn’t correctly implement IMyInterfaceA on either poco. I understand the error, however I would like to know if there is a way to strongly type a property that has an interface?
One way around this is to not have the interface IMyInterfaceA define a property of interface IMyInterfaceB at all and extent on the poco’s, however I am trying to enforce the property is implemented using interfaces.
The main reason I need to strongly type the properties of the poco is because I am using JSON to desterilize over the wire.
Thank you for any guidance.
or simply