Beispiel #1
0
        /// <summary>
        /// Processes/interprets an XML attribute. If an attribute isn't known to the class (<see cref="GetKnownAttributes"/>)
        /// it's name and value are stored in the <see cref="OtherAttributes"/> dictionary. There's usually no need to override
        /// this method, unless a child class needs to process the "unknown" attributes differently or has special requirements
        /// when handling the attribute element itself.
        /// </summary>
        /// <param name="attribute">XML Attribute.</param>
        public virtual void SetAttribute(Dictionary <string, Action <string, XAttribute> > knownAttributes, XAttribute attribute)
        {
            if (attribute == null)
            {
                throw new ArgumentNullException(nameof(attribute));
            }

            Action <string, XAttribute> setter;

            if (knownAttributes != null && knownAttributes.TryGetValue(attribute.Name.LocalName, out setter) && setter != null)
            {
                setter(attribute.Value, attribute);
                return;
            }

            if (otherAttributes == null)
            {
                otherAttributes = new Dictionary <string, string> (StringComparer.Ordinal);
            }

            if (otherAttributes.ContainsKey(attribute.Name.LocalName))
            {
                Logger.Warning($"Attribute '{attribute.Name.LocalName}' redefined for element {attribute.Parent.Name} at {DocumentPath}[{attribute.GetLineInfo ()}]");
            }

            otherAttributes [attribute.Name.LocalName] = attribute.Value;
        }