private string GetValue(XamlAttribute node, int level) { if (node.Value is XamlExtensionObjectNodeBase extensionObjectNodeBase) { string description; if (string.IsNullOrEmpty(Name)) { description = string.Format(" {0}", extensionObjectNodeBase.GetDescription(level)); } else { description = string.Format(" {0}{1}", Name, extensionObjectNodeBase.GetDescription(level)); } return(description); } else { if (node.Name == "_PositionalParameters") { return(node.Value?.ToString()); } return(string.Format(", {0}={1}", node.Name, node.Value)); } }
public void SingleAttribute(string xamlText) { XamlParser parser = new XamlParser(Errors); XamlMainObjectNode mainNode = parser.ParseFromString(xamlText); Assert.IsNotNull(mainNode, "It must be parse result"); Assert.AreEqual("tag", mainNode.Name, "Wrong tag name"); Assert.AreEqual(XamlNodeBase.EState.Closed, mainNode.State, "Node state"); Assert.AreEqual(0, mainNode.Children.Count, "Wrong children count"); Assert.AreEqual(1, mainNode.Attributes.Count, "Wrong attributes count"); XamlNodeBase node = mainNode.Attributes[0]; Assert.AreEqual(XamlNodeBase.ENodeType.Attribute, node.NodeType, "Wrong attribute type"); XamlAttribute attribute = node as XamlAttribute; Assert.AreEqual("a1", attribute.Name, "Wrong attribute name"); Assert.AreEqual("value1", attribute.Value, "Wrong attribute value"); CheckTextRange("Attribute:", 1, 1, 6, 16, node); CheckTextRangeValue("Attribute value:", 1, 1, 9, 16, attribute); }
private void SetProperty(object instance, XamlAttribute elementProperty) { SetProperty(instance, elementProperty.Name, elementProperty.Value, null); }
internal static bool ConvertToAttribute(ConverterState converterState, string attributeName, ref XamlAttribute xamlAttribute) { if (attributeName.Length == 0) { return false; } xamlAttribute = (XamlAttribute)BasicLookup(AttributeTable, attributeName); return xamlAttribute != XamlAttribute.XAUnknown; }
protected static void CheckTextRangeValue(string prefix, int?expectedLs, int?expectedLe, int?expectedPs, int?expectedPe, XamlAttribute node) { Assert.AreEqual(expectedLs, node.LineNumberValueStart, prefix + "Line number value start"); Assert.AreEqual(expectedLe, node.LineNumberValueEnd, prefix + "Line number value end"); Assert.AreEqual(expectedPs, node.LinePositionValueStart, prefix + "Position value start"); Assert.AreEqual(expectedPe, node.LinePositionValueEnd, prefix + "Position value end"); }
private static bool ReadAttributes(XamlObjectNode xamlObjectNode, SymbolScanner scanner, char chNext) { bool ret = false; char breakSymbol; string attributeName = string.Empty; string attributeValue = string.Empty; while (chNext != SymbolScanner.SymbolEndTag) { scanner.SkipSpaces(); XamlAttribute attribute = null; int lineNumberValue = -1; int linePositionValue = -1; int lineNumberAttrName = scanner.LineNumber; int linePositionAttrName = scanner.CharPosition; if (scanner.NextSymbol == SymbolScanner.SymbolCloseTag || scanner.NextSymbol == SymbolScanner.SymbolEndTag) { if (attribute != null) { attribute.LineNumberEnd = scanner.LineNumber; attribute.LinePositionEnd = scanner.CharPosition; } chNext = scanner.NextSymbol; break; } attributeName = scanner.GetName(); scanner.SkipSpaces(); breakSymbol = scanner.NextSymbol; if (breakSymbol == SymbolScanner.SymbolEq) { //skip '=' scanner.SkipSymbol(); scanner.SkipSpaces(); lineNumberValue = scanner.LineNumber; linePositionValue = scanner.CharPosition; attributeValue = scanner.ReadString(); chNext = scanner.CheckEndOfLine(scanner.NextSymbol); } else if (breakSymbol == SymbolScanner.SymbolEndTag) { if (attribute != null) { attribute.LineNumberEnd = scanner.LineNumber; attribute.LinePositionEnd = scanner.CharPosition; } chNext = breakSymbol; } else if (breakSymbol == SymbolScanner.SymbolCloseTag) { chNext = scanner.GetSymbol(); chNext = scanner.NextSymbol; } else { scanner.SkipSpaces(); chNext = scanner.NextSymbol; } attribute = new XamlAttribute(attributeName, attributeValue) { LineNumberStart = lineNumberAttrName + 1, LineNumberEnd = scanner.LineNumber + 1, LinePositionStart = linePositionAttrName + 1, LinePositionEnd = scanner.CharPosition, LineNumberValueStart = lineNumberValue + 1, LineNumberValueEnd = scanner.LineNumber + 1, LinePositionValueStart = linePositionValue + 1, LinePositionValueEnd = scanner.CharPosition }; xamlObjectNode.Attributes.Add(attribute); Trace.WriteLine( string.Format( "\t{0}:{1} Attribute Name:{2}, {3}:{4} Value:{5}", lineNumberAttrName + 1, linePositionAttrName + 1, attributeName, lineNumberValue + 1, linePositionValue + 1, attributeValue)); } ret = chNext == SymbolScanner.SymbolEndTag; chNext = scanner.CheckEndOfLine(scanner.NextSymbol); if (ret) { chNext = scanner.GetSymbol(); //chNext = TestNextSymbol(fileStream); chNext = scanner.CheckEndOfLine(chNext); } return(ret); }
private void ReadObjectElement(XamlName name, bool isEmptyTag) { this._typeArgumentAttribute = null; XamlScannerNode node = new XamlScannerNode(this._xmlLineInfo); this.PreprocessAttributes(); node.Prefix = name.Prefix; node.IsEmptyTag = isEmptyTag; string namespaceURI = this._xmlReader.NamespaceURI; if (namespaceURI == null) { this.ReadObjectElement_NoNamespace(name, node); } else { node.TypeNamespace = namespaceURI; XamlMember xamlDirective = this._parserContext.SchemaContext.GetXamlDirective(namespaceURI, name.Name); if (xamlDirective != null) { this.ReadObjectElement_DirectiveProperty(xamlDirective, node); } else if (this.ReadObjectElement_Object(namespaceURI, name.Name, node)) { return; } } this._readNodesQueue.Enqueue(node); while (this.HaveUnprocessedAttributes) { this.EnqueueAnotherAttribute(isEmptyTag); } }
private void PreprocessForTypeArguments(List<XamlAttribute> attrList) { int index = -1; for (int i = 0; i < attrList.Count; i++) { XamlAttribute attribute = attrList[i]; if (KS.Eq(attribute.Name.Name, XamlLanguage.TypeArguments.Name)) { string xamlNS = this._parserContext.FindNamespaceByPrefix(attribute.Name.Prefix); if (this._parserContext.ResolveDirectiveProperty(xamlNS, attribute.Name.Name) != null) { index = i; this._typeArgumentAttribute = attribute; break; } } } if (index >= 0) { attrList.RemoveAt(index); } }
private void PreprocessAttributes() { if (this._xmlReader.MoveToFirstAttribute()) { List<XamlAttribute> attrList = new List<XamlAttribute>(); do { string longName = this._xmlReader.Name; string val = this._xmlReader.Value; XamlPropertyName propName = XamlPropertyName.Parse(longName); if (propName == null) { throw new XamlParseException(System.Xaml.SR.Get("InvalidXamlMemberName", new object[] { longName })); } XamlAttribute attr = new XamlAttribute(propName, val, this._xmlLineInfo); if (attr.Kind == ScannerAttributeKind.Namespace) { this.EnqueuePrefixDefinition(attr); } else { attrList.Add(attr); } } while (this._xmlReader.MoveToNextAttribute()); this.PreprocessForTypeArguments(attrList); if (attrList.Count > 0) { this._attributes = attrList; } this._xmlReader.MoveToElement(); } }
private void EnqueuePrefixDefinition(XamlAttribute attr) { string xmlNsPrefixDefined = attr.XmlNsPrefixDefined; string xmlNsUriDefined = attr.XmlNsUriDefined; this._parserContext.AddNamespacePrefix(xmlNsPrefixDefined, xmlNsUriDefined); XamlScannerNode item = new XamlScannerNode(attr) { NodeType = ScannerNodeType.PREFIXDEFINITION, Prefix = xmlNsPrefixDefined, TypeNamespace = xmlNsUriDefined }; this._readNodesQueue.Enqueue(item); }