Esempio n. 1
0
 /// <summary>
 /// Inserts an item to the list at the specified index.
 /// </summary>
 /// <param name="index">The zero-based index at which item should be inserted.</param>
 /// <param name="item">The object to insert into the list.</param>
 public void Insert(int index, TData item)
 {
     ArgValidator.Create(item, "item").IsNotNull();
     ArgValidator.ParentIsNull(item);
     this.list.Insert(index, item);
     item.Parent = this.parent;
 }
Esempio n. 2
0
 /// <summary>
 /// Adds an item to the list.
 /// </summary>
 /// <param name="item">The object to add to the list.</param>
 public void Add(TData item)
 {
     ArgValidator.Create(item, "item").IsNotNull();
     ArgValidator.ParentIsNull(item);
     this.list.Add(item);
     item.Parent = this.parent;
 }
        /// <summary>
        /// Gets the specified resource from this assembly.
        /// </summary>
        /// <param name="name">The case-sensitive name of the manifest resource being requested</param>
        /// <returns>The resource or null if a resource with the specified name is not present.</returns>
        public static Stream GetResource(string name)
        {
            Assembly assembly;

            ArgValidator.Create(name, "name").IsNotNull();

            assembly = Assembly.GetExecutingAssembly();
            return(assembly.GetManifestResourceStream(name));
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OutputItem"/> class.
        /// </summary>
        /// <param name="itemType">The type of item to output.</param>
        /// <param name="childType">The type of the child to output, if the <paramref name="itemType"/> is Child.</param>
        /// <param name="groupOrdinal">The ordinal value of the grouping of elements that this item should be
        /// serialized with.</param>
        public OutputItem(OutputItemType itemType, Type childType, int groupOrdinal)
        {
            if (itemType == OutputItemType.Child)
            {
                ArgValidator.Create(childType, "childType").IsNotNull();
            }

            this.ItemType     = itemType;
            this.ChildType    = childType;
            this.GroupOrdinal = groupOrdinal;
        }
Esempio n. 5
0
        /// <summary>
        /// Removes the first occurrence of a specific object from the list.
        /// </summary>
        /// <param name="item">The object to remove from the list.</param>
        /// <returns>True if item was successfully removed from the list, otherwise false. This method also
        /// returns false if item is not found in the list.</returns>
        public bool Remove(TData item)
        {
            bool result;

            ArgValidator.Create(item, "item").IsNotNull();

            result = this.list.Remove(item);
            if (result)
            {
                item.Parent = null;
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets or sets the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to get or set.</param>
        /// <returns>The element at the specified index.</returns>
        public TData this[int index]
        {
            get
            {
                return(this.list[index]);
            }

            set
            {
                ArgValidator.Create(value, "value").IsNotNull();
                ArgValidator.ParentIsNull(value);
                this.list[index].Parent = null;
                this.list[index]        = value;
                this.list[index].Parent = this.parent;
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Registers the definition of an attribute so its value can be stored and retrieved.
        /// </summary>
        /// <param name="ns">The Xml namespace the attribute should be serialized in.</param>
        /// <param name="localName">The Xml local name the attribute should be serialized as.</param>
        /// <param name="friendlyName">The name used to reference the attribute in code.</param>
        /// <param name="value">The default value of the attribute.</param>
        protected void RegisterAttribute(string ns, string localName, string friendlyName, object value)
        {
            AttributeData data;

            ArgValidator.Create(localName, "localName").IsNotNullOrWhitespace();
            ArgValidator.Create(friendlyName, "friendlyName").IsNotNullOrWhitespace();

            if (this.attributes.ContainsKey(friendlyName))
            {
                string message;

                message = string.Format(
                    Properties.Resources.XliffElement_AttributeAlreadyRegistered_Format,
                    friendlyName);
                throw new AttributeAlreadyRegisteredException(message);
            }

            data = new AttributeData(this.GetType().Name, new XmlNameInfo(ns, localName), false, value, true);
            this.attributes.Add(friendlyName, data);
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Determines the index of a specific item in the list.
 /// </summary>
 /// <param name="item">The object to locate in the list.</param>
 /// <returns>The index of item if found in the list; otherwise, -1.</returns>
 public int IndexOf(TData item)
 {
     ArgValidator.Create(item, "item").IsNotNull();
     return(this.list.IndexOf(item));
 }