Exemplo n.º 1
0
        private void WriteAttribute(XmlWriter writer, XmlAttribute attribute, List <StyleResource> styleResources)
        {
            if (ParsingHelper.IsXmlOnlyAttribute(attribute))
            {
                WriteSpecificAttribute(writer, attribute, styleResources);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(attribute.NamespaceUri))
                {
                    string namespaceUri  = attribute.NamespaceUri;
                    string localName     = attribute.LocalName;
                    string namespaceName = attribute.FullName.Split(':')[0];

                    if (_nsDictionary.ContainsKey(namespaceUri))
                    {
                        namespaceName = _nsDictionary[namespaceUri];
                    }
                    else
                    {
                        _nsDictionary.Add(namespaceUri, namespaceName);
                    }

                    writer.WriteAttributeString(namespaceName, localName, namespaceUri, attribute.Value);
                }
                else
                {
                    writer.WriteAttributeString(attribute.FullName, attribute.Value);
                }
            }
        }
Exemplo n.º 2
0
        private void WriteSpecificAttribute(XmlWriter writer, XmlAttribute attribute, List <StyleResource> styleResources)
        {
            if (ParsingHelper.IsStyleAttribute(attribute))
            {
                BindingLanguageParser compiler = new BindingLanguageParser();
                bool       result;
                Expression resultExpression = compiler.Parse(attribute.Value, out result);

                if (!result)
                {
                    throw new CompileException(string.Format("Can not compile expression {0}", attribute.Value));
                }

                if (!resultExpression.IsOfType(ExpressionType.Resource))
                {
                    throw new CompileException(string.Format("Expecting resource expression for style, got {0}", attribute.Value));
                }

                string resourceKey = resultExpression.GetValue(ResourceExpression.KEY);
                //find correct resource
                StyleResource styleResource = styleResources.FirstOrDefault(x => resourceKey.Equals(x.Key, StringComparison.InvariantCultureIgnoreCase));

                if (styleResource == null)
                {
                    throw new IndexOutOfRangeException(string.Format("Resource with key {0} does not exists", resourceKey));
                }

                foreach (XmlAttribute attr in styleResource.ResourceElement.Attributes.Where(x => !ParsingHelper.IsResourceKeyAttribute(x)))
                {
                    // write all attributes embedded in the style
                    WriteAttribute(writer, attr, styleResources);
                }
            }
        }
Exemplo n.º 3
0
        private void WriteAttribute(XmlWriter writer, XmlAttribute attribute, List<StyleResource> styleResources)
        {
            if (ParsingHelper.IsXmlOnlyAttribute(attribute))
            {
                WriteSpecificAttribute(writer, attribute, styleResources);
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(attribute.NamespaceUri))
                {
                    string namespaceUri = attribute.NamespaceUri;
                    string localName = attribute.LocalName;
                    string namespaceName = attribute.FullName.Split(':')[0];

                    if (_nsDictionary.ContainsKey(namespaceUri))
                    {
                        namespaceName = _nsDictionary[namespaceUri];
                    }
                    else
                    {
                        _nsDictionary.Add(namespaceUri, namespaceName);
                    }

                    writer.WriteAttributeString(namespaceName, localName, namespaceUri, attribute.Value);
                }
                else
                {
                    writer.WriteAttributeString(attribute.FullName, attribute.Value);
                }
            }
        }
Exemplo n.º 4
0
 public static bool IsStyleAttribute(XmlAttribute attribute)
 {
     return IsAttributeNamed(attribute, DefaultConfiguration.XmlStyleAttribute);
 }
Exemplo n.º 5
0
 public static bool IsResourceKeyAttribute(XmlAttribute attribute)
 {
     return IsAttributeNamed(attribute, RESOURCE_KEY_ATTRIBUTE);
 }
Exemplo n.º 6
0
 public static bool IsIdAttribute(XmlAttribute attribute)
 {
     return IsAttributeNamed(attribute, ID_ATTRIBUTE);
 }
Exemplo n.º 7
0
 public static bool IsCustomAttribute(XmlAttribute attribute)
 {
     return DefaultConfiguration.CustomAttribute.Any(x => IsAttributeNamed(attribute, x));
 }
Exemplo n.º 8
0
 public static bool IsAttributeWithExpression(XmlAttribute attribute)
 {
     return IsExpressionValue(attribute.Value);
 }
Exemplo n.º 9
0
 private static bool IsAttributeNamed(XmlAttribute attribute, string name)
 {
     return name.Equals(attribute.LocalName, StringComparison.InvariantCultureIgnoreCase);
 }
Exemplo n.º 10
0
 public static bool IsXmlOnlyAttribute(XmlAttribute attribute)
 {
     return DefaultConfiguration.XmlOnlyAttributes.Any(x => IsAttributeNamed(attribute, x));
 }
Exemplo n.º 11
0
        private void WriteSpecificAttribute(XmlWriter writer, XmlAttribute attribute, List<StyleResource> styleResources)
        {
            if (ParsingHelper.IsStyleAttribute(attribute))
            {
                BindingLanguageParser compiler = new BindingLanguageParser();
                bool result;
                Expression resultExpression = compiler.Parse(attribute.Value, out result);

                if (!result)
                {
                    throw new CompileException(string.Format("Can not compile expression {0}", attribute.Value));
                }

                if (!resultExpression.IsOfType(ExpressionType.Resource))
                {
                    throw new CompileException(string.Format("Expecting resource expression for style, got {0}", attribute.Value));
                }

                string resourceKey = resultExpression.GetValue(ResourceExpression.KEY);
                //find correct resource
                StyleResource styleResource = styleResources.FirstOrDefault(x => resourceKey.Equals(x.Key, StringComparison.InvariantCultureIgnoreCase));

                if (styleResource == null)
                {
                    throw new IndexOutOfRangeException(string.Format("Resource with key {0} does not exists", resourceKey));
                }

                foreach (XmlAttribute attr in styleResource.ResourceElement.Attributes.Where(x => !ParsingHelper.IsResourceKeyAttribute(x)))
                {
                    // write all attributes embedded in the style
                    WriteAttribute(writer, attr, styleResources);
                }
            }
        }