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); } } }
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); } } }
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); } } }
public static bool IsStyleAttribute(XmlAttribute attribute) { return IsAttributeNamed(attribute, DefaultConfiguration.XmlStyleAttribute); }
public static bool IsResourceKeyAttribute(XmlAttribute attribute) { return IsAttributeNamed(attribute, RESOURCE_KEY_ATTRIBUTE); }
public static bool IsIdAttribute(XmlAttribute attribute) { return IsAttributeNamed(attribute, ID_ATTRIBUTE); }
public static bool IsCustomAttribute(XmlAttribute attribute) { return DefaultConfiguration.CustomAttribute.Any(x => IsAttributeNamed(attribute, x)); }
public static bool IsAttributeWithExpression(XmlAttribute attribute) { return IsExpressionValue(attribute.Value); }
private static bool IsAttributeNamed(XmlAttribute attribute, string name) { return name.Equals(attribute.LocalName, StringComparison.InvariantCultureIgnoreCase); }
public static bool IsXmlOnlyAttribute(XmlAttribute attribute) { return DefaultConfiguration.XmlOnlyAttributes.Any(x => IsAttributeNamed(attribute, x)); }
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); } } }