public void LoadConfiguration(OptionConfiguration configuration) { if (configuration == null) { return; } foreach (var section in configuration.Sections) { //必须先确保选项节对应的空节点被添加 var sectionNode = _root.FindNode(section.Path, token => { if (token.Current == null) { var parent = token.Parent as OptionNode; if (parent != null) { return(parent.Children.Add(token.Name)); } } return(token.Current); }); //在添加了选项上级空节点添加完成之后再添加选项元素的节点 foreach (var elementName in section.Children.Keys) { var node = (OptionNode)_root.FindNode(new string[] { section.Path, elementName }, token => { if (token.Current == null) { var parent = token.Parent as OptionNode; if (parent != null) { return(parent.Children.Add(token.Name, configuration)); } } return(token.Current); }); } } }
public void LoadConfiguration(OptionConfiguration configuration) { if (configuration == null) { return; } foreach (var section in configuration.Sections) { //必须先确保选项节对应的空节点被添加 var sectionNode = (OptionNode)_root.FindNode(section.Path, token => { if (token.Current == null) { var parent = token.Parent as OptionNode; if (parent != null) { return(parent.Children.Add(token.Name)); } } return(token.Current); }); //在添加了选项上级空节点添加完成之后再添加选项元素的节点 foreach (var elementName in section.Children.Keys) { if (sectionNode.Children.TryGet(elementName, out var elementNode)) { if (elementNode.Option == null) { elementNode.Option = new Option(elementNode, configuration); } else { elementNode.Option.Providers.Add(configuration); } } else { sectionNode.Children.Add(elementName, configuration); } } } }