0

Imagine the following code

public interface IFoo 
{
    /// <summary>
    /// Gets bar
    /// </summary>
    string Bar();
}

public class Foo : IFoo // fixed, as a miss from my simplified example for SO
{
    public string Bar() { return "Bar"; }
}

Visual Studio correctly shows the code comments in the intellisense popup when you code like this:

IFoo instance = new Foo(); // shows what is in IFoo

but if you use the var syntax it does not show the code comments from the interface

var instance = new Foo(); // only shows what is in class Foo

In an attempt to remediate this, I've tried throwing a <see> tag into the summary on class Foo which points to interface IFoo, however this doesn't work.

Is there a tag/way to allow the interface comments to pass through in all use cases?

For what its worth, I did read/review this question on a similar topic, providing two different comments isn't realistic for every method in every case (often they're one and the same, used only for injection and testing) so providing different flavor comments on both wont work, at least not for all cases.

Patrick
  • 1,717
  • 7
  • 21
  • 28
Nate
  • 30,286
  • 23
  • 113
  • 184

2 Answers2

0

You can use the "inheritdoc" element in the XML documentaion.

public interface IFoo
{
    /// <summary>
    /// gets Bar
    /// </summary>
    string Bar();
}

public class Foo : IFoo
{
    /// <inheritdoc />       
    public string Bar() { return "Bar"; }
}
-1

First of all, your code doesn't implement the interface... but that's not the cause. How about including the summary block in the implementation as well as in the interface?

public interface IFoo
{
    /// <summary>
    /// gets Bar
    /// </summary>
    string Bar();
}

public class Foo : IFoo
{
    /// <summary>
    /// gets Bar
    /// </summary>        
    public string Bar() { return "Bar"; }
}
Peter Huppertz
  • 361
  • 3
  • 7
  • This is quite redundant and prone to getting out of sync. In many cases, the *should* be the same, but I don't want to maintain two separate copies manually. Thus my question, is there a way to do this without manually keeping two copies in sync? – Nate Nov 25 '17 at 01:08