I want to mark an old class as Obsolete and redirect to the new class in the Obsolete attribute comment. However, if I write the new class name as a magic string, I won't be able to use the might of IDE.
For example, if I rename my class, I will loose the "link". And the reader won't be able to Ctrl + click on my comment to go to the new class.
The official documentation does seems to say that it is not possible, but I find strange that nobody has this need.
Instead of
// Mark OldProperty As Obsolete.
[ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", false)]
public static string OldProperty
{ get { return "The old property value."; } }
public static string NewProperty
{ get { return "The new property value."; } }
I would like to be able to write
[ObsoleteAttribute($"This property is obsolete. Use {nameof(NewProperty)} instead.", false)]
As a workaround, I can use the XML doc, but it's not the best way to do it.
/// <remarks>Replaced by <see cref="LoadBrainIndMeasMessTable"/></remarks>
"This property is obsolete. Use " + nameof(NewProperty) + " instead."An attribute argument must be a constant expression, 'typeof()' expression or array creation expression of an attribute parameter typewhen trying to do so, I did not think to check in later language version. Would you like to write it as an answer so I can accept it as resolved?[Obsolete]not[ObsoleteAttribute]