Пример #1
0
        /// <summary>
        /// Generates a <see cref="AttributeDefinitionBoolean"/> object from its XML representation.
        /// </summary>
        /// <param name="reader">
        /// an instance of <see cref="XmlReader"/>
        /// </param>
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);

            while (reader.Read())
            {
                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "ALTERNATIVE-ID")
                {
                    var alternativeId = new AlternativeId(this);
                    alternativeId.ReadXml(reader);
                }

                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "DATATYPE-DEFINITION-BOOLEAN-REF")
                {
                    var reference = reader.ReadElementContentAsString();

                    var datatypeDefinition = (DatatypeDefinitionBoolean)this.SpecType.ReqIFContent.DataTypes.SingleOrDefault(x => x.Identifier == reference);
                    this.Type = datatypeDefinition;
                }

                // read the default value if any
                if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "ATTRIBUTE-VALUE-BOOLEAN")
                {
                    this.DefaultValue = new AttributeValueBoolean(this);
                    using (var valuesubtree = reader.ReadSubtree())
                    {
                        valuesubtree.MoveToContent();
                        this.DefaultValue.ReadXml(valuesubtree);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Sets the <see cref="DatatypeDefinitionBoolean"/>
        /// </summary>
        /// <param name="datatypeDefinition">
        /// The instance of <see cref="DatatypeDefinitionBoolean"/> that is to be set.
        /// </param>
        protected override void SetDatatypeDefinition(DatatypeDefinition datatypeDefinition)
        {
            if (datatypeDefinition.GetType() != typeof(DatatypeDefinitionBoolean))
            {
                throw new ArgumentException("datatypeDefinition must of type DatatypeDefinitionBoolean");
            }

            this.Type = (DatatypeDefinitionBoolean)datatypeDefinition;
        }
        /// <summary>
        /// Asynchronously generates a <see cref="AttributeDefinitionBoolean"/> object from its XML representation.
        /// </summary>
        /// <param name="reader">
        /// an instance of <see cref="XmlReader"/>
        /// </param>
        /// <param name="token">
        /// A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        internal override async Task ReadXmlAsync(XmlReader reader, CancellationToken token)
        {
            base.ReadXml(reader);

            while (await reader.ReadAsync())
            {
                if (token.IsCancellationRequested)
                {
                    token.ThrowIfCancellationRequested();
                }

                if (await reader.MoveToContentAsync() == XmlNodeType.Element)
                {
                    switch (reader.LocalName)
                    {
                    case "ALTERNATIVE-ID":
                        var alternativeId = new AlternativeId(this);
                        alternativeId.ReadXml(reader);
                        break;

                    case "DATATYPE-DEFINITION-BOOLEAN-REF":
                        var reference = await reader.ReadElementContentAsStringAsync();

                        var datatypeDefinition = (DatatypeDefinitionBoolean)this.SpecType.ReqIFContent.DataTypes.SingleOrDefault(x => x.Identifier == reference);
                        this.Type = datatypeDefinition;

                        if (datatypeDefinition == null)
                        {
                            this.logger.LogTrace("The DatatypeDefinitionBoolean:{reference} could not be found and has been set to null on AttributeDefinitionBoolean:{Identifier}", reference, Identifier);
                        }

                        break;

                    case "ATTRIBUTE-VALUE-BOOLEAN":
                        this.DefaultValue = new AttributeValueBoolean(this, this.loggerFactory);
                        using (var valueSubtree = reader.ReadSubtree())
                        {
                            await valueSubtree.MoveToContentAsync();

                            await this.DefaultValue.ReadXmlAsync(valueSubtree, token);
                        }
                        break;
                    }
                }
            }
        }