4

I'm having trouble getting the generic parameters for the two methods below to display the types in Intellisence.

For the IEnumerable<T> I just simply want it to show as double.

Intellisence screenshot for IEnumerable<T> Method

And for the IDictionary<TKey,TValue> overload, I want it to show KeyValuePair<int,string> but of course without hard-coding the types.

Intellisence screenshot for KeyValuePair<TKey, TValue> Method

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Common.FluentValidation
{
    public static partial class Validate
    {
        /// <summary>
        /// Compares two dictionaries are null or contain equal sets of items.
        /// Returns true if both instances are null or contain equal sets of <see cref="T:System.Collections.Generic.KeyValuePair'1{TKey}{TValue}"></see> items; otherwise, false.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TValue">The type of the value.</typeparam>
        /// <param name="A">The first instance to compare</param>
        /// <param name="B">The second instance to compare</param>
        /// <returns>true if both instances are null or contain equal sets of <see cref="T:System.Collections.Generic.KeyValuePair'1{TKey}{TValue}"></see> items; otherwise, false.</returns>
        public static bool AreBothNullOrEqualSets<TKey, TValue>(IDictionary<TKey, TValue> A, IDictionary<TKey, TValue> B)
        {
            // XOR for null
            if ((A == null) ^ (B == null))
                return false;

            // Compare each value in set
            if (A != null)
                if (!A.OrderBy(x => x.Key).SequenceEqual(B.OrderBy(x => x.Key)))
                    return false;

            return true;
        }

        /// <summary>
        /// Compares two sequences are null or contain equal sets of items.
        /// Returns true if both instances are null or contain equal sets of <see cref="T:Common.FluentValidation.AreBothNullOrEqualSets`1"/> items; otherwise, false.
        /// </summary>
        /// ///  for more information.
        /// <typeparam name="T">The type of the enumerable.</typeparam>
        /// <param name="A">The first instance to compare</param>
        /// <param name="B">The second instance to compare</param>
        /// <returns>true if both instances are null or contain equal sets of <see cref="T:Common.FluentValidation.AreBothNullOrEqualSets`1"/> items; otherwise, false.</returns>
        public static bool AreBothNullOrEqualSets<T>(IEnumerable<T> A, IEnumerable<T> B)
        {
            // XOR for null
            if ((A == null) ^ (B == null))
                return false;

            // Compare each value in set
            if (A != null)
                if (!A.SequenceEqual(B))
                    return false;

            return true;
        }
    }
}

I searched and found a few hints, but have attempted several things with no luck. Best I can get is for it to just display "T" in the Intellisence balloon, which leaves something to be desired...

EDIT:

Here's Microsoft doing it on the class level type params... but not on the constructor... So is this possible for methods/constructors? (ideally I want to show the types inlined with my comments, but the way it is in the example image below is perfectly acceptable as well)

Microsoft Can do it

Community
  • 1
  • 1
HodlDwon
  • 1,131
  • 1
  • 13
  • 30

1 Answers1

2

Though this is a very old question, I've found myself today struggling with the exact same issue - and I regret to say that it doesn't look like there's a real solution.

using <see cref="Dictionary{int, string}"> will cause the following warning (at least on VS 2017):

CS1584 XML comment has syntactically incorrect cref attribute 'Dictionary{int, string}'

When hovering over the green squiggle, VS will show a tool-tip saying (among other things):

Type parameter declaration must be an identifier not a type. See also error CS0081.

The only solution I came up with is simply to add a couple of paragraphs specifying the types of TKey and TValue:

/// <summary>
/// Gets a <see cref="Dictionary{TKey, TValue}"/> that maps ints to strings.
/// <para>
/// TKey is <see cref="int"/>.
/// </para>
/// <para>
/// TValue is <see cref="string"/>.
/// </para>
/// </summary>
public Dictionary<int, string> Map {get;}

Intellisence will show it like this:

Gets a Dictionary<TKey, TValue> that maps ints to strings.
TKey is int.
TValue is string.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • 1
    Better than nothing, I suppose, but doesn't really explain why it can't parse what was originally there. Annoying choices by Microsoft here. But what the # do we know? – ruffin Jul 23 '20 at 21:05