This question is similar to Can I make a type "sealed except for internal types" but with interfaces instead of classes.
I want to make a library with something like:
public class SomeClass {
ISupporter Supporter {get; set;}
}
public interface ISupporter {/*Some public methods*/}
internal interface ISupporterInternal {/*Some secret methods*/}
public class SupporterA : ISupporterInternal {/*Includes some explicit interface impls of ISupporterInternal*/}
public class SupporterB : ISupporterInternal {/*Includes some explicit interface impls of ISupporterInternal*/}
The user of the library should be able to set a supporter object for instances of SomeClass. The user should also be able to use the methods from ISupporter but I don't want the user to create his own implementations of ISupporter and have him assign instances of those implementations.
Is there any way besides throwing an exception when the type of the assigned supporter is not derived from ISupporterInternal.