依赖属性的 XML 文档
记录依赖属性的最佳方法是什么?
我应该将 xml 文档放在 field:
/// <summary>Documentation goes here</summary>
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register(...)
或 property: 上
/// <summary>and/or here?</summary>
public string Name{ get{...} set{...} }
,还是我真的需要记录(和维护)两者?
What is the best way to document a dependency property?
Should I put the xml documentation on the field:
/// <summary>Documentation goes here</summary>
public static readonly DependencyProperty NameProperty =
DependencyProperty.Register(...)
or on the property:
/// <summary>and/or here?</summary>
public string Name{ get{...} set{...} }
or do I really need to document (and maintain) both?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这就是我想出的。
我在依赖属性中使用特殊的 xml 标记,该标记将被 xsl 转换替换。没有它也可以做到这一点,但随后 Visual Studio 会发出警告,因为该字段似乎未记录。
C# 属性照常记录,只需确保不要忘记值描述。
Visual Studio 在构建过程中根据这些注释创建一个 xml 文件。通过一些 xsl 转换,
dpdoc
节点被属性文档的修改版本所取代。生成的 xml 文件与我们很好地记录了属性标识符一样。它甚至包含一个简短的注释,指出有另一种访问变量的方法:这样,两个 API 都有适当的文档,我们不需要在代码中重复文档。 xsl 转换可以在构建后事件中完成,也可以集成到文档生成过程中。
下面是 xsl:
为什么我想这样做:
DependencyProperty
实例)和属性都是公共的,因此可以合法地用于访问该财产。我们对同一个逻辑变量有两个 API。Ok, this is what I've come up with.
I use a special xml tag at the dependency properties that will be replaced by an xsl transformation. It would be possible to do it without it, but then Visual Studio issues a warning because the field appears undocumented.
The C# property is documented as usual, just make sure not to forget the value description.
Visual studio creates an xml file from those comments during building. With a little xsl transformation the
dpdoc
node is replaced by a modified version of the property documentation. The resulting xml file is the same as if we nicely documented the property identifier. It even includes a short note that there is an alternative way of accessing the variable:That way, both API's have proper documentation and we don't need to duplicate the documentation in the code. The xsl transformation can be done in the post-build events or be integrated in the documentation generation process.
Here's the xsl:
Why I want to have it that way:
DependencyProperty
instance) and the property, are public and can therefore legally be used to access the property. Thous we have two APIs to the same logical variable.您应该记录并维护两者。一个是依赖属性,另一个是常规属性,恰好是通过访问该依赖属性来实现的。它们不是同一件事,需要单独的文档。
You should document and maintain both. One is the dependency property, the other is a regular property that just happens to be implemented as accessing that dependency property. They are not the same thing and require separate documentation.