Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParentAttachedList{TData}"/> class.
        /// </summary>
        /// <param name="parent">The object that acts as the parent of all items in the list.</param>
        public ParentAttachedList(XliffElement parent)
        {
            Debug.Assert(parent != null, "Parent should not be null.");

            this.list   = new List <TData>();
            this.parent = parent;
        }
Пример #2
0
 /// <summary>
 /// Sets the parent of an <see cref="XliffElement"/>.
 /// </summary>
 /// <param name="element">The element whose parent to set.</param>
 /// <param name="parent">The parent to set.</param>
 internal static void SetParent(XliffElement element, XliffElement parent)
 {
     if (element != null)
     {
         element.Parent = parent;
     }
 }
Пример #3
0
        /// <summary>
        /// Gets a <see cref="OriginalData"/> from the ancestor that stores the original data for the specified element.
        /// </summary>
        /// <param name="element">The element whose original data host to find.</param>
        /// <returns>The OriginalData that stores the data for the encoded element.</returns>
        internal static OriginalData GetOriginalData(XliffElement element)
        {
            OriginalData result;
            Match        match;

            result = null;

            match = element as Match;
            if (match == null)
            {
                match = element.FindAncestor <Match>();
            }

            if (match != null)
            {
                result = match.OriginalData;
            }
            else
            {
                Unit unit;

                unit = element as Unit;
                if (unit == null)
                {
                    unit = element.FindAncestor <Unit>();
                }

                if (unit != null)
                {
                    result = unit.OriginalData;
                }
            }

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Validates that the <see cref="XliffElement"/> is not already used as a child for another
        /// <see cref="XliffElement"/>. If the element is a child, then an <see cref="ElementReuseException"/>
        /// is thrown.
        /// </summary>
        /// <param name="element">The element to check.</param>
        public static void ParentIsNull(XliffElement element)
        {
            if ((element != null) && (element.Parent != null))
            {
                string message;

                message = string.Format(Properties.Resources.ArgValidator_ElementReused_Format, element.GetType().Name);
                throw new ElementReuseException(message);
            }
        }
        /// <summary>
        /// Creates an instance of this class and populates its members using reflection on the specified
        /// <see cref="XliffElement"/>
        /// </summary>
        /// <param name="element">The element to reflect upon.</param>
        /// <returns>An instance of this class with information about the elements children and attributes.</returns>
        public static IElementInformation Create(XliffElement element)
        {
            ElementInformationFromReflection result;

            result              = new ElementInformationFromReflection();
            result.ChildMap     = Reflector.GetSchemaChildren(element.GetType());
            result.AttributeMap = Reflector.GetSchemaAttributes(element.GetType(), element as IInheritanceInfoProvider, element as IOutputResolver);

            return(result);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AttributeDataProvider"/> class.
        /// </summary>
        /// <param name="host">The element that hosts the attribute.</param>
        /// <param name="property">The name of the property associated with the attribute.</param>
        /// <param name="data">The raw attribute data being referenced by this class.</param>
        internal AttributeDataProvider(XliffElement host, string property, AttributeData data)
            : base(data)
        {
            Debug.Assert(host != null, "Host cannot be null.");
            Debug.Assert(data != null, "Data cannot be null.");
            Debug.Assert(!string.IsNullOrEmpty(property), "Property cannot be null.");

            this.data     = data;
            this.host     = host;
            this.property = property;
        }
Пример #7
0
        /// <summary>
        /// Throws an <see cref="InvalidOperationException"/> exception if the specified value is not null.
        /// </summary>
        /// <param name="host">The element which contains the property to which to assign a new value.</param>
        /// <param name="propertyName">The name of the property trying to be assigned.</param>
        /// <param name="value">The current value of the property.</param>
        internal static void ThrowIfPropertyNotNull(XliffElement host, string propertyName, object value)
        {
            if (value != null)
            {
                string message;

                message = string.Format(
                    Properties.Resources.XliffElement_ChildAlreadyExists_Format,
                    host.GetType().Name,
                    propertyName);
                throw new InvalidOperationException(message);
            }
        }
Пример #8
0
        /// <summary>
        /// Handler called when getting the custom Directionality value from a spanning code element. The value
        /// depends on the hierarchy of the ancestry.
        /// </summary>
        /// <param name="element">The element that the property is for.</param>
        /// <param name="property">The name of the property that is to be returned.</param>
        /// <returns>The custom value.</returns>
        internal static object SpanningCodeInheritanceHandler(XliffElement element, string property)
        {
            object result;

            Debug.Assert(property == "Directionality", "Property name is not supported.");

            result = ContentDirectionality.Auto;
            if ((element is SpanningCode) || (element is SpanningCodeEnd) || (element is SpanningCodeStart))
            {
                XliffElement parent;

                parent = element.Parent;
                while (parent != null)
                {
                    if (parent is SpanningCode)
                    {
                        parent.GetPropertyValue("Directionality", false, out result);
                        break;
                    }
                    else if ((parent is Target) || (parent is Source))
                    {
                        bool isTarget;

                        isTarget = parent is Target;
                        while ((parent != null) && !(parent is Unit))
                        {
                            parent = parent.Parent;
                        }

                        if (parent != null)
                        {
                            if (isTarget)
                            {
                                parent.GetPropertyValue("TargetDirectionality", false, out result);
                            }
                            else
                            {
                                parent.GetPropertyValue("SourceDirectionality", false, out result);
                            }
                        }

                        break;
                    }

                    parent = parent.Parent;
                }
            }

            return(result);
        }