gpt4 book ai didi

c# - 对委托(delegate)声明事件的 XML 注释

转载 作者:太空宇宙 更新时间:2023-11-03 16:55:00 25 4
gpt4 key购买 nike

我正在访问一些旧代码,并且有相当多的事件是通过委托(delegate)手动声明的,而不是使用 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 来记录库,因为它无法为事件声明生成的私有(private) Added 字段找到任何 XML 注释。我想尝试解决这个问题,但我想做的是:

  • 让 sandcaSTLe 忽略自动生成的私有(private)字段而不告诉它完全忽略所有私有(private)字段

  • 获取为私有(private)字段生成的 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;
}
}

最佳答案

虽然不是最理想的,但我找到了解决此问题的方法,即手动将 XML 注释放入包含项目命名空间级文档的文件中,如下所示:

<member name="F:myCompany.Common.Collections.Generic.EventableCollection`1.Added">
<summary>
Auto-generated backing field for the <see cref="E:myCompany.Common.Collections.Generic.EventableSortedList`1.Added">Added</see> event
</summary>
</member>

然后这大致给出了我所需要的。

关于c# - 对委托(delegate)声明事件的 XML 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2452944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com