Proposal: Support generics and generic type parameters in aliases #90
-
Copied from dotnet/roslyn#3993 I propose the following changes to aliases to support generics:
* There's probably a better item in the spec for this. The purpose of this proposal is to allow aliases to be defined for unbound or partially bound generic types where the alias is then treated as a generic type that must be closed at the point at which it is used. For example the following is legal in C# today: using IntList = System.Collections.Generic.List<int>; This expansion would permit the following: // unbound
using MyList<T> = System.Collections.Generic.List<T>;
// partially bound
using StringDictionary<TValue> = System.Collections.Generic.Dictionary<String, TValue>; The name of the generic type parameter can be anything. The arguments are matched by their position in the aliased type. using FooList<FOO> = System.Collections.Generic.List<FOO>;
using ReorderedParameterDictionary<TValue, TKey> = System.Collections.Generic.Dictionary<TKey, TValue>; When consuming the alias the rules would apply the same as when consuming a generic type: MyList<int> list = new MyList<int>();
Debug.Assert(list is System.Collections.Generic.List<int>);
StringDictionary<bool> dict = new StringDictionary<bool>();
Debug.Assert(dict is System.Collections.Generic.Dictionary<string, bool>);
ReorderedParameterDictionary<int, string> dict2 = new ReorderedParameterDictionary<int, string>();
Debug.Assert(dict2 is System.Collections.Generic.Dictionary<string, int>); Arguments:
Complications:
The rules for aliases today already solves this problem by not permitting an alias to refer to itself or another alias. If that weren't the case this scenario would already be problematic: This is true. Given the
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Shouldn't this issue be closed? It's the same as #1239, which also includes the original comments from the roslyn repo. |
Beta Was this translation helpful? Give feedback.
Shouldn't this issue be closed? It's the same as #1239, which also includes the original comments from the roslyn repo.