如何在XML文档中引用C#关键字?

Dan*_*fer 53 c# keyword xml-documentation

<see cref="switch" />,例如,不起作用 - 我收到编译警告: XML comment on ... has syntactically incorrect cref attribute 'switch'


感兴趣的人的背景......

/// <summary>Provides base functionality for hand-coded abstractions of API method wrappers, mostly those that abstract over
/// parameters that are required to be JSON-encoded.</summary>
public class FacebookArgs : Dictionary<String, Object>
{
    /// <summary>Initializes an instance of <see cref="FacebookArgs" />.</summary>
    public FacebookArgs() { }

    /// <summary>Intializes an instance of <see cref="FacebookArgs" />, that contains elements copied from <paramref name="dictionary "/>.</summary>
    /// <param name="dictionary"></param>
    public FacebookArgs(IDictionary<String, Object> dictionary)
        : base(dictionary) { }

    /// <summary>Gets or sets the value associated with the specified key.</summary>
    /// <param name="key">The key of the value to get or set.</param>
    /// <returns>The value associated with the specified key.</returns>
    /// <remarks>This implementation hides the base indexer implementation such that specifying a key that does not exist returns null rather than throwing a <see cref="KeyNotFoundException" />.</remarks>
    public new Object this[String key]
    {
        get
        {
            Object value;
            if (this.TryGetValue(key, out value)) return value;
            else return null;
        }
        set { base[key] = value; }
    }

    /// <summary>In derived classes, provides specialized serialization logic for specific properties contained in this object.</summary>
    /// <param name="key">The key of the property to serialize.</param>
    /// <param name="args">A reference to a dictionary of arguments that will be passed directly to a <see cref="FacebookRequest" /> object.</param>
    /// <remarks>
    /// <para>This method allows specialized serialization logic, such as JSON encoding, to be applied to specific properties.</para>
    /// <para>To implement, use a <c>switch</c> (<c>Select</c> in VB.NET) statement to filter based on <paramref name="key" /> and provide the property-specific logic.
    /// The resulting value should then be added to <paramref name="args" /> using the same <paramref name="key "/>.
    /// </para>
    /// <para>Properties that do not require additional processing (strings, integral values, etc) should be ignored.</para>
    /// </remarks>
    protected virtual void SerializeProperty(String key, ref IDictionary<String, Object> args) { }

    /// <summary>Returns a dictionary of key/value pairs suitable to be passed a <see cref="FacebookRequest" /> object.</summary>
    /// <returns>A dictionary of key/value pairs suitable to be passed a <see cref="FacebookRequest" /> object.</returns>
    /// <remarks>This method calls the <see cref="SerializeProperty" /> for each key in the object, which allows property-specific processing
    /// to be done on any property.</remarks>
    /// <seealso cref="SerializeProperty" />
    public IDictionary<String, Object> GetArgs()
    {
        IDictionary<String, Object> args = new Dictionary<String, Object>();

        foreach (String key in this.Keys)
        {
            this.SerializeProperty(key, ref args);

            if (!args.ContainsKey(key) && this[key] != null)
            {
                args.Add(key, this[key]);
            }
        }

        return args;
    }
}
Run Code Online (Sandbox Code Playgroud)

有问题的标签可以在被发现<remarks>的标签SerializeProperty.我在冗长的文档方面犯了错误.我还打算提供一些<example>s,我还没有完成它.

Jon*_*eet 81

cref是指另一个成员 - 一个类,一个方法等.

在这种情况下,您希望它链接到什么?一般来说,你想要的整体效果是什么?

根据这篇优秀的XML文档指南,该<see>标记具有未记录的属性langword:

<see langword="switch" />
Run Code Online (Sandbox Code Playgroud)

这对你有帮助吗?可能值得尝试它只是为了看它做什么.

如果您只想使用普通超链接,请使用href而不是cref:

<see href="http://msdn.microsoft.com/en-us/library/06tc147t.aspx">switch</see>
Run Code Online (Sandbox Code Playgroud)

  • 未来,当 Microsoft [文档](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags#see) `&lt;see langword="..." 时,您好/&gt;` (7认同)
  • 链接的XML文档指南目前正在返回404.这是返回机器上同一篇文章的链接:http://web.archive.org/web/20080623060531/http://thoughtpad.net/alan-dean/cs -xml-documentation.html上 (3认同)
  • 我必须承认,我以前从未见过这个属性。我刚刚知道这个页面,并且看到了它本身所说的内容:) (2认同)
  • 我想`<see> ... </a>`是一个错字.两者,`<see href ="link"> </ see>`和`<a href="link"> </a>`适用于普通超链接(使用Sandcastle测试:[SHFB](https:// shfb. codeplex.com/)). (2认同)