internal LambdaExpression CreateInlineMapExpression(Type sourceType, Type destinationType, MapType mapType, CompileContext context) { var tuple = new TypeTuple(sourceType, destinationType); if (context.Running.Contains(tuple)) { return(CreateInvokeExpression(sourceType, destinationType)); } context.Running.Add(tuple); try { var exp = CreateMapExpression(sourceType, destinationType, mapType == MapType.Projection ? MapType.Projection : MapType.InlineMap, context); if (exp != null) { var detector = new BlockExpressionDetector(); detector.Visit(exp); if (detector.IsBlockExpression) { exp = null; } } return(exp ?? CreateInvokeExpression(sourceType, destinationType)); } finally { context.Running.Remove(tuple); } }
internal LambdaExpression CreateInlineMapExpression(Type sourceType, Type destinationType, MapType mapType, CompileContext context) { var tuple = new TypeTuple(sourceType, destinationType); if (context.Running.Contains(tuple)) { if (mapType == MapType.Projection) { throw new InvalidOperationException( $"Projection does not support circular reference: TSource: {sourceType} TDestination: {destinationType}"); } return(CreateInvokeExpression(sourceType, destinationType)); } context.Running.Add(tuple); try { var exp = CreateMapExpression(sourceType, destinationType, mapType == MapType.Projection ? MapType.Projection : MapType.InlineMap, context); if (exp != null) { var detector = new BlockExpressionDetector(); detector.Visit(exp); if (detector.IsBlockExpression) { exp = null; } } return(exp ?? CreateInvokeExpression(sourceType, destinationType)); } finally { context.Running.Remove(tuple); } }
internal LambdaExpression CreateInlineMapExpression(Type sourceType, Type destinationType, MapType parentMapType, CompileContext context) { var tuple = new TypeTuple(sourceType, destinationType); if (context.Running.Contains(tuple)) { if (parentMapType == MapType.Projection) { throw new InvalidOperationException("Projection does not support circular reference"); } return(CreateMapInvokeExpression(sourceType, destinationType)); } context.Running.Add(tuple); try { var arg = GetCompileArgument(tuple, parentMapType, context); var exp = CreateMapExpression(arg, true); if (exp != null) { var detector = new BlockExpressionDetector(); detector.Visit(exp); if (detector.IsBlockExpression) { exp = null; } } if (exp != null) { return(exp); } if (parentMapType == MapType.MapToTarget) { return(CreateMapToTargetInvokeExpression(sourceType, destinationType)); } else { return(CreateMapInvokeExpression(sourceType, destinationType)); } } finally { context.Running.Remove(tuple); } }