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 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
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
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<T> = Dictionary<string, T>;
(C# 1:) using DictionaryOfMyClass<> = Dictionary<string, int>;
(C# 2:) using StringDictionary<T> = Dictionary <string, T>
using IStringDictionary<T> = IDictioanry < string, T > (interface example)