当提供相同方法的多个重载时,我经常不得不重复该方法的描述,这违反了DRY并增加了维护成本:
////// Frobnicates all foos read from the given reader. Frobnication is a /// process where ...[lots of text]... /// /// [Description of hasBar] void FrobnicateFoo(TextReader reader, bool hasBar) { ... } ////// Frobnicates all foos read from the given file. Frobnication is a /// process where ...[same lots of text]... /// /// [Same description of hasBar] void FrobnicateFoo(String path, bool hasBar) { ... }
如果重复具有相同目的的多个参数,则该问题变得更糟(作为示例给出"hasBar").
我找到的一个"解决方法"是"引用"其他文档:
////// Frobnicates all foos read from the given reader. Frobnication is a /// process where ...[lots of text]... /// /// [Description of hasBar] void FrobnicateFoo(TextReader reader, bool hasBar) { ... } ////// Convenience method which opens the file with a UTF-8 encoding and then /// frobnicates all foos, see FrobnicateFoo(TextReader). /// void FrobnicateFoo(String path, bool hasBar) { ... }
显然,这对于图书馆的用户来说不太方便.
是否有一些内置机制(或智能策略)可以用来避免重复并让我的方法的用户轻松生活?我主要关注IntelliSense,而不是生成的HTML文档.