Created
March 28, 2017 01:38
-
-
Save U007D/7f8b9372b2522f568f68e7c37ad3c9f1 to your computer and use it in GitHub Desktop.
Imperative vs. Declarative Excerpts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return parser.ServiceNode.Nodes.OfType<TreeNode>() | |
.SelectMany(n => n.Nodes.OfType<TreeNode>()) | |
.Single(n => n.Text == Protocol.Values[(int)protocol]) | |
.Nodes.OfType<TreeNode>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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