我想确保在编译时永远不会在同一个类上找到两个接口,类似于AttributeUsage在编译时检查自定义属性的方式。
例如:
[InterfaceUsage(MutuallyExclusive = typeof(B))]
interface A {
//...
}
interface B {
//...
}
class C : A, B { //should throw an error on compile time
//...
}
我显然可以在运行时通过反射来做到这一点,但我对编译时解决方案感兴趣。
我想一个可能不存在开箱即用 - 但是有没有一种方法可以创建在编译时运行的自定义属性,就像 AttributeUsage 一样?