c# - How to properly merge lambda-expressions with different parameters -


i have 2 expressions :

expression<func<long, bool>> condition = x => x < max; // exp # 1  if (count > 0) {     expression<func<int, bool>> limit = x => x > -1; // exp # 2     condition = expression.lambda<func<long, bool>>(                 expression.andalso(condition, limit), condition.parameters); }  var comparator = condition.compile();  while (comparator(k++, n--)) {     // } 

the following code compiles takes 1 parameter of type "long" combined lambda, how can pass 2 different parameters combined lambda?

expression<func<long, bool>> condition = x => x < max; // exp # 1 expression<func<long, int, bool>> combined = null;  if (count > 0) {     expression<func<int, bool>> limit = x => x > -1; // exp # 2     combined = expression.lambda<func<long, int, bool>>(         expression.and(condition.body, limit.body),          new parameterexpression[]          {             condition.parameters[0],              limit.parameters[0]          }     ); } else {     // count <= 0, `int` parameter provided, `body` ignores     combined = expression.lambda<func<long, int, bool>>(         condition.body,          new parameterexpression[]          {             condition.parameters[0],              limit.parameters[0]          }     ); }  // compile `combined` expression var comparator = combined.compile();  while (comparator(k++, n--)) {     // } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -