这可能非常简单,但我对Lambda的这种说法很新。
I have a function that uses a Lambda function to recurse. The main function receives a bool telling it to include certain information or not within the lambda.
该职能旨在向XML书写一个习俗类别——我认为,该守则只是自我解释。
此时,如果说的话,我就用简单的方式来解决这一问题,但我感到很奇怪的是,谁知道更好的方式?
private XElement ErrorListToXml(ErrorList el, bool outputTagsOnly)
{
// Need to declare in advance to call within the lambda.
Func<ErrorType, XElement> recursiveGenerator = null;
if (outputTagsOnly)
recursiveGenerator = error => new XElement
(error.Name,
error.ChildErrors.Select(recursiveGenerator));
else
recursiveGenerator = error => new XElement
(error.Name,
new XAttribute("Ignore", error.Filter),
error.ChildErrors.Select(recursiveGenerator));
var element = new XElement
("ErrorList",
ChildErrors.Select(recursiveGenerator));
Console.WriteLine(element);
return element;
}