I suggest you ...

Proper (generic) type alising

F# has proper type aliasing, which allows partial resolving of generics:

type StringDictionary<T> = Dictionary<string, T>

However, C# only allows type aliasing when the target is fully resolved:

using StringDictionryOfMyClass = Dictionary<string, MyClass>;

Doing type aliasing the F# (the "right" away) would be much more useful! Hopefully I can just type:

using StringDictionary<T> = Dictioanry<string, T>;
using IStringDictionary<T> = IDictionary<string, T>;

And get the type alias -- The emitted CIL shoudl be Dictionary<string, T>, not a new interface / class named StringDictionary, since that will break polymorphism (i don't want to introduce new types, just want to rename existing ones in my program, filling in some of the type parameters!).

Thanks.

32 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Stephen Kou shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.

    - The Visual Studio Team

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Qwertie commented  ·   ·  Flag as inappropriate

        At least as important, it would be useful if "using" were supported inside a class, for cases when generic classes depend on each other:

        class GenericClass<Abc, Xyz>
        {
        // Imagine that GenericClass uses this data type in 30 different places.
        // The fully qualified name is very cumbersome.
        using Aggregator = IAggregator<Xyz, Func<Abc, Xyz>, Xyz>;
        // And yes, long generic types are a real problem in a library I wrote
        ...
        }

      • Stephen Kou commented  ·   ·  Flag as inappropriate

        It looks like there's a bug on this site, it's stripping out my angle brackets. The code snippet are acutally:

        (F#: ) type StringDictionary&lt;T&gt; = Dictionary&lt;string, T&gt;;
        (C# 1:) using DictionaryOfMyClass&lt;&gt; = Dictionary&lt;string, int&gt;;
        (C# 2:) using StringDictionary&lt;T&gt; = Dictionary &lt;string, T&gt;
        using IStringDictionary&lt;T&gt; = IDictioanry < string, T > (interface example)

      Feedback and Knowledge Base