我正在使用强类型DataSet
,手动添加行将容易出错。我正在提供工厂方法来正确创建行。我想引导我的类的消费者远离类上生成的Add*Row
方法*Table
。
将Obsolete 属性添加到生成的方法中就可以了。遗憾的是,它们将在下次生成代码时被删除。
我不能在非生成代码中使用部分方法,因为 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()));
}
}
有什么方法可以添加Obsolete
属性MyType.cs
吗?尝试 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
吗?
我还能如何警告消费者远离生成的方法?