private void ResolvePropertyName(string longName) { XamlPropertyName propName = XamlPropertyName.Parse(longName); if (propName == null) { throw new ArgumentException(SR.Get(SRID.MalformedPropertyName)); } XamlMember prop = null; XamlType declaringType; XamlType tagType = _context.CurrentType; string tagNamespace = _context.CurrentTypeNamespace; if (propName.IsDotted) { prop = _context.GetDottedProperty(tagType, tagNamespace, propName, false /*tagIsRoot*/); } // Regular property p else { string ns = _context.GetAttributeNamespace(propName, Namespace); declaringType = _context.CurrentType; prop = _context.GetNoDotAttributeProperty(declaringType, propName, Namespace, ns, false /*tagIsRoot*/); } _tokenProperty = prop; }
public static XamlPropertyName Parse(string longName, string namespaceURI) { XamlPropertyName propName = Parse(longName); propName._namespace = namespaceURI; return(propName); }
private void ReadPropertyElement(XamlPropertyName name, XamlType tagType, string tagNamespace, bool isEmptyTag) { XamlScannerNode node = new XamlScannerNode(this._xmlLineInfo); this.PreprocessAttributes(); string namespaceURI = this._xmlReader.NamespaceURI; XamlMember member = null; bool tagIsRoot = this._scannerStack.Depth == 1; member = this._parserContext.GetDottedProperty(tagType, tagNamespace, name, tagIsRoot); node.Prefix = name.Prefix; node.TypeNamespace = namespaceURI; node.IsEmptyTag = isEmptyTag; this.PostprocessAttributes(node); if (this._scannerStack.Depth > 0) { this._scannerStack.CurrentlyInContent = false; } node.PropertyElement = member; node.IsCtorForcingMember = !member.IsAttachable; if (!node.IsEmptyTag) { this._scannerStack.CurrentProperty = node.PropertyElement; node.NodeType = ScannerNodeType.PROPERTYELEMENT; } else { node.NodeType = ScannerNodeType.EMPTYPROPERTYELEMENT; } this._readNodesQueue.Enqueue(node); while (this.HaveUnprocessedAttributes) { this.EnqueueAnotherAttribute(isEmptyTag); } }
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(); } }
// ============= Element Processing ================================== private void ReadElement() { // Accumulated text is enqueued a piece of content before this element EnqueueAnyText(); _hasKeyAttribute = false; // Empty Elements are by definition leaf elements and they // don't nest. So we don't need to stack this state. bool isEmptyTag = _xmlReader.IsEmptyElement; string prefix = _xmlReader.Prefix; string strippedName = _xmlReader.LocalName; if (XamlName.ContainsDot(strippedName)) { Debug.Assert(_xmlReader.NodeType == XmlNodeType.Element); XamlPropertyName name = XamlPropertyName.Parse(_xmlReader.Name, _xmlReader.NamespaceURI); if (_scannerStack.CurrentType == null) { throw LineInfo(new XamlParseException(SR.Get(SRID.ParentlessPropertyElement, _xmlReader.Name))); } ReadPropertyElement(name, _scannerStack.CurrentType, _scannerStack.CurrentTypeNamespace, isEmptyTag); } else { XamlName name = new XamlQualifiedName(prefix, strippedName); ReadObjectElement(name, isEmptyTag); } }
// ========================== private ================================ private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot) { XamlMember prop = null; string ns = context.GetAttributeNamespace(propName, tagNamespace); // No Namespace, == Unknown Property if (ns == null) { XamlMember unknownProperty; if (propName.IsDotted) { XamlType attachedOwnerType = new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext); unknownProperty = new XamlMember(propName.Name, attachedOwnerType, true /*isAttachable*/); } else { unknownProperty = new XamlMember(propName.Name, tagType, false); } return(unknownProperty); } // Get the property (attached, normal, or directive) if (propName.IsDotted) { prop = context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot); } else { prop = context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, ns, tagIsRoot); } return(prop); }
public string GetAttributeNamespace(XamlPropertyName propName, string tagNamespace) { if (string.IsNullOrEmpty(propName.Prefix) && !propName.IsDotted) { return tagNamespace; } return this.ResolveXamlNameNS(propName); }
public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot) { if (tagType == null) { throw new XamlInternalException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { propName.ScopedName })); } XamlMember xamlAttachableProperty = null; XamlType xamlType = null; string propNs = this.ResolveXamlNameNS(propName); if (propNs == null) { throw new XamlParseException(System.Xaml.SR.Get("PrefixNotFound", new object[] { propName.Prefix })); } XamlType rootTagType = tagIsRoot ? tagType : null; bool flag = false; if (tagType.IsGeneric) { flag = this.PropertyTypeMatchesGenericTagType(tagType, tagNamespace, propNs, propName.OwnerName); if (flag) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType); if (xamlAttachableProperty != null) { return xamlAttachableProperty; } } } XamlTypeName typeName = new XamlTypeName(propNs, propName.Owner.Name); xamlType = this.GetXamlType(typeName, true); bool flag2 = tagType.CanAssignTo(xamlType); if (flag2) { xamlAttachableProperty = this.GetInstanceOrAttachableProperty(xamlType, propName.Name, rootTagType); } else { xamlAttachableProperty = this.GetXamlAttachableProperty(xamlType, propName.Name); } if (xamlAttachableProperty != null) { return xamlAttachableProperty; } XamlType declaringType = flag ? tagType : xamlType; if (flag || flag2) { return this.CreateUnknownMember(declaringType, propName.Name); } return this.CreateUnknownAttachableMember(declaringType, propName.Name); }
public XamlAttribute(XamlPropertyName propName, string val, IXmlLineInfo lineInfo) { this.Name = propName; this.Value = val; this.Kind = ScannerAttributeKind.Property; if (lineInfo != null) { this.LineNumber = lineInfo.LineNumber; this.LinePosition = lineInfo.LinePosition; } if (this.CheckIsXmlNamespaceDefinition(out this._xmlnsDefinitionPrefix, out this._xmlnsDefinitionUri)) { this.Kind = ScannerAttributeKind.Namespace; } }
// ======== Attribute Processing ============================= private void PreprocessAttributes() { // Collect up all the attributes. bool b = _xmlReader.MoveToFirstAttribute(); if (!b) { return; } List <XamlAttribute> list = new List <XamlAttribute>(); do { string xmlName = _xmlReader.Name; string val = _xmlReader.Value; XamlPropertyName propName = XamlPropertyName.Parse(xmlName); if (propName == null) { throw new XamlParseException(SR.Get(SRID.InvalidXamlMemberName, xmlName)); } XamlAttribute attr = new XamlAttribute(propName, val, _xmlLineInfo); if (attr.Kind == ScannerAttributeKind.Namespace) { EnqueuePrefixDefinition(attr); } else { list.Add(attr); } b = _xmlReader.MoveToNextAttribute(); } while (b); PreprocessForTypeArguments(list); if (list.Count > 0) { _attributes = list; } // Restore the XML reader’s position to the Element after reading the // attributes so that the rest of the code can always assume it is on an Element _xmlReader.MoveToElement(); }
public XamlAttribute(XamlPropertyName propName, string val, IXmlLineInfo lineInfo) { Name = propName; Value = val; Kind = ScannerAttributeKind.Property; // non-"namespace" default; if (lineInfo != null) { LineNumber = lineInfo.LineNumber; LinePosition = lineInfo.LinePosition; } // XmlNs like: xmlns:c="someUristring" if (CheckIsXmlNamespaceDefinition(out _xmlnsDefinitionPrefix, out _xmlnsDefinitionUri)) { Kind = ScannerAttributeKind.Namespace; } }
private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot) { string attributeNamespace = context.GetAttributeNamespace(propName, tagNamespace); if (attributeNamespace == null) { if (propName.IsDotted) { return new XamlMember(propName.Name, new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext), true); } return new XamlMember(propName.Name, tagType, false); } if (propName.IsDotted) { return context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot); } return context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, attributeNamespace, tagIsRoot); }
public static XamlPropertyName Parse(string longName) { if (String.IsNullOrEmpty(longName)) { return(null); } string prefix; string dottedName; if (!XamlQualifiedName.Parse(longName, out prefix, out dottedName)) { return(null); } int start = 0; string owner = string.Empty; int dotIdx = dottedName.IndexOf('.'); if (dotIdx != -1) { owner = dottedName.Substring(start, dotIdx); if (String.IsNullOrEmpty(owner)) { return(null); } start = dotIdx + 1; } string name = (start == 0) ? dottedName : dottedName.Substring(start); XamlQualifiedName ownerName = null; if (!String.IsNullOrEmpty(owner)) { ownerName = new XamlQualifiedName(prefix, owner); } XamlPropertyName propName = new XamlPropertyName(ownerName, prefix, name); return(propName); }
private XamlMember GetXamlAttributeProperty(XamlParserContext context, XamlPropertyName propName, XamlType tagType, string tagNamespace, bool tagIsRoot) { string attributeNamespace = context.GetAttributeNamespace(propName, tagNamespace); if (attributeNamespace == null) { if (propName.IsDotted) { return(new XamlMember(propName.Name, new XamlType(string.Empty, propName.OwnerName, null, context.SchemaContext), true)); } return(new XamlMember(propName.Name, tagType, false)); } if (propName.IsDotted) { return(context.GetDottedProperty(tagType, tagNamespace, propName, tagIsRoot)); } return(context.GetNoDotAttributeProperty(tagType, propName, tagNamespace, attributeNamespace, tagIsRoot)); }
private void ReadElement() { this.EnqueueAnyText(); this._hasKeyAttribute = false; bool isEmptyElement = this._xmlReader.IsEmptyElement; string prefix = this._xmlReader.Prefix; string localName = this._xmlReader.LocalName; if (XamlName.ContainsDot(localName)) { XamlPropertyName name = XamlPropertyName.Parse(this._xmlReader.Name, this._xmlReader.NamespaceURI); if (this._scannerStack.CurrentType == null) { throw this.LineInfo(new XamlParseException(System.Xaml.SR.Get("ParentlessPropertyElement", new object[] { this._xmlReader.Name }))); } this.ReadPropertyElement(name, this._scannerStack.CurrentType, this._scannerStack.CurrentTypeNamespace, isEmptyElement); } else { XamlName name2 = new XamlQualifiedName(prefix, localName); this.ReadObjectElement(name2, isEmptyElement); } }
private void ResolvePropertyName(string longName) { XamlPropertyName propName = XamlPropertyName.Parse(longName); if (propName == null) { throw new ArgumentException(System.Xaml.SR.Get("MalformedPropertyName")); } XamlMember member = null; XamlType currentType = this._context.CurrentType; string currentTypeNamespace = this._context.CurrentTypeNamespace; if (propName.IsDotted) { member = this._context.GetDottedProperty(currentType, currentTypeNamespace, propName, false); } else { string attributeNamespace = this._context.GetAttributeNamespace(propName, this._tokenNamespace); XamlType tagType = this._context.CurrentType; member = this._context.GetNoDotAttributeProperty(tagType, propName, this._tokenNamespace, attributeNamespace, false); } this._tokenProperty = member; }
private void ReadPropertyElement(XamlPropertyName name, XamlType tagType, string tagNamespace, bool isEmptyTag) { // <Button> <== currentElement // <FrameworkElement.Width> <== FrameworkElement is ownerType XamlScannerNode node = new XamlScannerNode(_xmlLineInfo); // Attributes aren't allowed on property elements. // but if they are there we need to scan them so the // XamlParser can error, or whatever. // (don't want to skip them w/o error) PreprocessAttributes(); // It is possible for an application to provide XML nodes via XmlNodeReader // where the URI is defined but there was no xmlns attribute for use to resolve against. // See app Paperboy Debug.Assert(_xmlReader.NodeType == XmlNodeType.Element); string ownerNamespace = _xmlReader.NamespaceURI; XamlMember property = null; bool tagIsRoot = _scannerStack.Depth == 1; // PEs are processed after frame is pushed property = _parserContext.GetDottedProperty(tagType, tagNamespace, name, tagIsRoot); node.Prefix = name.Prefix; node.TypeNamespace = ownerNamespace; node.IsEmptyTag = isEmptyTag; // node.Type is not set (this is a property) // so this processing does less. PostprocessAttributes(node); if (_scannerStack.Depth > 0) { // A property Element tag will be the end of content. // This also allows to to start content again. // That is an error, but at least the parser/scanner can // understand what is going on. _scannerStack.CurrentlyInContent = false; } node.PropertyElement = property; node.IsCtorForcingMember = !property.IsAttachable; if (!node.IsEmptyTag) { _scannerStack.CurrentProperty = node.PropertyElement; node.NodeType = ScannerNodeType.PROPERTYELEMENT; } else { node.NodeType = ScannerNodeType.EMPTYPROPERTYELEMENT; } _readNodesQueue.Enqueue(node); while (HaveUnprocessedAttributes) { EnqueueAnotherAttribute(isEmptyTag); } }
public XamlMember GetNoDotAttributeProperty(XamlType tagType, XamlPropertyName propName, string tagNamespace, string propUsageNamespace, bool tagIsRoot) { XamlMember xamlAttachableProperty = null; if ((propUsageNamespace == tagNamespace) || (((tagNamespace == null) && (propUsageNamespace != null)) && tagType.GetXamlNamespaces().Contains(propUsageNamespace))) { XamlType rootObjectType = tagIsRoot ? tagType : null; xamlAttachableProperty = this.GetXamlProperty(tagType, propName.Name, rootObjectType); if (xamlAttachableProperty == null) { xamlAttachableProperty = this.GetXamlAttachableProperty(tagType, propName.Name); } } if ((xamlAttachableProperty == null) && (propUsageNamespace != null)) { XamlDirective xamlDirective = this.SchemaContext.GetXamlDirective(propUsageNamespace, propName.Name); if (xamlDirective != null) { if ((xamlDirective.AllowedLocation & AllowedMemberLocations.Attribute) == AllowedMemberLocations.None) { xamlDirective = new XamlDirective(propUsageNamespace, propName.Name); } xamlAttachableProperty = xamlDirective; } } if (xamlAttachableProperty != null) { return xamlAttachableProperty; } if (tagNamespace == propUsageNamespace) { return new XamlMember(propName.Name, tagType, false); } return new XamlDirective(propUsageNamespace, propName.Name); }