<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>OOP - There It Is - Attributes</title>
    <link>http://www.vpsw.com/blogbaby/</link>
    <description>A Very Practical Blog</description>
    <language>en-us</language>
    <copyright>Dean Fiala</copyright>
    <lastBuildDate>Thu, 07 Sep 2006 14:14:07 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>dfiala@vpsw.com</managingEditor>
    <webMaster>dfiala@vpsw.com</webMaster>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=5543e4c2-771b-47c2-a8f2-80f820462f46</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,5543e4c2-771b-47c2-a8f2-80f820462f46.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,5543e4c2-771b-47c2-a8f2-80f820462f46.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=5543e4c2-771b-47c2-a8f2-80f820462f46</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Time tramples on and those .NET 1.1 applications
that were shiny and new just a few years ago are probably beginning to show their
age.  Improvements and refinements in every application or class library have
probably left behind a goodly number of dead and dying methods, or even whole classes. 
This is probably even more true of 1.1 applications that were ported to 2.0 and since
refactored to take advantage of new .NET features.  
<br /><br />
While ripping out all these methods before some newbie team member (or forgetful old
hand) accidentally uses one would be ideal, this is not always a practical solution.
But there is an easy way to warn off developers while planning for eventual refactoring,
the <a href="http://msdn2.microsoft.com/en-us/library/system.obsoleteattribute.aspx">Obsolete
Attribute</a>.<br /><br />
Marking a method, property, field, class or interface with the Obsolete Attribute
will generate a compiler warning, and Visual Studio will clearly mark each offending
use of the "soon" to be removed member.  Best of all, it easy is to use.  
<br /><br />
In C#...<br /><blockquote><font color="#000080" face="Courier New">[Obsolete("This method has been
replaced by ReallyUsefulMethod.")]<br />
public void OnceUsefulMethod(){</font><br /><pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"></pre></blockquote><br />
ala VB.NET (don't forget the line continuation)...<br /><blockquote><font color="#000080" face="Courier New">&lt;Obsolete("This method has
been replaced by ReallyUsefulMethod.")&gt; _</font><br /><font color="#000080" face="Courier New">Public Sub OnceUsefulMethod()</font><br /><pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"></pre></blockquote><br />
That's all there is to it. If it's called any place, a compiler warning will be generated,
and Intellisense will also display its impending doom.<br /><br />
If for some reason, the method needs to be taken out of use immediately (for a security
concern, etc.) , the Obsolete Attribute can also generate a compiler error using the
code below.  The second argument to the constructor if set=true will generate
an error instead of a warning.<br /><br />
In C#...<br /><blockquote><font color="#000080" face="Courier New">[Obsolete("This method has been
replaced by ReallyUsefulMethod.", true)]<br />
public void OnceUsefulMethod(){</font><br /></blockquote><br />
ala VB.NET...<br /><blockquote><font color="#000080" face="Courier New">&lt;Obsolete("This method has
been replaced by ReallyUsefulMethod.", True)&gt; _</font><br /><font color="#000080" face="Courier New">Public Sub OnceUsefulMethod(){</font><br /><pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"><br /></pre></blockquote>Using this attribute is also a quick and dirty way to find out
all the places in an application a particular code element is being used.  Compile
the application they'll all be nicely listed in the task list.<br /><br />
The Obsolete Attribute -- an easy to use, graceful first step in pruning and refactoring
-- try it today!<br /><p></p><img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5543e4c2-771b-47c2-a8f2-80f820462f46" /></body>
      <title>Stop Using This!</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,5543e4c2-771b-47c2-a8f2-80f820462f46.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,5543e4c2-771b-47c2-a8f2-80f820462f46.aspx</link>
      <pubDate>Thu, 07 Sep 2006 14:14:07 GMT</pubDate>
      <description>Time tramples on and those .NET 1.1 applications that were shiny and new just a few years ago are probably beginning to show their age.&amp;nbsp; Improvements and refinements in every application or class library have probably left behind a goodly number of dead and dying methods, or even whole classes.&amp;nbsp; This is probably even more true of 1.1 applications that were ported to 2.0 and since refactored to take advantage of new .NET features.&amp;nbsp; &lt;br&gt;
&lt;br&gt;
While ripping out all these methods before some newbie team member (or forgetful old
hand) accidentally uses one would be ideal, this is not always a practical solution.
But there is an easy way to warn off developers while planning for eventual refactoring,
the &lt;a href="http://msdn2.microsoft.com/en-us/library/system.obsoleteattribute.aspx"&gt;Obsolete
Attribute&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
Marking a method, property, field, class or interface with the Obsolete Attribute
will generate a compiler warning, and Visual Studio will clearly mark each offending
use of the "soon" to be removed member.&amp;nbsp; Best of all, it easy is to use.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
In C#...&lt;br&gt;
&lt;blockquote&gt;&lt;font color="#000080" face="Courier New"&gt;[Obsolete("This method has been
replaced by ReallyUsefulMethod.")]&lt;br&gt;
public void OnceUsefulMethod(){&lt;/font&gt;
&lt;br&gt;
&lt;pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;br&gt;
ala VB.NET (don't forget the line continuation)...&lt;br&gt;
&lt;blockquote&gt;&lt;font color="#000080" face="Courier New"&gt;&amp;lt;Obsolete("This method has
been replaced by ReallyUsefulMethod.")&amp;gt; _&lt;/font&gt;
&lt;br&gt;
&lt;font color="#000080" face="Courier New"&gt;Public Sub OnceUsefulMethod()&lt;/font&gt;
&lt;br&gt;
&lt;pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;br&gt;
That's all there is to it. If it's called any place, a compiler warning will be generated,
and Intellisense will also display its impending doom.&lt;br&gt;
&lt;br&gt;
If for some reason, the method needs to be taken out of use immediately (for a security
concern, etc.) , the Obsolete Attribute can also generate a compiler error using the
code below.&amp;nbsp; The second argument to the constructor if set=true will generate
an error instead of a warning.&lt;br&gt;
&lt;br&gt;
In C#...&lt;br&gt;
&lt;blockquote&gt;&lt;font color="#000080" face="Courier New"&gt;[Obsolete("This method has been
replaced by ReallyUsefulMethod.", true)]&lt;br&gt;
public void OnceUsefulMethod(){&lt;/font&gt;
&lt;br&gt;
&lt;/blockquote&gt;
&lt;br&gt;
ala VB.NET...&lt;br&gt;
&lt;blockquote&gt;&lt;font color="#000080" face="Courier New"&gt;&amp;lt;Obsolete("This method has
been replaced by ReallyUsefulMethod.", True)&amp;gt; _&lt;/font&gt;
&lt;br&gt;
&lt;font color="#000080" face="Courier New"&gt;Public Sub OnceUsefulMethod(){&lt;/font&gt;
&lt;br&gt;
&lt;pre class="code" id="ctl00_LibFrame_ctl13CSharp" space="preserve"&gt;
&lt;br&gt;
&lt;/pre&gt;&lt;/blockquote&gt;Using this attribute is also a quick and dirty way to find out
all the places in an application a particular code element is being used.&amp;nbsp; Compile
the application they'll all be nicely listed in the task list.&lt;br&gt;
&lt;br&gt;
The Obsolete Attribute -- an easy to use, graceful first step in pruning and refactoring
-- try it today!&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=5543e4c2-771b-47c2-a8f2-80f820462f46" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,5543e4c2-771b-47c2-a8f2-80f820462f46.aspx</comments>
      <category>.NET</category>
      <category>Attributes</category>
    </item>
  </channel>
</rss>