Beispiel #1
0
        /// <summary>
        /// Adds the specified <see cref="XliffElement"/> to this object in the appropriate place depending on
        /// the type and attributes.
        /// </summary>
        /// <param name="name">The name of the child to add.</param>
        /// <param name="child">The <see cref="XliffElement"/> to add.</param>
        void IXliffDataConsumer.AddXliffChild(XmlNameInfo name, IXliffDataConsumer child)
        {
            ArgValidator validator;

            validator = ArgValidator.Create(child, "child").IsNotNull().IsOfType(typeof(XliffElement));

            if (this.registered)
            {
                validator.IsOfType(this.childMap.Keys);
            }

            if (!this.StoreChild(new ElementInfo(name, (XliffElement)child)))
            {
                string message;

                message = string.Format(
                    Properties.Resources.XliffElement_InvalidElement_Format,
                    child.GetType().Name,
                    this.GetType().Name);
                throw new InvalidOperationException(message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Deserializes the attributes at the reader's current position and stores them in the
        /// <paramref name="currentElement"/>.
        /// </summary>
        /// <param name="currentElement">The element associated with the reader's current position.</param>
        private void DeserializeAttributes(IXliffDataConsumer currentElement)
        {
            if (this.reader.MoveToFirstAttribute())
            {
                IExtensible extensible;

                extensible = currentElement as IExtensible;
                do
                {
                    SetAttributeResult setResult;
                    XmlNameInfo        name;

                    name      = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
                    setResult = currentElement.TrySetAttributeValue(name, this.reader.Value);
                    if ((setResult == SetAttributeResult.InvalidAttribute) ||
                        ((setResult == SetAttributeResult.PossibleExtension) &&
                         (this.StoreAttributeExtension(extensible) == SetAttributeResult.InvalidAttribute)))
                    {
                        string message;

                        if (string.IsNullOrEmpty(name.Prefix))
                        {
                            message = name.LocalName;
                        }
                        else
                        {
                            message = string.Join(":", name.Prefix, name.LocalName);
                        }

                        message = string.Format(
                            Properties.Resources.XliffReader_InvalidAttributeName_Format,
                            message,
                            currentElement.GetType().Name);
                        throw new NotSupportedException(message);
                    }
                }while (this.reader.MoveToNextAttribute());
            }
        }
Beispiel #3
0
        /// <summary>
        /// Deserializes the attributes at the reader's current position and stores them in the
        /// <paramref name="currentElement"/>.
        /// </summary>
        /// <param name="currentElement">The element associated with the reader's current position.</param>
        private void DeserializeAttributes(IXliffDataConsumer currentElement)
        {
            if (this.reader.MoveToFirstAttribute())
            {
                IExtensible extensible;

                extensible = currentElement as IExtensible;
                do
                {
                    SetAttributeResult setResult;
                    XmlNameInfo name;

                    name = new XmlNameInfo(this.reader.Prefix, this.reader.NamespaceURI, this.reader.LocalName);
                    setResult = currentElement.TrySetAttributeValue(name, this.reader.Value);
                    if ((setResult == SetAttributeResult.InvalidAttribute) ||
                        ((setResult == SetAttributeResult.PossibleExtension) &&
                            (this.StoreAttributeExtension(extensible) == SetAttributeResult.InvalidAttribute)))
                    {
                        string message;

                        if (string.IsNullOrEmpty(name.Prefix))
                        {
                            message = name.LocalName;
                        }
                        else
                        {
                            message = string.Join(":", name.Prefix, name.LocalName);
                        }

                        message = string.Format(
                                                Properties.Resources.XliffReader_InvalidAttributeName_Format,
                                                message,
                                                currentElement.GetType().Name);
                        throw new NotSupportedException(message);
                    }
                }
                while (this.reader.MoveToNextAttribute());
            }
        }