public IStatValueParser CreateParser(StatField field, StatDefinitionRepository definitions)
        {
            switch (field.Type)
            {
            case "Requirements":
                return(new ExpressionParser("Requirements", definitions, this));

            case "Properties":
                return(new ExpressionParser("Properties", definitions, this));

            case "Conditions":
                return(new ConditionsParser(definitions, this));

            case "Enumeration":
                return(new EnumParser(field.EnumType));

            case "EnumerationList":
                return(new MultiValueEnumParser(field.EnumType));

            case "Boolean":
                return(new BooleanParser());

            case "Integer":
                return(new Int32Parser());

            case "Float":
                return(new FloatParser());

            case "UUID":
            case "RootTemplate":
                return(new UUIDParser());

            case "StatReference":
                return(new StatReferenceParser(ReferenceValidator, field.ReferenceTypes));

            case "StatReferences":
                return(new MultiValueStatReferenceParser(ReferenceValidator, field.ReferenceTypes));

            case "BaseClass":
            case "Name":
            case "String":
            case "TranslatedString":
            case "Comment":
            case "Color":
                return(new StringParser());

            default:
                throw new ArgumentException($"Could not create parser for type '{field.Type}'");
            }
        }
        private void AddField(StatTypeDefinition definition, StatSubtypeDefinition subtype, XElement field)
        {
            if (field.Attribute("export_name").Value == "")
            {
                return;
            }

            var             fieldName   = field.Attribute("export_name").Value;
            var             typeName    = field.Attribute("type").Value;
            StatEnumeration enumeration = null;
            List <StatReferenceConstraint> referenceConstraints = null;

            switch (typeName)
            {
            case "Enumeration":
            case "EnumerationList":
                var enumName = field.Attribute("enumeration_type_name").Value;
                enumeration = Enumerations[enumName];
                break;

            case "Name":
                if (definition.NameProperty == null)
                {
                    definition.NameProperty = fieldName;
                }
                else if (definition.NameProperty != fieldName)
                {
                    throw new Exception($"Conflicting Name property for type '{definition.Name}': First seen using '{definition.NameProperty}', now seen using '{fieldName}'.");
                }
                break;

            case "BaseClass":
                if (definition.BaseClassProperty == null)
                {
                    definition.BaseClassProperty = fieldName;
                }
                else if (definition.BaseClassProperty != fieldName)
                {
                    throw new Exception($"Conflicting BaseClass for type '{definition.Name}': First seen using '{definition.BaseClassProperty}', now seen using '{fieldName}'.");
                }
                break;

            case "StatReference":
            case "StatReferences":
                referenceConstraints = new List <StatReferenceConstraint>();
                var descriptions = field.Element("stat_descriptions");
                if (descriptions == null)
                {
                    throw new Exception("Field of type 'StatReference' must have a list of stat types in the <stat_descriptions> node");
                }

                var descs = descriptions.Elements("description");
                foreach (var desc in descs)
                {
                    var constraint = new StatReferenceConstraint
                    {
                        StatType    = desc.Attribute("stat_type").Value,
                        StatSubtype = desc.Attribute("stat_subtype")?.Value ?? null
                    };
                    referenceConstraints.Add(constraint);
                }

                break;

            case "Boolean":
            case "Integer":
            case "Float":
            case "String":
            case "TranslatedString":
            case "RootTemplate":
            case "Comment":
            case "Color":
            case "Requirements":
            case "Properties":
            case "Conditions":
            case "Passthrough":
            case "UUID":
                break;

            default:
                throw new Exception($"Unsupported stat field type: '{typeName}'");
            }

            var statField = new StatField
            {
                Name           = fieldName,
                Type           = typeName,
                EnumType       = enumeration,
                ReferenceTypes = referenceConstraints
            };

            subtype.Fields.Add(fieldName, statField);

            if (typeName == "TranslatedString")
            {
                var translatedKeyRefField = new StatField
                {
                    Name     = fieldName + "Ref",
                    Type     = typeName,
                    EnumType = enumeration
                };
                subtype.Fields.Add(fieldName + "Ref", translatedKeyRefField);
            }
        }