Marking code deprecated

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

Guest

How do I mark a method or class in my library as deprecated, so that when it
is used by some other application, the compiler will issue a warning?
 
Michael,

You want to add the Obsolete attribute to it.

Hope this helps.
 
Hi,

Yes, just as Nicholas pointed out, you may use ObsoleteAttribute for this
task. Actually, .Net Base Class Library also uses ObsoleteAttribute to mark
obsolete classes or methods. For example, if you search
AppDomain.AppendPrivatePath Method in .Net2.0 MSDN, you will see the
following:
[ObsoleteAttribute("AppDomain.AppendPrivatePath has been deprecated. Please
investigate the use of AppDomainSetup.PrivateBinPath instead.
http://go.microsoft.com/fwlink/?linkid=14202")]
public void AppendPrivatePath (
string path
)

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thank you. I will give that a try...
Could I also ask where I might find an overview article on attributes? I
have had occasion to use a few now and then (this one, with nunit, and
others) but I would like to learn a bit more about them, including which ones
are available (like the ObsoleteAttribute).
 
How do I mark a method or class in my library as deprecated, so that when it
is used by some other application, the compiler will issue a warning?

It might be a good idea to use the EditorBrowsableAttribute as well.
Intellisense uses this attribute to decide whether or not to display
the member.
 
Hi Michael ,

Yes, Attribute is an essential mechanism of .Net. You may read the 2 links
below to understand the Attribute feature in .Net:
"Attributes Tutorial"
http://msdn2.microsoft.com/en-us/library/aa288454(VS.71).aspx
"Designing With Custom Attributes"
http://msdn.microsoft.com/msdnmag/issues/05/05/BasicInstincts/

Since all the .Net BCL Attribute classes inherited from System.Attribute
class, you may search and examine the "Attribute Hierarchy" below to find
any useful attribute in .Net BCL:
http://msdn2.microsoft.com/en-us/library/2e39z096(VS.80).aspx

However, as you can see, the "Attribute Hierarchy" is really a big table,
there is no quick way to understand them all in a short time.

If you still have anything unclear, please feel free to tell me, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Michael,

Have you reviewed my last reply to you? Does it make sense to you? If you
still need any help or have any concern, please feel free to tell me,
thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Very cool--thank you, Brian.

Brian Gideon said:
It might be a good idea to use the EditorBrowsableAttribute as well.
Intellisense uses this attribute to decide whether or not to display
the member.
 
Your links are quite helpful. Even allowed me to quickly look up the
EditorBrowsableAttribute that Brian Gideon mentioned in another reply to this.
 
Hi Michael,

Thank you for the confirmation. Ok, if you need further help, please feel
free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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