How to throw a compiler error if more than one member has the same Attribute

前端 未结 4 1276
南笙
南笙 2020-12-06 05:44

Simple question, how do you force the C# compiler to throw a compilation error.


Update: Perhaps it\'s better to use an Assert.Fail() instead?

4条回答
  •  我在风中等你
    2020-12-06 06:08

    I don't believe this can be done, because it is not possible to tell compiler to check for custom errors. Of course, you can use #error, like Jon said, but there is no way to add the condition itself. Because #error will cause error each and every time.

    Only thing you can be sure about is to check at runtime and then throw exception.

    Edit: Damn, getting to question after it was heavily edited.

提交回复
热议问题