2

I have generic class

public class Range<T> where T : IEquatable<T>
{
    ///<summary>
    /// Minimum value of Range<T>
    ///</summary>
    public T Min;
}

and if I were to call class as

public Range<int> range;

how would I get the tooltip for Min to show that it is the Min value of Range<int> instead of Range<T>?

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • The XML commenting feature is documented [here](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments), There seems to be no reference to its being dynamic. – Peter Smith Oct 14 '18 at 18:14
  • I suspect the XML docs were intended to be static so that you can generate it from the source code. VIsual Studio intellisense just does its best by interpreting it as it is. There is e.g. a [typeparamref](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/typeparamref) that you can use to semantically denote the `T` parameter but the intellisense does not interpret it based on the actual runtime type (albeit it may be known to the intellisense at that point). As a side note, specifying the type name in field description seems redundant. – Zdeněk Jelínek Oct 14 '18 at 18:18
  • Possible duplicate of [How to reference generic classes and methods in xml documentation](https://stackoverflow.com/questions/532166/how-to-reference-generic-classes-and-methods-in-xml-documentation) – Andersnk Oct 14 '18 at 18:20
  • @Andersnk That's not the same question, that's about referencing another class/method – Camilo Terevinto Oct 14 '18 at 18:24
  • 1
    @ZdeněkJelínek I dont mind if generated documentation for my code displays as T, it's in the tooltip where I want the selected T type to be displayed. If that makes any sense –  Oct 14 '18 at 18:31

1 Answers1

0

If you look at CLR types, you will find out this is not done, because it cannot be done and it shouldn't be done either. Visual Studio already advertises you what's T.

Following c# conventions, look at something like this:

public class Range<T> where T : IEquatable<T>
{
    ///<summary>
    /// Gets or sets the minimum value
    ///</summary>
    public T Min { get; set; }
}

Which, when used as this:

var range = new Range<string>();
range.Min = "ab";

If you hover over Min, you will see:

enter image description here

So you clearly see that the current <T> is <string>.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
  • I was aware of that, the particular class i used was a) just an example and b) probably not the best choice for an example. But it was where it says Get or Set the minimum value that I want it to say Get or Set the mimimum value of Range as opposed to Range. –  Oct 14 '18 at 18:36
  • @Jdoonan Ok, so the short answer is no, you cannot get the current T. – Camilo Terevinto Oct 14 '18 at 18:37
  • Thank you, I have been creating a bunch of Generic Extension methods and as wanting to explain the classes as the type called rather than always as T, if that possibly changes anything. –  Oct 14 '18 at 18:39
  • @Jdoonan I understand. You can use `` to differentiate between different `T`s but I could understand that doesn't help much. Look at LINQ, though, every single method is explained in a way that the `T`s are rather unimportant – Camilo Terevinto Oct 14 '18 at 18:42
  • I would like to add to the previous comment that actually reading documentation saying that e.g. `Enumerable.Select` projects `int`s to `TResult`s (see [Enumerable.Select at MS doc](https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable.select?view=netframework-4.7.2)) would have me confused as to whether the method is actually generic in the input parameter. – Zdeněk Jelínek Oct 14 '18 at 20:16