ObsoleteAttribute on properties?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know if it’s possible to apply an ObsoleteAttribute to just the
Get or Set of part a property in .NET 1.1?

From my tests, I don't think you can, but I wanted to make sure.

Thanks,
DlgProc
 
No, you have to assign it to the whole property. I tried to do this:

public static string Home
{
[method: Obsolete]
get
{
return null;
}
[method: Obsolete]
set
{

}
}

And it gave me this:

Error 1 Attribute 'Obsolete' is not valid on property or event accessors. It
is valid on 'class, struct, enum, constructor, method, property, indexer,
field, event, interface, delegate' declarations only.
c:\temp\WindowsApplication1\WindowsApplication1\Program.cs 23 14
WindowsApplication1

Note, you can attach other attributes to the accessors inside a
property, just not the Obsolete one. For example, the Description attribute
can be applied like so:

public static string Home
{
[method: Description("hello")]
get
{
return null;
}
[method: Obsolete]
set
{

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top