I was wondering if it's possible to create a custom obsolete class. I need it and I hate the fact Obsolete shows up this warning before my input: SOMETHING is Obsolete:. I just want to give a warning/error when I use the field/method with ONLY my input, so for example:
[CustomObsolete("Hello")]
public int i = 0;
Will give warning/debug Hello.
Is this possible? If I use #warning/#error, it will ALWAYS show up the error/warning.
One way to achieve what you want would be a custom post-build task
. After your project compiled, let another program that you created load this assembly and parse it for your attribute. You could then output the message you wand and whatever more. But outputting the exact line number and file where this attribute is used will be tricky task, because for this you'd have to parse the pdb file (and would only work in Debug mode properly).
You should better just stick to the Obsolete
attribute of .NET. :-)
you can use only obsolete
With Error
[Obsolete("Hello", true)]
public String foo() {
return "bar";
}
and with warning
[Obsolete("Hello", false)]
public String foo() {
return "bar";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With