Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I mark generated methods obsolete?
    primarykey
    data
    text
    <p>I'm using a <strong>strongly typed <code>DataSet</code></strong> for which manually adding rows will be error prone. I'm providing <strong>factory methods</strong> to create rows properly. I'd like to guide consumers of my class away from the generated <code>Add*Row</code> methods on the <code>*Table</code> classes. </p> <p><strong>Adding <a href="http://dotnettipoftheday.org/tips/ObsoleteAttribute.aspx" rel="nofollow noreferrer">Obsolete attributes</a> to the generated methods</strong> would do the trick. Sadly, they would be removed the next time the code is generated. </p> <p>I can't use <strong><a href="http://msdn.microsoft.com/en-us/library/bb546176.aspx" rel="nofollow noreferrer">partial methods</a></strong> in the non-generated code because the VS2008 DataSet designer doesn't use them.</p> <p><code>MyType.Dataset.Designer.cs</code> looks a little like this:</p> <pre><code>public partial class ThingyDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable { // I'd love an [Obsolete("Please use the factory method.")] here. // I can't use a partial method, as this method isn't partial. [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public ShelfRow NewShelfRow() return ((ShelfRow)(this.NewRow())); } } </code></pre> <p>Is there some way I can add an <code>Obsolete</code> attribute from <code>MyType.cs</code>? Trying a C-style prototype doesn't work, as the member is already defined. Jamming in <code>partial</code> doesn't work because the generated member isn't <code>partial</code>.</p> <pre><code>// BROKEN EXAMPLE: public partial class ThingyDataTable { // I'd love an [Obsolete("Please use the factory method.")] here. // I can't use a partial method, as this method isn't partial. [Obsolete("Please use the factory method.")] public ShelfRow NewShelfRow(); // ERROR: member already defined. } </code></pre> <p>Is there some other way I can <strong>mark the generated method <code>Obsolete</code>?</strong> </p> <p>How else could I <strong>warn consumers</strong> away from the generated method? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload