C#自定义过时属性

x_m*_*d_x 11 c# attributes obsolete

我想知道是否可以创建一个自定义的过时类.我需要它并且我讨厌在我输入之前Obsolete出现这个警告的事实:SOMETHING已经过时了:我只想在仅使用输入的字段/方法时发出警告/错误,例如:

[CustomObsolete("Hello")]
public int i = 0;
Run Code Online (Sandbox Code Playgroud)

将给出警告/调试你好.

这可能吗?如果我使用#warning/#error,它将始终显示错误/警告.

Jon*_*eet 9

No, ObsoleteAttribute is effectively hard-coded into the C# compiler - there's no way of creating your own attribute that the C# compiler will understand as indicating that a member is obsolete.

Personally I'd just go with ObsoleteAttribute - is it really that bad that the error message starts with "X is obsolete"?