对委托声明事件的 XML 注释
我正在访问一些旧代码,并且有相当多的事件是用委托手动声明的,而不是使用 EventHandler
/// <summary>
/// Delegate for event Added
/// </summary>
/// <param name="index">Index of the item</param>
/// <param name="item">The item itself</param>
public delegate void ItemAdded(int index, T item);
/// <summary>
/// Added is raised whenever an item is added to the collection
/// </summary>
public event ItemAdded Added;
一切都很好,直到我开始使用 sandcastle 来记录库,因为它可以'找不到由事件声明生成的私有“已添加”字段的任何 XML 注释。我想尝试解决这个问题,但我想做的是:
- 让 sandcastle 忽略自动生成的私有字段,而不告诉它完全忽略所有私有字段,
或者
- 获取为私有字段生成的 XML 注释
是否有无需重构代码即可实现此目的的方法如下:
/// <summary>
/// Delegate for event <see cref="Added"/>
/// </summary>
/// <param name="index">Index of the item</param>
/// <param name="item">The item itself</param>
public delegate void ItemAdded(int index, T item);
/// <summary>
/// Private storage for the event firing delegate for the <see cref="Added"/> event
/// </summary>
private ItemAdded _added;
/// <summary>
/// Added is raised whenever an item is added to the collection
/// </summary>
public event ItemAdded Added
{
add
{
_added += value;
}
remove
{
_added -= value;
}
}
I am visiting some old code, and there are quite a few events declared with delegates manually rather than using EventHandler<T>, like this:
/// <summary>
/// Delegate for event Added
/// </summary>
/// <param name="index">Index of the item</param>
/// <param name="item">The item itself</param>
public delegate void ItemAdded(int index, T item);
/// <summary>
/// Added is raised whenever an item is added to the collection
/// </summary>
public event ItemAdded Added;
All well and good, until I come to use sandcastle to document the library, because it then can't find any XML comments for the private Added field that is generated by the event declaration. I want to try and sort that out, but what I would like to do is either:
- Get sandcastle to ignore the auto-generated private field without telling it to ignore all private fields entirely
or
- Get XML comments generated for the private field
Is there any way of achieving this without re-factoring the code to look like this:
/// <summary>
/// Delegate for event <see cref="Added"/>
/// </summary>
/// <param name="index">Index of the item</param>
/// <param name="item">The item itself</param>
public delegate void ItemAdded(int index, T item);
/// <summary>
/// Private storage for the event firing delegate for the <see cref="Added"/> event
/// </summary>
private ItemAdded _added;
/// <summary>
/// Added is raised whenever an item is added to the collection
/// </summary>
public event ItemAdded Added
{
add
{
_added += value;
}
remove
{
_added -= value;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然不是最理想的,但我找到了解决这个问题的方法,即手动将 XML 注释放入包含项目命名空间级文档的文件中,大致如下:
这样就大致给出了我所需要的内容。
Although sub-optimal, I found a way around this, which was to manually put the XML comments into the file that contains namespace-level documentation for the project, along these lines:
This then gives roughly what I needed.