Inheritance: System.Linq.Expressions.ExpressionVisitor
Beispiel #1
0
 protected override Expression VisitMember(MemberExpression node)
 {
     if (typeof(IModelElement).IsAssignableFrom(node.Type) && !typeof(IModelElement).IsAssignableFrom(node.Expression.Type))
     {
         var parameterCollector = new ParameterCollector();
         parameterCollector.Visit(node);
         parameterCollector.Parameters.IntersectWith(lambdaParameters);
         if (parameterCollector.Parameters.Count > 0)
         {
             return(node);
         }
         var replaceMemberId = node.ToString();
         ParameterExtraction extraction;
         if (!parameters.TryGetValue(replaceMemberId, out extraction))
         {
             extraction = new ParameterExtraction(Expression.Parameter(node.Type, "model_par_" + parameters.Count.ToString()), node);
             parameters.Add(replaceMemberId, extraction);
         }
         return(extraction.Parameter);
     }
     return(base.VisitMember(node));
 }
 private bool CheckConflictingExtractions(Dictionary <string, ParameterExtraction> extractionsSaved, LambdaExpression lambda)
 {
     if (parameterextractions.Count > extractionsSaved.Count)
     {
         foreach (var extraction in parameterextractions)
         {
             if (!extractionsSaved.ContainsKey(extraction.Key))
             {
                 var parametersUsed = new ParameterCollector();
                 parametersUsed.Visit(extraction.Value.Value);
                 foreach (var parameter in lambda.Parameters)
                 {
                     if (parametersUsed.Parameters.Contains(parameter))
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }