您可以这样做:
List<string> errors = new List<string>();
Func<Dictionary<string, object>, bool>[] eval =
{
e => { bool ret = e != null; if (!ret) errors.Add("Null"); return ret; },
然而,一个更优雅的解决方案是
List<string> errors = new List<string>();
Func<bool, string, List<string>, bool> EvaluateWithError = (test, message, collection) =>
{
if (!test) collection.Add(message); return test;
};
Func<Dictionary<string, object>, bool>[] eval =
{
e => EvaluateWithError(e != null, "Null", errors),