/// <summary> /// Convert custom attributes (that aren't found via reflection, e.g. width/height) into useable values /// </summary> /// <param name="attributes"></param> /// <returns></returns> protected AttributeDictionary HandleCustomAttributes(AttributeDictionary attributes) { var elementName = this.GetType().Name.Replace("TagHandler", ""); var customAttributes = attributes.Where(k => XmlLayoutUtilities.IsCustomAttribute(k.Key)) .ToList(); foreach (var attribute in customAttributes) { var customAttribute = XmlLayoutUtilities.GetCustomAttribute(attribute.Key); if (customAttribute.RestrictToPermittedElementsOnly) { if (!customAttribute.PermittedElements.Contains(elementName, StringComparer.OrdinalIgnoreCase)) { continue; } } attributes = XmlLayoutUtilities.MergeAttributes( attributes, customAttribute.Convert(attribute.Value, attributes.Clone(), this.currentXmlElement)); customAttribute.Apply(currentXmlElement, attribute.Value, attributes.Clone()); if (customAttribute.UsesApplyMethod && !defaultAttributeValues.ContainsKey(attribute.Key)) { defaultAttributeValues.Add(attribute.Key, customAttribute.DefaultValue); } if (!customAttribute.KeepOriginalTag) { attributes.Remove(attribute.Key); } } return(attributes); }
public static AttributeDictionary MergeAttributes(AttributeDictionary defaults, AttributeDictionary elementAttributes) { var result = defaults.Clone(); if (elementAttributes == null) { return(result); } foreach (var attribute in elementAttributes) { if (!result.ContainsKey(attribute.Key)) { result.Add(attribute.Key, attribute.Value); } else { result[attribute.Key] = attribute.Value; } } return(result); }