コード例 #1
0
        public ElementCompileTreeNode Evaluate(ElementCompileTreeNode node, List <PropertyCompileTreeNode> newProperties, string defaultOverloadPropertyName = null)
        {
            var replacedNodes = new Dictionary <ElementCompileTreeNode, List <PropertyCompileTreeNode> >();

            bool isIfProducer = node.Producer is IfProducer;

            if (!isIfProducer)
            {
                foreach (ElementCompileTreeNode child in node.Children)
                {
                    var newProps = new List <PropertyCompileTreeNode>();


                    string childDefaultOverloadPropertyName = null;
                    if (node.Producer != null)
                    {
                        ReadBindingControlValueOverload attribute = node.Producer.GetType().GetCustomAttributesRecursively <ReadBindingControlValueOverload>().SingleOrDefault();

                        if (attribute != null)
                        {
                            childDefaultOverloadPropertyName = attribute.PropertyName;
                        }
                    }

                    ElementCompileTreeNode resultNode = Evaluate(child, newProps, childDefaultOverloadPropertyName);

                    if ((null == resultNode) || (false == child.Equals(resultNode)))
                    {
                        replacedNodes.Add(child, newProps);

                        foreach (PropertyCompileTreeNode newProperty in newProps)
                        {
                            if (newProperty.Name == CompilerGlobals.DefaultPropertyName)
                            {
                                node.DefaultProperties.Add(newProperty);
                            }
                            else
                            {
                                node.AddNamedProperty(newProperty);
                            }
                        }
                    }
                }
            }


            if (!isIfProducer)
            {
                foreach (ElementCompileTreeNode nodeToRemove in replacedNodes.Keys)
                {
                    node.Children.Remove(nodeToRemove);
                }
            }


            return(EvaluateElementCompileTreeNode(node, newProperties, defaultOverloadPropertyName));
        }
コード例 #2
0
        public static ElementCompileTreeNode BuildRec(XElement element)
        {
            int depth = element.Ancestors().Count();

            var debugInfo = new XmlSourceNodeInformation(depth, element.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName);

            var result = new ElementCompileTreeNode(debugInfo);

            foreach (var attribute in element.Attributes())
            {
                if (attribute.Name.LocalName == "xmlns")
                {
                    continue;
                }

                bool isNamespaceDeclaration = attribute.Name.Namespace == "http://www.w3.org/2000/xmlns/";

                var property = new PropertyCompileTreeNode(attribute.Name.LocalName, debugInfo, isNamespaceDeclaration);
                property.Value = StringResourceSystemFacade.ParseString(attribute.Value);

                result.AddNamedProperty(property);
            }

            foreach (var node in element.Nodes())
            {
                if (node is XElement)
                {
                    result.Children.Add(BuildRec(node as XElement));
                    continue;
                }

                if (node is XText)
                {
                    string text = (node as XText).Value;

                    if (string.IsNullOrWhiteSpace(text))
                    {
                        continue;
                    }

                    var textProperty = new PropertyCompileTreeNode(CompilerGlobals.DefaultPropertyName, debugInfo);
                    textProperty.Value = StringResourceSystemFacade.ParseString(text);

                    result.DefaultProperties.Add(textProperty);
                    continue;
                }
            }

            return(result);
        }