Skip to content

Instantly share code, notes, and snippets.

@U007D
Created March 28, 2017 01:38
Show Gist options
  • Save U007D/7f8b9372b2522f568f68e7c37ad3c9f1 to your computer and use it in GitHub Desktop.
Save U007D/7f8b9372b2522f568f68e7c37ad3c9f1 to your computer and use it in GitHub Desktop.
Imperative vs. Declarative Excerpts
return parser.ServiceNode.Nodes.OfType<TreeNode>()
.SelectMany(n => n.Nodes.OfType<TreeNode>())
.Single(n => n.Text == Protocol.Values[(int)protocol])
.Nodes.OfType<TreeNode>();
var endpoints = new List<TreeNode>();
foreach (var service in parser.ServiceNode.Nodes.OfType<TreeNode>())
{
foreach (var acceptedProtocol in service.Nodes.OfType<TreeNode>())
{
if (acceptedProtocol.Text == Protocol.Values[(int)protocol])
{
if (foundProtocol)
{
throw new DuplicateProtocolException(String.Format("Protocol {0} found more than once.", acceptedProtocol.Text)); //==Linq's .Single()
}
foundProtocol = true;
endpoints.AddRange(acceptedProtocol.Nodes.OfType<TreeNode>());
}
}
}
return endpoints;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment