Exemple #1
0
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");
            Collapse          = TryParseBool(definition, "Collapse");
            Seperator         = definition.Attribute("Seperator")?.Value;
            if (Seperator == null)
            {
                Seperator = ",";
            }

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            var currentGroup = "Items";

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes" || xel.Name == "AdditionalDefs")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }

            var addEls = definition.Element("AdditionalDefs");

            if (addEls != null)
            {
                foreach (var addEl in addEls.Elements())
                {
                    var addDef = LoadDefinition(addEl);
                    AdditionalDefs.Add(addDef);
                }
            }
        }
Exemple #2
0
        public override void Parse(XElement definition)
        {
            ChildrenAreUnique = TryParseBool(definition, "ChildrenAreUnique");
            Collapse          = TryParseBool(definition, "Collapse");
            Seperator         = definition.Attribute("Seperator")?.Value;
            if (Seperator == null)
            {
                Seperator = ",";
            }

            MinCount = TryParseInt(definition, "MinCount", 0);
            MaxCount = TryParseInt(definition, "MaxCount", int.MaxValue);

            DefKey = definition.Attribute("DefKey")?.Value?.ToString();
            var keyString = definition.Attribute("Keys")?.Value?.ToString();

            if (!string.IsNullOrWhiteSpace(keyString))
            {
                if (!keyString.Contains('('))
                {
                    DefKeys.AddRange(keyString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), "Type")));
                }
                else
                {
                    var categories = keyString.Split(new char[] { ')' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var categoryString in categories)
                    {
                        var split    = categoryString.Split('(');
                        var category = split[0].Trim();
                        if (category.StartsWith(","))
                        {
                            category = category.Substring(1);
                        }
                        DefKeys.AddRange(split[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(e => new Tuple <string, string>(e.Trim(), category)));
                    }
                }
            }

            var currentGroup = "Items";

            var childDefs = definition.Nodes();

            foreach (var childDef in childDefs)
            {
                if (childDef is XComment)
                {
                    currentGroup = (childDef as XComment).Value;
                }
                else if (childDef is XElement)
                {
                    var xel = childDef as XElement;
                    if (xel.Name == "Attributes" || xel.Name == "AdditionalDefs")
                    {
                        continue;
                    }

                    var cdef = new CollectionChildDefinition();
                    cdef.Parse(xel);

                    ChildDefinitions.Add(cdef);
                    Keys.Add(new Tuple <CollectionChildDefinition, string>(cdef, currentGroup));
                }
            }

            if (ChildDefinitions.Count == 0 && DefKey == null && DefKeys.Count == 0)
            {
                throw new Exception("No child definitions in collection '" + Name + "'!");
            }

            var addEls = definition.Element("AdditionalDefs");

            if (addEls != null)
            {
                foreach (var addEl in addEls.Elements())
                {
                    var addDef = LoadDefinition(addEl);
                    AdditionalDefs.Add(addDef);
                }
            }
        }