How can I disable external inheritance without using classes? I know it can be done with classes like this:
public abstract class NoInherit
{
internal NoInherit() { }
}
public sealed class MyType : NoInherit { /* ... */ }
But not with interfaces. I don't want to use classes because I want to inherit MyType
from another class and C# doesn't support multiple inheritance.
Perhaps I should explain better what I'm开发者_开发技巧 trying to do. I'm attempting to create an object-like class but that only accepts some types.
List<NoInherit> x = new List<NoInherit>();
x.Add(new MyType()); // OK
x.Add(new MyType2()); // OK
x.Add(123); // ERROR
精彩评论