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)); }
void AnalyzePropertyAttr(TypeDefinition typeDef, XamlContext txt, XAttribute attr) { XamlPropertyName name = XamlPropertyName.Parse(typeDef, attr.Name, txt); name.Xmlns = attr.Parent.GetPrefixOfNamespace(name.Xmlns); var prop = ResolveProperty(name.TypeDef, name.PropertyName); if (prop != null && Assemblies.Contains(prop.DeclaringType.Module.Assembly)) { IXmlLineInfo li = attr as IXmlLineInfo; string line = txt.lines[li.LineNumber - 1]; int end = line.IndexOf('=', li.LinePosition - 1); string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1); var r = new XamlPropertyNameReference() { Name = name }; txt.refers.Add(new XamlRef() { lineNum = li.LineNumber - 1, index = li.LinePosition - 1, length = end - li.LinePosition + 1, name = name, refer = r }); ((prop as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r); } if (name.Xmlns == "x" && name.PropertyName == "Class") { IXmlLineInfo li = attr as IXmlLineInfo; string line = txt.lines[li.LineNumber - 1]; int start = line.IndexOf('=', li.LinePosition - 1) + 2; int end = line.IndexOf(line[start - 1], start); string fullName = line.Substring(start, end - start); TypeDefinition type = txt.context.MainModule.GetType(fullName); if (type != null) { var n = new XamlClrName() { Namespace = type.Namespace, Name = type.Name }; var r = new XamlClrNameReference() { Name = n }; txt.refers.Add(new XamlRef() { lineNum = li.LineNumber - 1, index = start, length = end - start, name = n, refer = r }); ((type as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r); } } }
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 XamlMember GetNoDotAttributeProperty(XamlType tagType, XamlPropertyName propName, string tagNamespace, string propUsageNamespace, bool tagIsRoot) { XamlMember property = null; // workaround: tagNamespace will always be null coming from MeScanner. // Second line of if just handles tagNamespace always being null from MEScanner // Correct fix is to fix MEScanner and remove second line if ((propUsageNamespace == tagNamespace) || (tagNamespace == null && propUsageNamespace != null && tagType.GetXamlNamespaces().Contains(propUsageNamespace))) { XamlType rootTagType = tagIsRoot ? tagType : null; property = GetXamlProperty(tagType, propName.Name, rootTagType); // Sometimes Attached properties look like normal properties. // [Attribute case] The above lookup fails and fall into here. // <Grid> <Grid Row="0"/> </Grid> if (property == null) { property = GetXamlAttachableProperty(tagType, propName.Name); } } // Not Simple, not Attachable, look for Directives. if (property == null && propUsageNamespace != null) { // A processing attribute like; x:Key x:Name XamlDirective directive = SchemaContext.GetXamlDirective(propUsageNamespace, propName.Name); if (directive != null) { if (AllowedMemberLocations.None == (directive.AllowedLocation & AllowedMemberLocations.Attribute)) { // Need a way to surface up this usage error now that // we don't have UnknownProperty.Exception directive = new XamlDirective(propUsageNamespace, propName.Name); } property = directive; } } if (property == null) { if (tagNamespace == propUsageNamespace) { // Unknown simple property property = new XamlMember(propName.Name, tagType, false); } else { // Unknown directive property = new XamlDirective(propUsageNamespace, propName.Name); } } return(property); }
public string GetAttributeNamespace(XamlPropertyName propName, string tagNamespace) { string ns = null; // Get the proper XamlNamespace for the Property // If prefix is "" then // Normal Properties resolve to the ownerType namespace // Attachable properties resolve to the actual "" namespace if (String.IsNullOrEmpty(propName.Prefix) && !propName.IsDotted) { ns = tagNamespace; } else { ns = ResolveXamlNameNS(propName); } return(ns); }
void AnalyzePropertyElem(TypeDefinition typeDef, XamlContext txt, XElement elem) { XamlPropertyName name = XamlPropertyName.Parse(typeDef, elem.Name, txt); name.Xmlns = elem.GetPrefixOfNamespace(name.Xmlns); var prop = ResolveProperty(name.TypeDef, name.PropertyName); if (prop != null && Assemblies.Contains(prop.DeclaringType.Module.Assembly)) { IXmlLineInfo li = elem as IXmlLineInfo; string line = txt.lines[li.LineNumber - 1]; int end = line.IndexOf('>', li.LinePosition - 1); string str = line.Substring(li.LinePosition - 1, end - li.LinePosition + 1); var r = new XamlPropertyNameReference() { Name = name }; txt.refers.Add(new XamlRef() { lineNum = li.LineNumber - 1, index = li.LinePosition - 1, length = end - li.LinePosition + 1, name = name, refer = r }); ((prop as IAnnotationProvider).Annotations[RenRef] as List <IReference>).Add(r); } foreach (var i in elem.Elements()) { if (i.Name.LocalName.Contains(".")) { AnalyzePropertyElem(name.TypeDef, txt, i); } else { AnalyzeElement(txt, i); } } }
/// <summary> /// Resolves a property of the form 'Foo.Bar' or 'a:Foo.Bar', in /// in the context of a parent tag. The parent tagType may or may not /// be covariant with the ownerType. In the case of dotted attribute /// syntax, the namespace my be passed in. /// </summary> /// <param name="tagType">The xamlType of the enclosing Tag</param> /// <param name="tagNamespace">The namespace of the enclosing Tag</param> /// <param name="propName">The dotted name of the property</param> /// <param name="tagIsRoot">Whether the tag is the root of the document</param> /// <returns></returns> public XamlMember GetDottedProperty(XamlType tagType, string tagNamespace, XamlPropertyName propName, bool tagIsRoot) { if (tagType == null) { throw new XamlInternalException(SR.Get(SRID.ParentlessPropertyElement, propName.ScopedName)); } XamlMember property = null; XamlType ownerType = null; string ns = ResolveXamlNameNS(propName); if (ns == null) { throw new XamlParseException(SR.Get(SRID.PrefixNotFound, propName.Prefix)); } XamlType rootTagType = tagIsRoot ? tagType : null; // If we have <foo x:TA="" foo.bar=""/> we want foo in foo.bar to match the tag // type since there is no way to specify generic syntax in dotted property notation // If that fails, then we fall back to the non-generic case below. bool ownerTypeMatchesGenericTagType = false; if (tagType.IsGeneric) { ownerTypeMatchesGenericTagType = PropertyTypeMatchesGenericTagType(tagType, tagNamespace, ns, propName.OwnerName); if (ownerTypeMatchesGenericTagType) { property = GetInstanceOrAttachableProperty(tagType, propName.Name, rootTagType); if (property != null) { return(property); } } } // Non-generic case, just resolve using the namespace and name XamlTypeName ownerTypeName = new XamlTypeName(ns, propName.Owner.Name); ownerType = GetXamlType(ownerTypeName, true); bool canAssignTagTypeToOwnerType = tagType.CanAssignTo(ownerType); if (canAssignTagTypeToOwnerType) { property = GetInstanceOrAttachableProperty(ownerType, propName.Name, rootTagType); } else { property = GetXamlAttachableProperty(ownerType, propName.Name); } if (property == null) { // This is an unknown property. // We don't know for sure whether or not it's attachable, so we go with our best guess. // If the owner type is same as the generic tag type, or is assignable to the tag type, // it's probably not attachable. XamlType declaringType = ownerTypeMatchesGenericTagType ? tagType : ownerType; if (ownerTypeMatchesGenericTagType || canAssignTagTypeToOwnerType) { property = CreateUnknownMember(declaringType, propName.Name); } else { property = CreateUnknownAttachableMember(declaringType, propName.Name); } } return(property); }