【问题标题】:Get .Net XML documentation to return specific type for Dictionary获取 .Net XML 文档以返回 Dictionary 的特定类型
【发布时间】:2013-07-04 09:02:22
【问题描述】:

我有这样的方法:

/// <summary>
/// Gets a typed Dictionary of <see cref="T:System.Collections.Generic.Dictionary`2"/> 
/// </summary>
/// <returns></returns>
public Dictionary<string, object> ToDictionary()

当我调用此方法并查看智能感知时,它显示它返回 Dictionary&lt;TKey,TValue&gt;

智能感知有没有办法显示Dictionary&lt;string, object&gt;

我尝试了以下方法,但失败了:

<see cref="System.Collections.Generic.Dictionary`2[System.String,System.Object]"/>

这是我看到的:

【问题讨论】:

  • 但它确实如您所愿在弹出窗口中显示Dictionary&lt;string, object&gt;
  • 是的,它只是智能感知中显示 Dictionary 的注释位

标签: c# .net visual-studio xml-comments


【解决方案1】:

这应该可行:

/// <summary>
/// Gets a typed Dictionary of <see cref="Dictionary{String, Object}" />
/// </summary>
/// <returns></returns>
public Dictionary<string, object> ToDictionary()
{
    return null;
}

【讨论】:

  • 但是您到底想看到什么?我认为您需要在弹出窗口中使用确切的类型 - 它们现在就在那里。
  • 谢谢,但我得到的是花括号而不是尖括号,这可能是一个限制
  • 我猜他们想要的是 而不是 {string,object}。但是,cref 属性的文档 (msdn.microsoft.com/en-us/library/cc837134.aspx) 声明要使用 { 和 }。生成的 XML 文件看起来是正确的,所以我认为这实际上可能是要走的路。当然,如果你想让 Sandcastle 和类似的东西用自定义文本生成它,你可以将自定义文本设置为 see-element 的内容。但是,VS 会忽略该内容。
【解决方案2】:

您“可以”在泛型类级别声明类型

public Dictionary<T, T2> ToDictionary()

然后使用文档如

/// <typeparam name="T">The type of xxxx</typeparam>
/// <typeparam name="T2">The type of xxxx</typeparam>

只是一个想法......

直流

【讨论】:

  • 这个类是动态字典,所以在构造类时我无法指定类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-15
  • 1970-01-01
  • 2014-06-27
  • 1970-01-01
  • 2013-09-20
  • 2019-02-26
相关资源
最近更新 更多