How to reference a parameter of a different method

2019-06-17 05:47发布

问题:

Is it possible to reference a parameter from a different method than the one you are writing a summary for, and if so what is the syntax.

I know about <paramref name="..."/> but I don't know how to reference from a different method.

Simple humorous example in case I'm not making myself clear:

/// <summary>
/// Does magical Foo things!
/// </summary>
/// <param name="magic">Magic Toggle!</param>
public void Foo(bool magic)
{
    //...
}

/// <summary>
/// Does Bar things. More down to earth, no <paramref name="Foo(bool).magic"/> involved!
/// </summary>
public void Bar()
{
    //...
}

(Obviously the above is not a great use case, it's just for illustratory purposes.)

回答1:

There is no recommended tag for this.

I suspect the reason why there is no recommended tag is because the primary use-case of this documentation is generated documentation in the style of the MSDN pages which doesn't make use of links to specific parameters of other methods. That said, its not a spec, just a recommendation. any valid XML you write will end up in the output XML file, so if you have a custom documentation generator which would make use of this there is nothing stopping you from adding "custom" tags that do whatever it is you need.

Personally I'd just do something like this:

interface IFoo
{
    void Foo(object otherParam);

    /// <summary>Documentation for this method.</summary>
    /// <returns>The object passed as the otherParam argument of
    /// the <see cref="Foo" /> method.</returns>
    object Bar();
}


标签: c# sandcastle