27

If I have these two methods

public Foo Get(string bar) { ... }
public Foo Get(int bar) { ... }

And write this piece of xml documentation on a different method

/// <summary>
/// Has a close relation to the <see cref="Get"/> methods.
/// </summary>

I get a blue squiggly under Get, saying that it is an Ambiguous reference 'Get'. which is true, but I want it to reference both. What is the correct way of doing this? Or should am I only supposed to reference a single method overload?

Svish
  • 138,188
  • 158
  • 423
  • 589
  • Possible duplicate of [How to make a cref to method overloads in a tag in C#?](https://stackoverflow.com/questions/419702/how-to-make-a-cref-to-method-overloads-in-a-seealso-tag-in-c) – binki May 31 '17 at 23:59

2 Answers2

27

Try

/// Has a close relation to the <see cref="Get(string)"/>  
/// and <see cref="Get(int)" /> methods.

You may need full typenames but intellisense should help as soon as you put first bracket in.

Hope that helps,

Dan

Daniel Elliott
  • 21,751
  • 10
  • 60
  • 82
  • 1
    Indeed! However, if you have a lot of overloads that could be a smell telling you there is a refactor in the works. Kindness, Dan – Daniel Elliott Aug 18 '09 at 18:41
  • 3
    I would really hope there'd be some way to do what the OP originally wanted. While this approach is practical in the absence of a better way, it's also sloppy, in the sense that the argument list is an _implementation detail_ which isn't relevant to the actual remark being made. If at some later time a third overload were added and this remark forgotten, it would incorrectly suggest that the remark _doesn't_ apply to that new overload when in fact it probably does. (I think I've seen a closer approach but can't remember it unfortunately.) – Kevin Oct 19 '13 at 05:49
3

Here's an updated answer to this old question. I'm not sure when this became valid because there isn't much documentation out there. If you prefix a cref attribute with "o:..." such as in "o:myMethod()" it will link to the overload section and cover all of the overloads of that method. Using Daniel Elliott's answer's example:

/// Has a close relation to the <see cref="o:Get()"/> methods.  

This will also remove warnings from Intellisense / Resharper about ambiguous references.

JNYRanger
  • 6,270
  • 12
  • 46
  • 71
  • I notice when I do this, the IntelliSense popup for the applied method no-longer syntax-colors the `` content anymore. I also lose warnings that the method exists at all - so I'm not sure this is a good solution. – Dai Oct 31 '19 at 01:46
  • Not sure where you got this from, but it does not seem to work in VS Community in version 16.4.5. It just shows up as text and is no different than skipping the `see` tag altogether. – Krzaku Mar 04 '20 at 13:10