src/NetStandard/Linq/Expressions/Expressions/src/SourceTargetExpressionTools.cs
/// <summary>
/// Replaces all expressions by those expressions who are defined
/// with the help of <paramref name="configureMemberMappings"/>.
/// </summary>
/// <typeparam name="SourceType">The source type.</typeparam>
/// <typeparam name="TargetType">The target type.</typeparam>
/// <param name="expression">The expression which may expressions</param>
/// <param name="sourceParameter">The source parameter expression who may 
/// used by those expressions you want to have replaced.</param>
/// <param name="configureMemberMappings">Configures the expression 
/// mappings.</param>
/// <param name="targetParameter">The new target expression parameter that
/// is used in replacement of the source target expression.</param>
/// <returns>The expression with replaced expressions.</returns>
Replaces all expressions by those expressions who are defined
with the help of .
Replaces all expressions by those expressions who are defined with the help of .
public static Expression ReplaceExpressions<SourceType, TargetType>(
            Expression expression, 
            ParameterExpression sourceParameter,
            ref ParameterExpression? targetParameter, 
            Action<IParameterReplacableExpressionMapper<SourceType, TargetType>> configureMemberMappings)
        {
            targetParameter ??= Expression.Parameter(typeof(TargetType), "targetAsSource");
            var memberMappingBuilder = new ParameterReplacingExpressionMapper<SourceType, TargetType>(sourceParameter, targetParameter);
            configureMemberMappings(memberMappingBuilder);
            var memberMappings = memberMappingBuilder.GetMappings().ToList();
            if (memberMappings == null || memberMappings.Count == 0) {
                return expression;
            }
            var memberPathReplacer = new EqualityComparingExpressionReplacerVisitor(memberMappings);
            expression = memberPathReplacer.Visit(expression);
            return expression;
        }
public static Expression ReplaceExpressions < SourceType , TargetType > ( Expression expression , ParameterExpression sourceParameter , ref ParameterExpression ? targetParameter , Action < IParameterReplacableExpressionMapper < SourceType , TargetType > > configureMemberMappings ) { targetParameter ??= Expression . Parameter ( typeof ( TargetType ) , " " ) ; var memberMappingBuilder = new ParameterReplacingExpressionMapper < SourceType , TargetType > ( sourceParameter , targetParameter ) ; configureMemberMappings ( memberMappingBuilder ) ; var memberMappings = memberMappingBuilder . GetMappings ( ) . ToList ( ) ; if ( memberMappings == null || memberMappings . Count == 0 ) { return expression ; } var memberPathReplacer = new EqualityComparingExpressionReplacerVisitor ( memberMappings ) ; expression = memberPathReplacer . Visit ( expression ) ; return expression ; }
Replaces all expressions by those expressions who are defined
with the help of .
Replaces all expressions by those expressions who are defined with the help of .
The expression with replaced expressions.
The expression with replaced expressions .
expression
Expression
The expression which may expressions
The expression which may expressions
sourceParameter
ParameterExpression
The source parameter expression who may
used by those expressions you want to have replaced.
The source parameter expression who may used by those expressions you want to have replaced .
ParameterExpression?
ref
configureMemberMappings
Action<IParameterReplacableExpressionMapper<SourceType, TargetType>>
Configures the expression
mappings.
Configures the expression mappings .
targetParameter
The new target expression parameter that
is used in replacement of the source target expression.
The new target expression parameter that is used in replacement of the source target expression .
typeparam
The source type.
The source type .
typeparam
The target type.
The target type .