我正在使用强类型DataSet
手动添加行会出错。我正在提供工厂方法以正确创建行。我想引导我的班级的消费者远离*Table
生成的Add*Row
方法。如何将生成的方法标记为过时?
将Obsolete attributes添加到生成的方法会做的伎俩。可悲的是,他们将在下次生成代码时被删除。
我不能在非生成的代码中使用partial methods,因为VS2008 DataSet设计器不使用它们。
MyType.Dataset.Designer.cs
看起来有点像这样:
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()));
}
}
有一些方法可以让我从MyType.cs
添加Obsolete
属性?由于成员已经定义,尝试C样式原型不起作用。由于生成的成员不是partial
,因此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.
}
有一些其他的方式,我可以标记生成的方法Obsolete
?
我该怎样才能警告消费者远离生成的方法?
我会尝试这个查找并替换为“[global :: System.Diagnostics.DebuggerNonUserCodeAttribute()] [Obsolete(”请使用工厂方法。“)”[global :: System.Diagnostics.DebuggerNonUserCodeAttribute()]“ ]”。我无法找到DataSets的模板 – jrcs3 2009-02-25 00:03:11
编辑模板是一个非常有趣的想法。我如何确保任何拥有VS2008股票的人都会在查看源代码后最终使用该模板? – 2009-02-25 00:08:51
如果你能找到模板。我认为Visual Studio使用xsd.exe为DataSet生成类,模板数据位于.exe或某些支持的.dll。 – jrcs3 2009-02-25 00:49:58