示例#1
0
        private Element createElementFromTemplateNoChildren(Template template, Template parentTemplate, AttributeCollection attributes, Element parent, params object[] inputs)
        {
            // If the parent template exists and defines a template with the same name as the new element, use that template instead of the given one.
            string identifierName = attributes?.GetAttributeOrDefault(nameAttributeName, (string)null);

            if (parentTemplate == null || identifierName == null || !parentTemplate.ChildrenByIdentifierName.TryGetValue(identifierName, out Template baseTemplate))
            {
                baseTemplate = template;
            }

            // If attributes were given, combine them with the base template to make a unique template for this element.
            Template elementTemplate = attributes == null || attributes.Count == 0 ? baseTemplate.CreateCopy() : baseTemplate.CombineOver(attributes);

            // Get the style name from the element template attributes, if the style is missing, use the default.
            string styleName = elementTemplate.Attributes.GetAttributeOrDefault(styleAttributeName, string.Empty);
            Style  style     = string.IsNullOrWhiteSpace(styleName) ? styleManager.DefaultStyle.CreateCopy() : styleManager.GetStyleFromName(styleName);

            // Create the element.
            Element element = elementCache.CreateInstance(elementTemplate.ControllerName, serviceProvider, inputs);

            // Create the components, which internally initialises each one.
            Dictionary <Type, Component> components = componentManager.CreateComponents(elementTemplate.ComponentNames, element, inputs);

            // Initialise the element internally.
            element.internalOnCreated(root, this, styleManager, elementTemplate, parent == null ? ElementContainer : parent.ElementContainer, style, components);

            // Handle adding the element as tagged.
            addTaggedElement(element);

            // Initialise the element publicly.
            element.OnCreated();
            return(element);
        }
示例#2
0
        public StyleVariant(XmlNode variantNode, ResourceManager resourceManager, ConstructorCache <IStyleAttribute> attributeCache)
        {
            // Set the name.
            Name = variantNode.Name;

            foreach (XmlNode childNode in variantNode)
            {
                // Create the attribute.
                IStyleAttribute styleAttribute = attributeCache.CreateInstance(childNode.Name, resourceManager, new AttributeCollection(childNode));

                // Try to add the attributes to the collection.
                AddAttribute(styleAttribute);
            }
        }
示例#3
0
文件: Style.cs 项目: LiruJ/GuiCookie
        /// <summary> Creates a style from the given <paramref name="styleNode"/>. </summary>
        /// <param name="styleNode"> The <see cref="XmlNode"/> that contains the element style. </param>
        public Style(ResourceManager resourceManager, ConstructorCache <IStyleAttribute> attributeCache, XmlNode styleNode)
        {
            // Set the name of this style based on the name of the node.
            Name = styleNode.Name;

            // Create attributes from this style node.
            IReadOnlyAttributes attributes = new AttributeCollection(styleNode);

            // Set the name of the base style if one was given.
            BaseStyleName = attributes.GetAttributeOrDefault(BaseVariantName, string.Empty);

            // Hold collections of the loaded variants and attributes.
            List <StyleVariant>    variants        = new List <StyleVariant>();
            List <IStyleAttribute> styleAttributes = new List <IStyleAttribute>();

            // Read each child node.
            foreach (XmlNode childNode in styleNode)
            {
                // If the child node has children, load it as a variant.
                if (childNode.HasChildNodes)
                {
                    variants.Add(new StyleVariant(childNode, resourceManager, attributeCache));
                }
                // Otherwise; dynamically create the style attribute and add it to the list.
                else
                {
                    styleAttributes.Add(attributeCache.CreateInstance(childNode.Name, resourceManager, new AttributeCollection(childNode)));
                }
            }

            // Create the base variant using the loaded attributes.
            BaseVariant = new StyleVariant(BaseVariantName, styleAttributes);
            AddVariant(BaseVariant);

            // Create the derived variants using the base variant.
            foreach (StyleVariant variant in variants)
            {
                // Combine the variant with the base.
                variant.CombineOverBase(BaseVariant);

                // Add the variant to the dictionary using its name.
                AddVariant(variant);
            }
        }
示例#4
0
 public Component CreateComponent(string name, params object[] inputs) => componentCache.CreateInstance(name, serviceProvider, inputs);