Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

ObsoleteAttribute on properties?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dlgproc - 31 May 2007 20:49 GMT
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
Nicholas Paldino [.NET/C# MVP] - 31 May 2007 20:59 GMT
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
   {

   }
}

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> Does anyone know if it's possible to apply an ObsoleteAttribute to just
> the
[quoted text clipped - 4 lines]
> Thanks,
>    DlgProc

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.