-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
Support generic mappings #1285
Comments
If you can point me to the solution, I can implement it. |
Thanks for opening this. It seems to be somewhat related to #884 and #451.
These are the points that currently come to my mind. Examplepublic partial IReadOnlyCollection<S, T> MapItems<S, T>(IReadOnlyCollection<S> source)
{
var target = new T[source.Count];
var i = 0;
foreach (var item in source)
{
target[i] = MapItem(item);
i++;
}
return target;
}
public partial T MapItem<S, T>(S source)
{
return source switch
{
A x when typeof(T).IsAssignableFrom(typeof(B)) => MapToB(x),
IReadOnlyCollection<A> x when typeof(IReadOnlyCollection<B>).IsAssignableFrom(typeof(IReadOnlyCollection<B>)) => MapItems<A, B>(x),
_ => throw ...,
}
}
public partial B MapToB(A source)
{
return new B(source.Value);
} |
Is your feature request related to a problem? Please describe.
Mapping definition
produces nice mapping using an array:
When you change it to generic:
it refuses to generate array mapping.
Describe the solution you'd like
Additional context
Failing test
Workaround:
Add another (specific-non-generic) mapping, then generic arm-search finds a match. The downside is that you need to define it for all generic arguments (which makes it ugly)
The text was updated successfully, but these errors were encountered: