簡體   English   中英

如何為復雜表達式添加 c# xml cref 注釋?

[英]How to add c# xml cref comment for a complex expression?

我想為表達式Bars[0].Name添加一個 cref

這是代碼,但它會生成 2 個警告
在此處輸入圖像描述 在此處輸入圖像描述

using System.Collections.Generic;

namespace MyProject
{
    class IFoo
    {
        public Bars Bars { get; } = new Bars();

        /// <summary>
        /// Returns true if <see cref="Bars[0].Name"/>  is empty or null.
        /// </summary>
        /// <value>Indicates if name is empty or null</value>
        public bool IsFirstBarChildNameEmptyOrNull() =>
            Bars.Count == 0 || string.IsNullOrEmpty(Bars[0].Name);
    }

    class Bars
    {
        private List<Child> _children = new List<Child>();

        public Child this[int index] => _children[index];
        public int Count => _children.Count;
    }

    class Child
    {
        public string Name { get; set; }
    }
}

如何在不生成警告的情況下添加此 cref?

你不能直接那樣做。

可以通過將其分成兩部分來接近,如下所示:

/// <summary>
/// Returns true if <see cref="Bars"/>[0].<see cref="Child.Name"/> is empty or null.
/// </summary>
/// <value>Indicates if name is empty or null</value>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM