Esempio n. 1
0
        /// <summary>
        /// Returns a copy of the <see cref="AbideTagField"/> object.
        /// </summary>
        /// <returns>A copy of the current <see cref="AbideTagField"/> object.</returns>
        public object Clone()
        {
            //Create field
            AbideTagField field = new AbideTagField()
            {
                fieldType       = fieldType,
                fieldName       = new ObjectName(fieldName.ToString()),
                blockName       = blockName,
                structName      = structName,
                alignment       = alignment,
                maximumSize     = maximumSize,
                elementSize     = elementSize,
                length          = length,
                referencedBlock = (AbideTagBlock)referencedBlock?.Clone() ?? null,
                explanation     = explanation,
                groupTag        = groupTag,
            };

            //Add children
            field.fields.AddRange(fields.Select(f => (AbideTagField)f.Clone()));
            field.options.AddRange(options.Select(o => new ObjectName(o.ToString())));

            //Return
            return(field);
        }
Esempio n. 2
0
        /// <summary>
        /// Loads the Abide tag block document document from the specified <see cref="XmlDocument"/>.
        /// </summary>
        /// <param name="doc">The <see cref="XmlDocument"/> to load the <see cref="AbideTagBlock"/> from.</param>
        private void LoadFromXmlDocument(XmlDocument doc)
        {
            try
            {
                //Get tag block
                XmlNode tagBlock = doc["AbideTagBlock"] ?? throw new TagException("Document doesn't contain a tag block node.");

                //Setup
                name        = tagBlock.Attributes["Name"]?.Value ?? throw new TagException("Tag block node doesn't specify a name.");
                displayName = tagBlock.Attributes["DisplayName"]?.Value ?? throw new TagException("Tag block node doesn't specify a display name.");
                if (!int.TryParse(tagBlock.Attributes["MaximumElementCount"]?.Value, out maximumElementCount))
                {
                    throw new TagException("Tag block node doesn't specify a maximum element count.");
                }

                //Get field set
                XmlNode fieldSetNode = tagBlock["FieldSet"] ?? throw new TagException("Tag block node doesn't contain a field set node.");

                //Setup
                if (!int.TryParse(fieldSetNode.Attributes["Alignment"]?.Value, out int alignment))
                {
                    throw new TagException("Field set node doesn't specify an alignment.");
                }
                fieldSet.Alignment = alignment;

                //Loop
                foreach (XmlNode field in fieldSetNode)
                {
                    fieldSet.Add(AbideTagField.FromXmlNode(field));
                }
            }
            catch (Exception ex) { throw new TagException("An error occured while loading the tag group document.", ex); }
        }
Esempio n. 3
0
        /// <summary>
        /// Returns an <see cref="AbideTagField"/> instance from a supplied <see cref="XmlNode"/>.
        /// </summary>
        /// <param name="xmlNode">The base XML node.</param>
        /// <returns>A <see cref="AbideTagField"/> instance.</returns>
        internal static AbideTagField FromXmlNode(XmlNode xmlNode)
        {
            //Prepare
            AbideTagField field = new AbideTagField();

            //Get Attributes
            field.fieldName   = new ObjectName(xmlNode.Attributes["Name"]?.Value ?? string.Empty);
            field.explanation = xmlNode.Attributes["Explanation"]?.Value?.Replace("|n", "\n") ?? string.Empty;
            field.blockName   = xmlNode.Attributes["BlockName"]?.Value ?? string.Empty;
            field.structName  = xmlNode.Attributes["StructName"]?.Value ?? string.Empty;
            int.TryParse(xmlNode.Attributes["GroupTag"]?.Value, out field.groupTag);
            int.TryParse(xmlNode.Attributes["Alignment"]?.Value, out field.alignment);
            int.TryParse(xmlNode.Attributes["MaximumSize"]?.Value, out field.maximumSize);
            int.TryParse(xmlNode.Attributes["ElementSize"]?.Value, out field.elementSize);
            int.TryParse(xmlNode.Attributes["Length"]?.Value, out field.length);

            //Get Type
            if (!Enum.TryParse(xmlNode.Name, out field.fieldType))
            {
                throw new TagException($"Unable to parse field node's type. ({xmlNode.Name})");
            }

            //Check
            switch (field.fieldType)
            {
            case FieldType.FieldArrayStart:
                foreach (XmlNode fieldNode in xmlNode)
                {
                    field.fields.Add(FromXmlNode(fieldNode));
                }
                break;

            case FieldType.FieldCharEnum:
            case FieldType.FieldEnum:
            case FieldType.FieldLongEnum:
            case FieldType.FieldLongFlags:
            case FieldType.FieldWordFlags:
            case FieldType.FieldByteFlags:
            case FieldType.FieldLongBlockFlags:
            case FieldType.FieldWordBlockFlags:
            case FieldType.FieldByteBlockFlags:
                foreach (XmlNode optionNode in xmlNode)
                {
                    field.options.Add(new ObjectName(optionNode.Attributes["Name"]?.Value ?? string.Empty));
                }
                break;
            }

            //Return
            return(field);
        }