/// <summary> /// Tries to set the value of an attribute. /// </summary> /// <param name="name">The XLIFF Name of the attribute.</param> /// <param name="value">The value to set.</param> /// <returns>A <see cref="SetAttributeResult"/> that indicates whether the attribute was set.</returns> SetAttributeResult IXliffDataConsumer.TrySetAttributeValue(XmlNameInfo name, string value) { SetAttributeResult result; result = SetAttributeResult.Success; if (name.LocalName == NamespacePrefixes.XmlNamespace) { // xmlns shouldn't be stored at all. result = SetAttributeResult.ReservedName; } else if (this.TrySetPropertyValue(name, value)) { // Property saved. result = SetAttributeResult.Success; } else if ((name.Prefix == NamespacePrefixes.Xml) || Utilities.IsModuleNamespace(name.Namespace)) { // xml:xx is not an extension. // Known modules cannot be stored as extensions. result = SetAttributeResult.InvalidAttribute; } else { // abc:xx might be an extension. result = SetAttributeResult.PossibleExtension; } return(result); }
/// <summary> /// Creates a new <see cref="XliffElement"/> depending on the XLIFF element Name. /// </summary> /// <param name="name">The XLIFF element Name.</param> /// <returns>An instance of a class associated with the specified XLIFF Name.</returns> public virtual XliffElement CreateElement(XmlNameInfo name) { Type elementType; XliffElement result; elementType = null; foreach (Type type in this.childMap.Keys) { XmlNameInfo info; // If namespace isn't supplied then the information isn't available to compare so assume // they match. This happens if decoding Xml fragments without the full document. info = this.childMap[type]; if ((name.LocalName == info.LocalName) && ((name.Namespace == null) || (name.Namespace == info.Namespace))) { elementType = type; break; } } result = null; if (elementType != null) { // Cannot call Activator.CreateInstance because the .ctor may not be public. // Cannot call GetConstructor() directly because it doesn't exist in PCL. result = (XliffElement)Reflector.InvokeDefaultConstructor(elementType); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="AttributeData"/> class. /// </summary> /// <param name="hostTypeName">The type name of the host that contains the attribute.</param> /// <param name="name">The name of the XLIFF attribute.</param> /// <param name="isOptional">Indicates whether the attribute is optional in the XLIFF document.</param> /// <param name="value">The default value of the attribute.</param> /// <param name="hasValue">A value indicating whether the attribute has a value.</param> public AttributeData(string hostTypeName, XmlNameInfo name, bool isOptional, object value, bool hasValue) : base(name) { this.ExplicitOutputDependencies = new Dictionary <string, AttributeData>(); this.InheritanceList = new List <InheritanceInfo>(); this.IsOptional = isOptional; this.IsSupported = true; this.Value = value; // This must go last because Value sets it. this.HasValue = hasValue; this.defaultValue = value; this.hasDefaultValue = true; this.hostTypeName = hostTypeName; }
/// <summary> /// Initializes a new instance of the <see cref="AttributeData"/> class. /// </summary> /// <param name="hostTypeName">The type name of the host that contains the attribute.</param> /// <param name="name">The name of the XLIFF attribute.</param> /// <param name="isOptional">Indicates whether the attribute is optional in the XLIFF document.</param> /// <param name="value">The default value of the attribute.</param> /// <param name="hasValue">A value indicating whether the attribute has a value.</param> public AttributeData(string hostTypeName, XmlNameInfo name, bool isOptional, object value, bool hasValue) : base(name) { this.ExplicitOutputDependencies = new Dictionary<string, AttributeData>(); this.InheritanceList = new List<InheritanceInfo>(); this.IsOptional = isOptional; this.IsSupported = true; this.Value = value; // This must go last because Value sets it. this.HasValue = hasValue; this.defaultValue = value; this.hasDefaultValue = true; this.hostTypeName = hostTypeName; }
/// <summary> /// Creates an <see cref="XliffElement"/> that corresponds to the given Xml namespace and name. /// </summary> /// <param name="name">The Xml namespace and name that represents the element to create.</param> /// <returns>The corresponding <see cref="XliffElement"/> or null if one wasn't found.</returns> public XliffElement CreateElement(XmlNameInfo name) { Dictionary <string, Type> typeMap; XliffElement result; Type elementType; string key; typeMap = this.GetAllXliffElementTypes(); key = ReflectorCache.MakeAllXliffElementTypesKey(name); if (typeMap.TryGetValue(key, out elementType)) { result = (XliffElement)Reflector.InvokeDefaultConstructor(elementType); } else { result = null; } return(result); }
/// <summary> /// Tries to set the value of an attribute. /// </summary> /// <param name="name">The XLIFF Name of the attribute.</param> /// <param name="value">The value to set.</param> /// <returns>This method always returns true.</returns> protected virtual bool TrySetPropertyValue(XmlNameInfo name, string value) { bool result; result = false; foreach (AttributeData attribute in this.attributes.Values) { if (attribute.IsSupported && (name.Prefix == attribute.Prefix) && (name.LocalName == attribute.LocalName) && (attribute.IgnoreNamespace || (name.Namespace == attribute.Namespace))) { attribute.SetValue(value); result = true; break; } } return(result); }
/// <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); } }
/// <summary> /// Creates a new <see cref="XliffElement"/> depending on the XLIFF element Name. /// </summary> /// <param name="name">The XLIFF element Name.</param> /// <returns>An instance of a class associated with the specified XLIFF Name.</returns> IXliffDataConsumer IXliffDataConsumer.CreateXliffElement(XmlNameInfo name) { return(this.CreateElement(name)); }
/// <summary> /// Initializes a new instance of the <see cref="AttributeData"/> class without a default value. /// </summary> /// <param name="hostTypeName">The type name of the host that contains the attribute.</param> /// <param name="name">The name of the XLIFF attribute.</param> /// <param name="isOptional">Indicates whether the attribute is optional in the XLIFF document.</param> public AttributeData(string hostTypeName, XmlNameInfo name, bool isOptional) : this(hostTypeName, name, isOptional, null, false) { this.hasDefaultValue = false; }
/// <summary> /// Creates an <see cref="XliffElement"/> that corresponds to the given Xml namespace and name. /// </summary> /// <param name="name">The Xml namespace and name that represents the element to create.</param> /// <returns>The corresponding <see cref="XliffElement"/> or null if one wasn't found.</returns> public XliffElement CreateElement(XmlNameInfo name) { Dictionary<string, Type> typeMap; XliffElement result; Type elementType; string key; typeMap = this.GetAllXliffElementTypes(); key = ReflectorCache.MakeAllXliffElementTypesKey(name); if (typeMap.TryGetValue(key, out elementType)) { result = (XliffElement)Reflector.InvokeDefaultConstructor(elementType); } else { result = null; } return result; }
/// <summary> /// Computes a key to use for the allXliffElementTypes dictionary. /// </summary> /// <param name="name">The Xml name information about the item whose key to compute.</param> /// <returns>A key that can be used to reference an element in this.allXliffElementTypes.</returns> private static string MakeAllXliffElementTypesKey(XmlNameInfo name) { return string.Join("<", name.Namespace, name.LocalName); }
/// <summary> /// Initializes a new instance of the <see cref="XmlNameInfo"/> class by cloning another <see cref="XmlNameInfo"/>. /// </summary> /// <param name="info">The instance to clone.</param> public XmlNameInfo(XmlNameInfo info) : this(info.Prefix, info.Namespace, info.LocalName) { }
/// <summary> /// Creates a new <see cref="XliffElement"/> depending on the XLIFF element Name. /// </summary> /// <param name="name">The XLIFF element Name.</param> /// <returns>An instance of a class associated with the specified XLIFF Name.</returns> public override XliffElement CreateElement(XmlNameInfo name) { return Reflector.CreateElement(name) ?? new GenericElement(); }
/// <summary> /// Tries to set the value of an attribute. /// </summary> /// <param name="name">The XLIFF Name of the attribute.</param> /// <param name="value">The value to set.</param> /// <returns>This method always returns true.</returns> protected override bool TrySetPropertyValue(XmlNameInfo name, string value) { XmlNameInfo nameWithoutPrefix; string key; key = string.Join("@@", name.Namespace, name.LocalName); this.RegisterAttribute(name.Namespace, name.LocalName, key, value); nameWithoutPrefix = new XmlNameInfo(name.Namespace, name.LocalName); this.SetPropertyValue(value, key); return true; }
/// <summary> /// Stores the <see cref="XliffElement"/> as a child of this <see cref="XliffElement"/>. /// </summary> /// <param name="info">The object to add.</param> /// <returns>True if the child was stored, otherwise false.</returns> protected override bool StoreChild(ElementInfo info) { ArgValidator.ParentIsNull(info.Element); Utilities.SetParent(info.Element, this); if (info.Namespace == null) { XmlNameInfo name; name = new XmlNameInfo(info.Prefix, NamespaceValues.Core, info.LocalName); info = new ElementInfo(name, info.Element); } this.children.Value.Add(info); return true; }
/// <summary> /// Creates an <see cref="XliffElement"/> that corresponds to the given Xml namespace and name. /// </summary> /// <param name="name">The Xml namespace and name that represents the element to create.</param> /// <returns>The corresponding <see cref="XliffElement"/> or null if one wasn't found.</returns> public static XliffElement CreateElement(XmlNameInfo name) { return ReflectorCache.Instance.CreateElement(name); }
/// <summary> /// Creates an <see cref="XliffElement"/> that corresponds to the given Xml namespace and name. /// </summary> /// <param name="name">The Xml namespace and name that represents the element to create.</param> /// <returns>The corresponding <see cref="XliffElement"/> or null if one wasn't found.</returns> public static XliffElement CreateElement(XmlNameInfo name) { return(ReflectorCache.Instance.CreateElement(name)); }
/// <summary> /// Initializes a new instance of the <see cref="AttributeData"/> class. /// </summary> /// <param name="hostTypeName">The type name of the host that contains the attribute.</param> /// <param name="name">The name of the XLIFF attribute.</param> /// <param name="isOptional">Indicates whether the attribute is optional in the XLIFF document.</param> /// <param name="value">The default value of the attribute.</param> public AttributeData(string hostTypeName, XmlNameInfo name, bool isOptional, object value) : this(hostTypeName, name, isOptional, value, !isOptional) { }
/// <summary> /// Computes a key to use for the allXliffElementTypes dictionary. /// </summary> /// <param name="name">The Xml name information about the item whose key to compute.</param> /// <returns>A key that can be used to reference an element in this.allXliffElementTypes.</returns> private static string MakeAllXliffElementTypesKey(XmlNameInfo name) { return(string.Join("<", name.Namespace, name.LocalName)); }