コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Unit"/> class.
        /// </summary>
        /// <param name="id">The Id of the unit.</param>
        /// <param name="internalCtor">True if this internal constructor was called that is used for deserialization,
        /// false if the public one was called.
        /// </param>
        private Unit(string id, bool internalCtor)
            : base(id, internalCtor)
        {
            this.RegisterElementInformation(ElementInformationFromReflection.Create(this));

            this.translationCandidates = new TranslationMatches();
            Utilities.SetParent(this.translationCandidates, this);

            // DEV NOTE: Order of segments must be maintained during serialization and deserialization so make sure
            // the order can be preserved. Using a type of list maintains order, but if you change this.Resources
            // to another type (like dictionary), make sure you have a way to maintain order.
            this.Resources = new ParentAttachedList <ContainerResource>(this);

            // The default .ctor is called during deserialization and that is the only case where matches can be overridden.
            this.storedMatches = !internalCtor;
        }
コード例 #2
0
        /// <summary>
        /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>.
        /// </summary>
        /// <param name="child">The child to add.</param>
        /// <returns>True if the child was stored, otherwise false.</returns>
        protected override bool StoreChild(ElementInfo child)
        {
            bool result;

            result = true;
            if (child.Element is ContainerResource)
            {
                // DEV NOTE: Order of segments must be maintained during serialization and deserialization so make sure
                // the order can be preserved. Using a type of list maintains order, but if you change this.Resources
                // to another type (like dictionary), make sure you have a way to maintain order.
                this.Resources.Add((ContainerResource)child.Element);
            }
            else if (child.Element is Glossary)
            {
                Utilities.ThrowIfPropertyNotNull(this, PropertyNames.Glossary, this.Glossary);
                this.Glossary = (Glossary)child.Element;
            }
            else if (child.Element is OriginalData)
            {
                Utilities.ThrowIfPropertyNotNull(this, PropertyNames.OriginalData, this.OriginalData);
                this.OriginalData = (OriginalData)child.Element;
            }
            else if (child.Element is TranslationMatches)
            {
                if (this.storedMatches)
                {
                    Utilities.ThrowIfPropertyNotNull(this, "Matches", this.translationCandidates);
                }

                this.translationCandidates = (TranslationMatches)child.Element;
                Utilities.SetParent(this.translationCandidates, this);
                this.storedMatches = true;
            }
            else if (child.Element is ResourceData)
            {
                Utilities.ThrowIfPropertyNotNull(this, PropertyNames.ResourceData, this.ResourceData);
                this.ResourceData = (ResourceData)child.Element;
            }
            else
            {
                result = base.StoreChild(child);
            }

            return(result);
        }