簡體   English   中英

在 C# XML 評論中,如何引用另一種方法的參數?

[英]In C# XML comments, how can I refer a parameter of another method?

在 MethodB XML 文檔中,我想寫類似

/// <remarks>Before calling this method, call <see cref="MethodA"> passing zero as <paramef name="MethodA.MyParam"/> value.

MethodA 聲明為

void MethodA(int MyParam)

可能嗎? 目前,我必須這樣寫:

/// <remarks>Before calling this method, call <see cref="MethodA"> passing zero as <i>MyParam<i/> value.

當然,這會導致潛在的錯誤,因為如果我打錯字或更改代碼中的名稱,編譯器不再警告我參數名稱錯誤。

你不能

但是,您可以聲明一個IsReady的公共屬性,並在正確調用MethodA時將其設置為true。

MethodB應該檢查該屬性,如果其值為false,則拋出InvalidOperationException 然后將此XML注釋添加到MethodB

/// <exception cref="InvalidOperationException">
///     <see cref="IsReady" /> is <c>false<c>.
/// </exception>

這樣,您的實例狀態就可以公開使用,因此調用者無需事先知道是否使用正確的參數調用了MethodA ,它只需檢查IsReady是否為true。

我認為,傳遞什么參數將使實例“就緒”應該在MethodA自己的文檔中,而不是在MethodB的文檔中。

WAYYYY 晚了(6 年),但是怎么樣:

public class Foo
{
    /// <remarks>
    /// <para>
    /// Custom InnerHTML:<br/>
    ///   <see cref="Foo.Bar(System.Boolean)">value</see> argument from another method.
    /// </para>
    /// <para>
    /// Custom InnerHTML w/Embedded Inline-Code Element:<br/>
    ///   <see cref="Foo.Bar(System.Boolean)"><c>value</c></see> argument from another method.
    /// </para>
    /// </remarks>
    public void NotBar() { }

    /// <summary>
    /// If you call this method, feces will hit the rotating metallic blades.
    /// </summary>
    /// <param name="value">The value.</param>
    public void Bar(bool value) { }
}

暫無
暫無

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

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