I'm using a strongly typed DataSet
for which manually adding rows will be error prone. I'm providing factory methods to create rows properly. I'd like to guide consumers of my class away from the generated Add*Row
methods on the *Table
classes.
Adding Obsolete attributes to the generated methods would do the trick. Sadly, they would be removed the next time the code is generated.
I can't use partial methods in the non-generated code because the VS2008 DataSet designer doesn't use them.
MyType.Dataset.Designer.cs
looks a little like this:
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()));
}
}
Is there some way I can add an Obsolete
attribute from MyType.cs
? Trying a C-style prototype doesn't work, as the member is already defined. Jamming in partial
doesn't work because the generated member isn't partial
.
// 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.
}
Is there some other way I can mark the generated method Obsolete
?
How else could I warn consumers away from the generated method?