Generic expression abstraction issue

纵然是瞬间 提交于 2019-12-04 17:25:26

The key difference between your two implementations is that the second captures a method parameter, while the first does not. The parameter gets stored as a field in a closure, and the presence of that field access is probably causing problems in RefactorThis.GraphDiff.dll.

Try changing the second implementation as follows:

protected void SetOwnedCollectionMapping<T>(Expression<Func<TDataEntity, ICollection<T>>> mapping)
{
    //
    // Hack to resolve the `OwnedCollection` extension method.
    //
    Expression<Func<IUpdateConfiguration<TDataEntity>, object>> template = 
        _ => _.OwnedCollection(mapping);

    var map = Expression.Parameter(
        typeof(IUpdateConfiguration<TDataEntity>),
        "map");

    graphMapping = Expression.Lambda<Func<IUpdateConfiguration<TDataEntity>, object>>(
        Expression.Call(
            ((MethodCallExpression)template.Body).Method,
            map,
            Expression.Quote(mapping)),
        map);
}

The value of graphMapping should then be identical to that produced by your first implementation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!