Support generic `IQueryable<T>` mapping
Support for generic IQueryable<T> mapping methods:
public static partial System.Linq.IQueryable<TTarget> Map<TSource, TTarget>(System.Linq.IQueryable<TSource> source);
private B Map(A source);
private D Map(C source);
// generates
public static partial System.Linq.IQueryable<TTarget> Map<TSource, TTarget>(System.Linq.IQueryable<TSource> source)
{
return source switch
{
IQueryable<global::A> x when typeof(TTarget).IsAssignableFrom(typeof(global::B)) => source.Select(...),
IQueryable<global::C> x when typeof(TTarget).IsAssignableFrom(typeof(global::D)) => source.Select(...),
_ => throw new System.ArgumentException($"Cannot map {source.GetType()} to {typeof(IQueryable<TTarget>)} as there is no known type mapping", nameof(source)),
};
}
Similar to the existing generic mapping methods (docs), type constraints should also be supported.
Brought up by @19bartek92 in https://github.com/riok/mapperly/discussions/960#discussion-5910036
Thanks for this, i briefly look into it.
Are switch expressions supported for IQueryable? ### Also should the source parameter be IQueryable<object>, can't look at the tests or source code rn
@TimothyMakkison The switch expression doesn't happen inside the Expression/Select, therefore I think it should work.
We should support the same feature set as we are supporting for regular generic mappings (where possible), therefore we should support IQueryable<T> as well as IQueryable<object> as source.
@TimothyMakkison The switch expression doesn't happen inside the
Expression/Select, therefore I think it should work.
Thanks, I was a little confused because the docs only mentioned the object source for generic mapping.
We should support the same feature set as we are supporting for regular generic mappings (where possible), therefore we should support
IQueryable<T>as well asIQueryable<object>as source.
Might be worth creating an issue to track all the variants for this and existing target mapping. I have an idea for IQueryable<TSource> but haven't looked into the others
@TimothyMakkison I think existing target mapping isn't relevant for IQueryable, is it?
Sorry, I was suggesting that an issue needs to track each variant of generic mapping for IQueryable and for generic existing target mapping
Ah got it, I'll probably create one if needed after the initial implementation. Probably it's easy enough to implement all here in the first version of the implementation.
:tada: This issue has been resolved in version 3.5.0-next.4 :tada:
The release is available on:
- GitHub release
v3.5.0-next.4
Your semantic-release bot :package::rocket: