Пример #1
0
        public virtual void ClassChanged()
        {
            if (currentXmlLayoutInstance.defaultAttributeValues.ContainsKey(this.tagType))
            {
                var defaultAttributesMerged = new AttributeDictionary();

                if (this.currentXmlLayoutInstance.defaultAttributeValues[this.tagType].ContainsKey("all"))
                {
                    defaultAttributesMerged = this.currentXmlLayoutInstance.defaultAttributeValues[this.tagType]["all"];
                }

                if (currentXmlElement.classes != null && currentXmlElement.classes.Any())
                {
                    foreach (var _class in currentXmlElement.classes)
                    {
                        if (currentXmlLayoutInstance.defaultAttributeValues[this.tagType].ContainsKey(_class))
                        {
                            defaultAttributesMerged = XmlLayoutUtilities.MergeAttributes(defaultAttributesMerged, currentXmlLayoutInstance.defaultAttributeValues[this.tagType][_class]);
                        }
                    }
                }

                // remove any class attributes that have been defined directly on the element
                defaultAttributesMerged = new AttributeDictionary(defaultAttributesMerged.Where(a => !currentXmlElement.elementAttributes.Contains(a.Key)).ToDictionary(k => k.Key, v => v.Value));

                // merge in the updated class attributes and apply them
                //currentXmlElement.attributes = XmlLayoutUtilities.MergeAttributes(defaultAttributesMerged, elementAttributes);
                currentXmlElement.ApplyAttributes(defaultAttributesMerged);
            }
        }
Пример #2
0
        public virtual void ClassChanged()
        {
            if (currentXmlLayoutInstance.defaultAttributeValues.ContainsKey(this.tagType))
            {
                var defaultAttributesMerged = new AttributeDictionary();

                var elementAttributes = new AttributeDictionary(currentXmlElement.elementAttributes.ToDictionary(k => k, v => currentXmlElement.GetAttribute(v)));

                defaultAttributesMerged = currentXmlLayoutInstance.MergeDefaultAttributesWithElementAttributes(currentXmlElement, this.tagType, elementAttributes);

                // remove any class attributes that have been defined directly on the element
                defaultAttributesMerged = new AttributeDictionary(defaultAttributesMerged.Where(a => !currentXmlElement.elementAttributes.Contains(a.Key)).ToDictionary(k => k.Key, v => v.Value));

                // merge in the updated class attributes and apply them
                //currentXmlElement.attributes = XmlLayoutUtilities.MergeAttributes(defaultAttributesMerged, elementAttributes);
                currentXmlElement.ApplyAttributes(defaultAttributesMerged);
            }
        }
Пример #3
0
        /// <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 = XmlLayoutUtilities.GetTagName(GetType());
            //var elementName = this.GetType().Name.Replace("TagHandler", String.Empty);
            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;
                    }
                }

                if (customAttribute.UsesConvertMethod)
                {
                    attributes = XmlLayoutUtilities.MergeAttributes(
                        attributes,
                        customAttribute.Convert(attribute.Value, attributes.AsReadOnly(), this.currentXmlElement));
                }

                if (customAttribute.UsesApplyMethod)
                {
                    customAttribute.Apply(currentXmlElement, attribute.Value, attributes.AsReadOnly());
                }

                if (customAttribute.UsesApplyMethod && !defaultAttributeValues.ContainsKey(attribute.Key))
                {
                    defaultAttributeValues.Add(attribute.Key, customAttribute.DefaultValue);
                }

                if (!customAttribute.KeepOriginalTag)
                {
                    attributes.Remove(attribute.Key);
                }
            }

            return(attributes);
        }