Exemplo n.º 1
0
        public SettingNode(XmlNode settingNode)
            : this()
        {
            if (!char.IsLetter(settingNode.Name[0]) || !char.IsUpper(settingNode.Name[0]))
            {
                throw new Exception("Keys must start with an uppercase letter");
            }

            Key = settingNode.Name;
            foreach (XmlAttribute attr in settingNode.Attributes)
            {
                switch (attr.Name)
                {
                case "value": Value = attr.Value; break;

                case "emptyNods": foreach (var emptyNode in attr.Value.Split(','))
                    {
                        nods.Add(new SettingNode {
                            Key = emptyNode
                        });
                    }
                    break;

                default:
                    if (!char.IsLetter(attr.Name[0]) || !char.IsUpper(attr.Name[0]))
                    {
                        throw new Exception("Non keyword in attribute list must start with an uppercase letter");
                    }
                    nods.Add(new SettingNode {
                        Key = attr.Name, Value = attr.Value
                    });
                    break;
                }
            }

            int nodeCount = nods.Count;

            foreach (XmlNode node in settingNode)
            {
                switch (node.NodeType)
                {
                case XmlNodeType.Element: nods.Add(new SettingNode(node)); break;

                case XmlNodeType.Text:
                    if (Value != null)
                    {
                        throw new Exception("Setting the value twice is not allowed (Node: " + node.Name + ")");
                    }
                    Value = node.Value;
                    break;

                default: break;
                }
            }

            if (nods.Count != nodeCount && Value != null)
            {
                throw new Exception("Mixed Content not allowed (Node: " + Key + ")");
            }
        }
Exemplo n.º 2
0
            public SettingsSection(XmlNode settingsNode)
            {
                foreach (XmlAttribute attr in settingsNode.Attributes)
                {
                    switch (attr.Name)
                    {
                    case "target": Target = attr.Value; break;

                    default: break;
                    }
                }

                SettingNods = new DynReadOnlyCollection <string, SettingNode>(settingNods = new DynCollection <string, SettingNode>(s => s.Key));
                foreach (XmlNode node in settingsNode)
                {
                    settingNods.Add(new SettingNode(node));
                }
            }