Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Assuming the two lists are named list1 and list2, you can use the following code to merge them:

List<Func<bool>> mergedList = new List<Func<bool>>();
mergedList.AddRange(list1);
mergedList.AddRange(list2);

To add options for OR/AND between the items within the resulting list, you can use LINQ to perform the filtering based on the options:

bool useAndBetweenItems = true; // Set to true for AND and false for OR

var merged = mergedList.Aggregate((useAndBetweenItems)
  ? (Func<bool>)(() => true)
  : (Func<bool>)(() => false),
  (acc, next) => (useAndBetweenItems)
    ? () => acc() && next()
    : () => acc() || next()
);

This code uses the Aggregate method to iterate over the merged list and combine the functions using either AND or OR depending on the value of the useAndBetweenItems variable. The resulting function can then be used to evaluate the entire merged list.