-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Allow Obsolete attribute on getters and setters #32472
Description
Currently in C# the Obsolete attribute is not allowed on property getters and setters.
using System;
class C
{
int P { get; [Obsolete] set; }
}
Has the error
error CS1667: Attribute 'System.ObsoleteAttribute' is not valid on property or event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
In VB it is allowed, and seems to work as expected.
It would also be useful, for example when I want to start making a property readonly, and so mark usages of the setter obsolete in the meantime. Also a property setter might have to be declared for eg. XmlSerialization, but I don't want anyone else using it, so I would like to mark it obsolete.
Since the obsolete attribute seems to be unique in this regard among attributes, I'm guessing this is either a compiler or a language feature.
I'm not sure which repository is the correct place for this issue, so I'm asking it here, and if necessary I will move it to csharplang.