public override XamlType GetXamlType(Type type) { XamlType xamlType = null; if (this.customXamlTypes != null && this.customXamlTypes.TryGetValue(type, out xamlType)) { return(xamlType); } bool isCustom = false; xamlType = GetCustomType(type); if (xamlType != null) { isCustom = true; } else { xamlType = base.GetXamlType(type); if (xamlType.GetXamlNamespaces().Any(ns => IsClrNamespaceInLocalAssembly(ns))) { isCustom = true; xamlType = new XamlTypeWithExplicitNamespace(xamlType, xamlType.GetXamlNamespaces().Select(ns => IsClrNamespaceInLocalAssembly(ns) ? TrimLocalAssembly(ns) : ns)); } } if (isCustom) { if (this.customXamlTypes == null) { this.customXamlTypes = new Dictionary <Type, XamlType>(); } this.customXamlTypes[type] = xamlType; } return(xamlType); }
protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments) { XamlType xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); if (xamlType == null || xamlType.IsUnknown) { xamlNamespace = XamlBuildTaskServices.UpdateClrNamespaceUriWithLocalAssembly(xamlNamespace, this.localAssemblyName, this.realAssemblyName); xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); } else if (!xamlType.UnderlyingType.Assembly.ReflectionOnly && xamlType.UnderlyingType.Assembly != typeof(object).Assembly) { // Types from XamlLanguage are live; but we want the ROL equivalent, so that we can validate // against expected member types. We do this by looking it up via its clr-namespace form. // Note this means that the resulting XamlType will only have its clr-namespace, not the XAML2006 namespace. IList <string> namespaces = xamlType.GetXamlNamespaces(); Fx.Assert(namespaces.Contains(XamlLanguage.Xaml2006Namespace) && xamlType.TypeArguments == null, "This should only happen for XamlLanguage types, none of which are generic"); string clrNamespace = namespaces[namespaces.Count - 1]; XamlType rolType = base.GetXamlType(clrNamespace, xamlType.UnderlyingType.Name); if (rolType != null) { xamlType = rolType; } } return(xamlType); }
private bool PropertyTypeMatchesGenericTagType(XamlType tagType, string tagNs, string propNs, string propTypeName) { if (((tagNs != propNs) && (tagType.Name != propTypeName)) && !tagType.GetXamlNamespaces().Contains(propNs)) { return(false); } XamlType type = this.GetXamlType(propNs, propTypeName, tagType.TypeArguments); return(tagType == type); }
private string LookupPrefix(XamlType type) { string str; string prefix = this.xamlXmlWriter.LookupPrefix(type.GetXamlNamespaces(), out str); if ((prefix == null) && !this.meSettings.ContinueWritingWhenPrefixIsNotFound) { this.failed = true; return string.Empty; } return prefix; }
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); }
string LookupPrefix(XamlType type) { string prefix = xamlXmlWriter.LookupPrefix(type.GetXamlNamespaces(), out _); if (prefix == null) { if (!meSettings.ContinueWritingWhenPrefixIsNotFound) { // the prefix is not found and curly syntax has no way of defining a prefix failed = true; return(string.Empty); // what we return here is not important, since Failed has set to be true } } return(prefix); }
public XamlTypeName(XamlType xamlType) { if (xamlType == null) { throw new ArgumentNullException("xamlType"); } this.Name = xamlType.Name; this.Namespace = xamlType.GetXamlNamespaces()[0]; if (xamlType.TypeArguments != null) { foreach (XamlType argumentType in xamlType.TypeArguments) { TypeArguments.Add(new XamlTypeName(argumentType)); } } }
public XamlTypeName(XamlType xamlType) { if (xamlType == null) { throw new ArgumentNullException("xamlType"); } this.Name = xamlType.Name; this.Namespace = xamlType.GetXamlNamespaces()[0]; if (xamlType.TypeArguments != null) { foreach (XamlType type in xamlType.TypeArguments) { this.TypeArguments.Add(new XamlTypeName(type)); } } }
private bool PropertyTypeMatchesGenericTagType(XamlType tagType, string tagNs, string propNs, string propTypeName) { // Schema can potentially remap names and namespaces from what is requested in GetXamlType. // However, a failed GetXamlType call is expensive, we don't want to do one unnecessarily. // So we try to match the property type to the generic type if: // - The xml namespaces are an exact match // - The type names are an exact match // - The property is in any of the same namespaces as the tag type if (tagNs != propNs && tagType.Name != propTypeName && !tagType.GetXamlNamespaces().Contains(propNs)) { return(false); } XamlType propertyType = GetXamlType(propNs, propTypeName, tagType.TypeArguments); return(tagType == propertyType); }
public void GetXamlNamespaces() { var xt = new XamlType(typeof(string), new XamlSchemaContext(null, null)); var l = xt.GetXamlNamespaces().ToList(); l.Sort(); Assert.AreEqual(2, l.Count, "#1-1"); Assert.AreEqual("clr-namespace:System;assembly=mscorlib", l [0], "#1-2"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [1], "#1-3"); xt = new XamlType(typeof(TypeExtension), new XamlSchemaContext(null, null)); l = xt.GetXamlNamespaces().ToList(); l.Sort(); Assert.AreEqual(3, l.Count, "#2-1"); Assert.AreEqual("clr-namespace:System.Windows.Markup;assembly=System.Xaml", l [0], "#2-2"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [1], "#2-3"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [2], "#2-4"); // ?? }
public void GetXamlNamespaces() { var xt = new XamlType(typeof(string), new XamlSchemaContext(null, null)); var l = xt.GetXamlNamespaces().ToList(); l.Sort(); Assert.AreEqual(2, l.Count, "#1-1"); Assert.AreEqual("clr-namespace:System;assembly=mscorlib", l [0], "#1-2"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [1], "#1-3"); xt = new XamlType(typeof(TypeExtension), new XamlSchemaContext(null, null)); l = xt.GetXamlNamespaces().ToList(); l.Sort(); Assert.AreEqual(3, l.Count, "#2-1"); Assert.AreEqual("clr-namespace:Portable.Xaml.Markup;assembly=Portable.Xaml".Fixup(), l [0], "#2-2"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [1], "#2-3"); Assert.AreEqual(XamlLanguage.Xaml2006Namespace, l [2], "#2-4"); // ?? xt = new XamlType(typeof(List <string>), new XamlSchemaContext(null, null)); l = xt.GetXamlNamespaces().ToList(); l.Sort(); Assert.AreEqual(1, l.Count, "#3-1"); Assert.AreEqual("clr-namespace:System.Collections.Generic;assembly=mscorlib", l [0], "#3-2"); }
public void GetXamlNamespaces () { var xt = new XamlType (typeof (string), new XamlSchemaContext (null, null)); var l = xt.GetXamlNamespaces (); Assert.AreEqual (2, l.Count, "#1"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [0], "#2"); Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", l [1], "#3"); }
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)); }
public void GetXamlNamespaces () { var xt = new XamlType (typeof (string), new XamlSchemaContext (null, null)); var l = xt.GetXamlNamespaces ().ToList (); l.Sort (); Assert.AreEqual (2, l.Count, "#1-1"); Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", l [0], "#1-2"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [1], "#1-3"); xt = new XamlType (typeof (TypeExtension), new XamlSchemaContext (null, null)); l = xt.GetXamlNamespaces ().ToList (); l.Sort (); Assert.AreEqual (3, l.Count, "#2-1"); Assert.AreEqual ("clr-namespace:System.Windows.Markup;assembly=System.Xaml", l [0], "#2-2"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [1], "#2-3"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [2], "#2-4"); // ?? }
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); }
private bool PropertyTypeMatchesGenericTagType(XamlType tagType, string tagNs, string propNs, string propTypeName) { if (((tagNs != propNs) && (tagType.Name != propTypeName)) && !tagType.GetXamlNamespaces().Contains(propNs)) { return false; } XamlType type = this.GetXamlType(propNs, propTypeName, tagType.TypeArguments); return (tagType == type); }
bool IsXClassName(XamlType xamlType) { if (xamlType == null || this.xClassName == null || xamlType.Name != this.xClassName.Name) { return false; } // this code is kept for back compatible string preferredNamespace = xamlType.PreferredXamlNamespace; if (preferredNamespace.Contains(clrNamespacePart)) { return IsXClassName(preferredNamespace); } // GetXamlNamespaces is a superset of PreferredXamlNamespace, it's not a must for the above code // to check for preferredXamlNamespace, but since the old code uses .Contains(), which was a minor IList<string> namespaces = xamlType.GetXamlNamespaces(); foreach (string ns in namespaces) { if (ns.StartsWith(clrNamespacePart, StringComparison.Ordinal)) { return IsXClassName(ns); } } return false; }
private void WriteObject(XamlType xamlType, bool isFromMember) { Indent(); if (isFromMember) { _out.Write("GO"); } else { _out.Write("SO "); } SimpleWriterFrame frame; if (_stack.CurrentIndex == 0 || _stack.Peek().NodeType == XamlNodeType.StartObject || _stack.Peek().NodeType == XamlNodeType.GetObject) { frame = new SimpleWriterFrame(); _stack.Push(frame); } else { frame = _stack.Peek(); } frame.Type = xamlType; if (xamlType == null) { if (isFromMember) { frame.NodeType = XamlNodeType.GetObject; } else { _out.Write(_nullString); } } else { // Figure out prefix frame.NodeType = XamlNodeType.StartObject; var xmlNamespaces = xamlType.GetXamlNamespaces(); var prefix = _stack.FindPrefixFromXmlnsList(xmlNamespaces); _stack.Peek().TypePrefix = prefix; switch (prefix) { case null: var nullStr = isFromMember ? _nullObjectFromMember : _nullString; _out.Write(nullStr + ":"); break; case "": break; default: _out.Write("{0}:", prefix); break; } if (xamlType.TypeArguments != null) { _out.Write("{0}({1})", xamlType.Name, Join(xamlType.TypeArguments, PrintType, ", ")); } else { _out.Write("{0}", xamlType.Name); } } if (!isFromMember && xamlType.IsUnknown) { _out.Write(" [{0}]", UnknownText); } _out.WriteLine(" {0}", LineInfoString); ++_depth; if (_wrappedWriter != null) { if (isFromMember) { _wrappedWriter.WriteGetObject(); } else { _wrappedWriter.WriteStartObject(xamlType); } } }
private string Logic_GetFullyQualifiedNameForType(XamlType type) { Baml2006ReaderFrame currentFrame = _context.CurrentFrame; IList<string> xamlNamespaces = type.GetXamlNamespaces(); while (currentFrame != null) { foreach(string xmlns in xamlNamespaces) { string prefix = null; if (currentFrame.TryGetPrefixByNamespace(xmlns, out prefix)) { if (String.IsNullOrEmpty(prefix)) { return type.Name; } else { return prefix + ":" + type.Name; } } } currentFrame = (Baml2006ReaderFrame)currentFrame.Previous; } throw new InvalidOperationException("Could not find prefix for type: " + type.Name); }
public void GetXamlNamespaces () { var xt = new XamlType (typeof (string), new XamlSchemaContext (null, null)); var l = xt.GetXamlNamespaces ().ToList (); l.Sort (); Assert.AreEqual (2, l.Count, "#1-1"); Assert.AreEqual ("clr-namespace:System;assembly=mscorlib", l [0], "#1-2"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [1], "#1-3"); xt = new XamlType (typeof (TypeExtension), new XamlSchemaContext (null, null)); l = xt.GetXamlNamespaces ().ToList (); l.Sort (); Assert.AreEqual (3, l.Count, "#2-1"); Assert.AreEqual ("clr-namespace:Portable.Xaml.Markup;assembly=Portable.Xaml".Fixup(), l [0], "#2-2"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [1], "#2-3"); Assert.AreEqual (XamlLanguage.Xaml2006Namespace, l [2], "#2-4"); // ?? xt = new XamlType (typeof (List<string>), new XamlSchemaContext (null, null)); l = xt.GetXamlNamespaces ().ToList (); l.Sort (); Assert.AreEqual (1, l.Count, "#3-1"); Assert.AreEqual ("clr-namespace:System.Collections.Generic;assembly=mscorlib", l [0], "#3-2"); }