Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow "using type aliases" inside generic classes and allow generic aliases #2123

Closed
mikernet opened this issue Jan 8, 2019 · 4 comments
Closed

Comments

@mikernet
Copy link

mikernet commented Jan 8, 2019

Currently "using type aliases" have to have known generic type parameters because they can't be inside a class. A propose that you allow them to be placed inside types so the generic parameters can be used to create aliases for generic types:

// Before:

public class WeakValueDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>> where TValue : class
{
    private Dictionary<TKey, WeakReference<TValue>> _lookup = new Dictionary<TKey, WeakReference<TValue>>();
    // ... 
}

// After:

public class WeakValueDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>> where TValue : class
{
    using Lookup = System.Collections.Generic.Dictionary<TKey, WeakReference<TValue>>;
    private Lookup _lookup = new Lookup();
    // ... 
}

Also somewhat related, allow generic using definitions so you could do something like this:

using WeakLookup<TKey, TValue> = System.Collections.Generic.Dictionary<TKey, WeakReference<TValue>>;

public class WeakValueDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>> where TValue : class
{
    private WeakLookup<TKey, TValue> _lookup = new WeakLookup<TKey, TValue>();
    // ... 
}
@svick
Copy link
Contributor

svick commented Jan 8, 2019

I think the second part of this proposal is a duplicate of #1239.

@alrz
Copy link
Contributor

alrz commented Jan 8, 2019

First part would be #218.

@mikernet
Copy link
Author

mikernet commented Jan 8, 2019

@alrz Partly yeah, the main motivation I intended here was to be able to use the type's generic type parameters in the using statement which seems like a separate feature.

@YairHalberstadt
Copy link
Contributor

Closing as duplicates of #1239 and #218 respectively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants