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 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));
         }
     }
 }
Example #3
0
		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"); // ??
		}
Example #4
0
        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);
        } 
Example #5
0
		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");
		}
 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);
 }
 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);
 }
        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;
        }
Example #9
0
		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");
		}