[Xaml] cleanup xmlns usage, add XmlnsDefinition (#531)
authorStephane Delcroix <stephane@delcroix.org>
Thu, 17 Nov 2016 19:31:05 +0000 (20:31 +0100)
committerGitHub <noreply@github.com>
Thu, 17 Nov 2016 19:31:05 +0000 (20:31 +0100)
* [Xaml] cleanup xmlns usage, add XmlnsDefinition

* docs

17 files changed:
Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
Xamarin.Forms.Build.Tasks/XamlGTask.cs
Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
Xamarin.Forms.Core/Properties/AssemblyInfo.cs
Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs [new file with mode: 0644]
Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs
Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs
Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs
Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs
Xamarin.Forms.Xaml/TypeArgumentsParser.cs
Xamarin.Forms.Xaml/XamlParser.cs
Xamarin.Forms.Xaml/XamlServiceProvider.cs
Xamarin.Forms.Xaml/XmlnsHelper.cs
docs/Xamarin.Forms.Core/Xamarin.Forms/XmlnsDefinitionAttribute.xml [new file with mode: 0644]
docs/Xamarin.Forms.Core/index.xml
docs/Xamarin.Forms.Xaml/index.xml

index 6d6405e..4e1372c 100644 (file)
@@ -194,8 +194,12 @@ namespace Xamarin.Forms.Build.Tasks
                                                ntype = node.CollectionItems [0];
 
                                        var type = ((ValueNode)ntype).Value as string;
-                                       var namespaceuri = type.Contains(":") ? node.NamespaceResolver.LookupNamespace(type.Split(':') [0].Trim()) : "";
-                                       type = type.Contains(":") ? type.Split(':') [1].Trim() : type;
+                                       var prefix = "";
+                                       if (type.Contains(":")) {
+                                               prefix = type.Split(':') [0].Trim();
+                                               type = type.Split(':') [1].Trim();
+                                       }
+                                       var namespaceuri = node.NamespaceResolver.LookupNamespace(prefix);
                                        Context.TypeExtensions [node] = new XmlType(namespaceuri, type, null).GetTypeReference(Module, node);
 
                                        if (!node.SkipProperties.Contains(new XmlName("", "TypeName")))
index ada6bb6..85a400a 100644 (file)
@@ -235,14 +235,14 @@ namespace Xamarin.Forms.Build.Tasks
                        {
                                foreach (var typeArg in typeArguments)
                                {
-                                       var ns_uri = "";
+                                       var prefix = "";
                                        var _type = typeArg;
                                        if (typeArg.Contains(":"))
                                        {
-                                               var prefix = typeArg.Split(':')[0].Trim();
-                                               ns_uri = getNamespaceOfPrefix(prefix);
+                                               prefix = typeArg.Split(':')[0].Trim();
                                                _type = typeArg.Split(':')[1].Trim();
                                        }
+                                       var ns_uri = getNamespaceOfPrefix(prefix);
                                        returnType.TypeArguments.Add(GetType(ns_uri, _type, null, getNamespaceOfPrefix));
                                }
                        }
@@ -252,7 +252,7 @@ namespace Xamarin.Forms.Build.Tasks
 
                static string GetNamespace(string namespaceuri)
                {
-                       if (!XmlnsHelper.IsCustom(namespaceuri))
+                       if (namespaceuri == "http://xamarin.com/schemas/2014/forms")
                                return "Xamarin.Forms";
                        if (namespaceuri == "http://schemas.microsoft.com/winfx/2009/xaml")
                                return "System";
index db18284..185c272 100644 (file)
@@ -1,4 +1,3 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Xml;
@@ -15,29 +14,45 @@ namespace Xamarin.Forms.Build.Tasks
                        return new XmlType (namespaceURI, typename, null).GetTypeReference (module, xmlInfo);
                }
 
+               static IList<XmlnsDefinitionAttribute> s_xmlnsDefinitions;
+
+               static void GatherXmlnsDefinitionAttributes()
+               {
+                       //this could be extended to look for [XmlnsDefinition] in all assemblies
+                       var assemblies = new [] {
+                               typeof(View).Assembly,
+                               typeof(XamlLoader).Assembly,
+                       };
+
+                       s_xmlnsDefinitions = new List<XmlnsDefinitionAttribute>();
+
+                       foreach (var assembly in assemblies)
+                               foreach (XmlnsDefinitionAttribute attribute in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false)) {
+                                       s_xmlnsDefinitions.Add(attribute);
+                                       attribute.AssemblyName = attribute.AssemblyName ?? assembly.FullName;
+                               }
+               }
+
                public static TypeReference GetTypeReference(this XmlType xmlType, ModuleDefinition module, IXmlLineInfo xmlInfo)
                {
+                       if (s_xmlnsDefinitions == null)
+                               GatherXmlnsDefinitionAttributes();
+
                        var namespaceURI = xmlType.NamespaceUri;
                        var elementName = xmlType.Name;
                        var typeArguments = xmlType.TypeArguments;
 
-                       List<Tuple<string, string>> lookupAssemblies = new List<Tuple<string, string>>(); //assembly, namespace
-                       List<string> lookupNames = new List<string>();
+                       var lookupAssemblies = new List<XmlnsDefinitionAttribute>();
 
-                       if (!XmlnsHelper.IsCustom(namespaceURI))
-                       {
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms.Core", "Xamarin.Forms"));
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml"));
-                       }
-                       else if (namespaceURI == "http://schemas.microsoft.com/winfx/2009/xaml" ||
-                                namespaceURI == "http://schemas.microsoft.com/winfx/2006/xaml")
-                       {
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml"));
-                               lookupAssemblies.Add(new Tuple<string, string>("mscorlib", "System"));
-                               lookupAssemblies.Add(new Tuple<string, string>("System", "System"));
+                       var lookupNames = new List<string>();
+
+                       foreach (var xmlnsDef in s_xmlnsDefinitions) {
+                               if (xmlnsDef.XmlNamespace != namespaceURI)
+                                       continue;
+                               lookupAssemblies.Add(xmlnsDef);
                        }
-                       else
-                       {
+
+                       if (lookupAssemblies.Count == 0) {
                                string ns;
                                string typename;
                                string asmstring;
@@ -45,12 +60,14 @@ namespace Xamarin.Forms.Build.Tasks
 
                                XmlnsHelper.ParseXmlns(namespaceURI, out typename, out ns, out asmstring, out targetPlatform);
                                asmstring = asmstring ?? module.Assembly.Name.Name;
-                               lookupAssemblies.Add(new Tuple<string, string>(asmstring, ns));
+                               lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns) {
+                                       AssemblyName = asmstring
+                               });
                        }
 
                        lookupNames.Add(elementName);
-                       if (namespaceURI == "http://schemas.microsoft.com/winfx/2009/xaml")
-                               lookupNames.Add(elementName + "Extension");
+                       lookupNames.Add(elementName + "Extension");
+
                        for (var i = 0; i < lookupNames.Count; i++)
                        {
                                var name = lookupNames[i];
@@ -71,15 +88,16 @@ namespace Xamarin.Forms.Build.Tasks
                                        if (type != null)
                                                break;
 
-                                       var assemblydefinition = module.Assembly.Name.Name == asm.Item1
-                                               ? module.Assembly
-                                               : module.AssemblyResolver.Resolve(asm.Item1);
-                                       type = assemblydefinition.MainModule.GetType(asm.Item2, name);
+                                       var assemblydefinition = module.Assembly.Name.Name == asm.AssemblyName ?
+                                                                                               module.Assembly :
+                                                                                               module.AssemblyResolver.Resolve(asm.AssemblyName);
+
+                                       type = assemblydefinition.MainModule.GetType(asm.ClrNamespace, name);
                                        if (type == null)
                                        {
                                                var exportedtype =
                                                        assemblydefinition.MainModule.ExportedTypes.FirstOrDefault(
-                                                               (ExportedType arg) => arg.IsForwarder && arg.Namespace == asm.Item2 && arg.Name == name);
+                                                               (ExportedType arg) => arg.IsForwarder && arg.Namespace == asm.ClrNamespace && arg.Name == name);
                                                if (exportedtype != null)
                                                        type = exportedtype.Resolve();
                                        }
index 49bc4e6..6bbdb60 100644 (file)
@@ -56,4 +56,6 @@ using Xamarin.Forms.Internals;
 [assembly: InternalsVisibleTo("Xamarin.Forms.Pages")]
 [assembly: InternalsVisibleTo("Xamarin.Forms.Pages.UnitTests")]
 [assembly: InternalsVisibleTo("Xamarin.Forms.CarouselView")]
-[assembly: Preserve]
\ No newline at end of file
+[assembly: Preserve]
+
+[assembly: XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms")]
\ No newline at end of file
index c283364..a6540c1 100644 (file)
     <Compile Include="INativeBindingService.cs" />
     <Compile Include="ProvideCompiledAttribute.cs" />
     <Compile Include="TypedBinding.cs" />
+    <Compile Include="XmlnsDefinitionAttribute.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
   <ItemGroup>
     </PostBuildEvent>
   </PropertyGroup>
   <ItemGroup />
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs b/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs
new file mode 100644 (file)
index 0000000..2d6b075
--- /dev/null
@@ -0,0 +1,25 @@
+using System;
+using System.Reflection;
+using System.Diagnostics;
+namespace Xamarin.Forms
+{
+       [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
+       [DebuggerDisplay("{XmlNamespace}, {ClrNamespace}, {AssemblyName}")]
+       public sealed class XmlnsDefinitionAttribute : Attribute
+       {
+               public string XmlNamespace { get; }
+               public string ClrNamespace { get; }
+               public string AssemblyName { get; set; }
+
+               public XmlnsDefinitionAttribute(string xmlNamespace, string clrNamespace)
+               {
+                       if (xmlNamespace == null)
+                               throw new ArgumentNullException(nameof(xmlNamespace));
+                       if (clrNamespace == null)
+                               throw new ArgumentNullException(nameof(clrNamespace));
+
+                       ClrNamespace = clrNamespace;
+                       XmlNamespace = xmlNamespace;
+               }
+       }
+}
\ No newline at end of file
index f6083fb..8fb1759 100644 (file)
@@ -10,7 +10,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
                public void ImplicitCollectionWithSingleElement ()
                {
                        var xaml = @"
-                               <Grid>
+                               <Grid xmlns=""http://xamarin.com/schemas/2014/forms"">
                                        <Grid.RowDefinitions>
                                                <RowDefinition Height=""*"" />
                                </Grid.RowDefinitions>
index f132b19..4d3e004 100644 (file)
@@ -381,9 +381,9 @@ namespace Xamarin.Forms.Xaml.UnitTests
                [Test]
                public void MissingStaticResourceShouldThrow ()
                {
-                       var xaml = @"<Label Text=""{StaticResource foo}""/>";
+                       var xaml = @"<Label xmlns=""http://xamarin.com/schemas/2014/forms"" Text=""{StaticResource foo}""/>";
                        var label = new Label ();
-                       Assert.Throws (new XamlParseExceptionConstraint (1, 8), () => label.LoadFromXaml (xaml));
+                       Assert.Throws (new XamlParseExceptionConstraint (1, 54), () => label.LoadFromXaml (xaml));
                }
 
                public class CustView : Button
@@ -605,7 +605,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
                public void TestCollectionContentProperties ()
                {
                        var xaml = @"
-                               <StackLayout>
+                               <StackLayout xmlns=""http://xamarin.com/schemas/2014/forms"">
                                        <Label Text=""Foo""/>
                                        <Label Text=""Bar""/>
                                </StackLayout>";
@@ -619,7 +619,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
                public void TestCollectionContentPropertiesWithSingleElement ()
                {
                        var xaml = @"
-                               <StackLayout>
+                               <StackLayout xmlns=""http://xamarin.com/schemas/2014/forms"">
                                        <Label Text=""Foo""/>
                                </StackLayout>";
                        var layout = new StackLayout ().LoadFromXaml (xaml);
@@ -796,7 +796,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
                public void StyleWithoutTargetTypeThrows ()
                {
                        var xaml = @"
-                               <Label>
+                               <Label xmlns=""http://xamarin.com/schemas/2014/forms"">
                                        <Label.Style>
                                                <Style>
                                                        <Setter Property=""Text"" Value=""Foo"" />
index 49c4bb4..0eec655 100644 (file)
@@ -19,9 +19,10 @@ namespace Xamarin.Forms.Xaml.UnitTests
                {
                        base.Setup ();
                        var nsManager = new XmlNamespaceManager (new NameTable ());
-                       nsManager.AddNamespace ("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests");
-                       nsManager.AddNamespace ("sys", "clr-namespace:System;assembly=mscorlib");
-                       nsManager.AddNamespace ("x", "http://schemas.microsoft.com/winfx/2006/xaml");
+                       nsManager.AddNamespace("", "http://xamarin.com/schemas/2014/forms");
+                       nsManager.AddNamespace("local", "clr-namespace:Xamarin.Forms.Xaml.UnitTests;assembly=Xamarin.Forms.Xaml.UnitTests");
+                       nsManager.AddNamespace("sys", "clr-namespace:System;assembly=mscorlib");
+                       nsManager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
 
                        typeResolver = new Internals.XamlTypeResolver (nsManager, XamlParser.GetElementType, Assembly.GetCallingAssembly ());
 
index 58c48d2..d6b8ae9 100644 (file)
@@ -1,5 +1,6 @@
 using System.Reflection;
 using System.Runtime.CompilerServices;
+using Xamarin.Forms;
 using Xamarin.Forms.Internals;
 
 // Information about this assembly is defined by the following attributes.
@@ -23,4 +24,12 @@ using Xamarin.Forms.Internals;
 [assembly: InternalsVisibleTo("Xamarin.Forms.Xaml.UnitTests")]
 [assembly: InternalsVisibleTo("Xamarin.Forms.Build.Tasks")]
 [assembly: InternalsVisibleTo("Xamarin.Forms.Xaml.Design")]
-[assembly: Preserve]
\ No newline at end of file
+[assembly: Preserve]
+
+[assembly: XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms.Xaml")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "Xamarin.Forms.Xaml")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System", AssemblyName = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System", AssemblyName = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "Xamarin.Forms.Xaml")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "System", AssemblyName = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
+[assembly: XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "System", AssemblyName = "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
\ No newline at end of file
index 59b2dd0..525b4d7 100644 (file)
@@ -47,8 +47,22 @@ namespace Xamarin.Forms.Xaml
                                        type.Substring(type.IndexOf('(') + 1, type.LastIndexOf(')') - type.IndexOf('(') - 1), resolver, lineinfo);
                                type = type.Substring(0, type.IndexOf('('));
                        }
-                       var namespaceuri = type.Contains(":") ? resolver.LookupNamespace(type.Split(':')[0].Trim()) : "";
-                       return new XmlType(namespaceuri, type, typeArguments);
+
+                       var split = type.Split(':');
+                       if (split.Length > 2)
+                               return null;
+
+                       string prefix, name;
+                       if (split.Length == 2) {
+                               prefix = split [0];
+                               name = split [1];
+                       } else {
+                               prefix = "";
+                               name = split [0];
+                       }
+
+                       var namespaceuri = resolver.LookupNamespace(prefix);
+                       return new XmlType(namespaceuri, name, typeArguments);
                }
        }
 }
\ No newline at end of file
index f2ac319..9e841b9 100644 (file)
@@ -34,7 +34,7 @@ using System.Xml;
 
 namespace Xamarin.Forms.Xaml
 {
-       internal static class XamlParser
+       static class XamlParser
        {
                public static void ParseXaml(RootNode rootNode, XmlReader reader)
                {
@@ -83,16 +83,16 @@ namespace Xamarin.Forms.Xaml
                                                        var prop = ReadNode(reader);
                                                        if (prop != null)
                                                                node.Properties.Add(XmlName.xArguments, prop);
-                                                       // 3. DataTemplate (should be handled by 4.)
                                                }
+                                               // 3. DataTemplate (should be handled by 4.)
                                                else if (node.XmlType.NamespaceUri == "http://xamarin.com/schemas/2014/forms" &&
                                                         (node.XmlType.Name == "DataTemplate" || node.XmlType.Name == "ControlTemplate"))
                                                {
                                                        var prop = ReadNode(reader, true);
                                                        if (prop != null)
                                                                node.Properties.Add(XmlName._CreateContent, prop);
-                                                       // 4. Implicit content, implicit collection, or collection syntax. Add to CollectionItems, resolve case later.
                                                }
+                                               // 4. Implicit content, implicit collection, or collection syntax. Add to CollectionItems, resolve case later.
                                                else
                                                {
                                                        var item = ReadNode(reader, true);
@@ -191,7 +191,10 @@ namespace Xamarin.Forms.Xaml
                                        continue;
                                }
 
-                               var propertyName = new XmlName(reader.NamespaceURI, reader.LocalName);
+                               var namespaceUri = reader.NamespaceURI;
+                               if (reader.LocalName.Contains(".") && namespaceUri == "")
+                                       namespaceUri = ((IXmlNamespaceResolver)reader).LookupNamespace("");
+                               var propertyName = new XmlName(namespaceUri, reader.LocalName);
 
                                object value = reader.Value;
 
@@ -283,39 +286,56 @@ namespace Xamarin.Forms.Xaml
                                ((IXmlLineInfo)reader).LinePosition);
                }
 
+               static IList<XmlnsDefinitionAttribute> s_xmlnsDefinitions;
+
+               static void GatherXmlnsDefinitionAttributes()
+               {
+                       //this could be extended to look for [XmlnsDefinition] in all assemblies
+                       var assemblies = new [] {
+                               typeof(View).GetTypeInfo().Assembly,
+                               typeof(XamlLoader).GetTypeInfo().Assembly,
+                       };
+
+                       s_xmlnsDefinitions = new List<XmlnsDefinitionAttribute>();
+
+                       foreach (var assembly in assemblies)
+                               foreach (XmlnsDefinitionAttribute attribute in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute))) {
+                                       s_xmlnsDefinitions.Add(attribute);
+                                       attribute.AssemblyName = attribute.AssemblyName ?? assembly.FullName;
+                               }
+               }
+
                public static Type GetElementType(XmlType xmlType, IXmlLineInfo xmlInfo, Assembly currentAssembly,
                        out XamlParseException exception)
                {
+                       if (s_xmlnsDefinitions == null)
+                               GatherXmlnsDefinitionAttributes();
+
                        var namespaceURI = xmlType.NamespaceUri;
                        var elementName = xmlType.Name;
                        var typeArguments = xmlType.TypeArguments;
                        exception = null;
 
-                       var lookupAssemblies = new List<Tuple<string, string>>(); //namespace, assemblyqualifiednamed
+                       var lookupAssemblies = new List<XmlnsDefinitionAttribute>();
                        var lookupNames = new List<string>();
 
-                       if (!XmlnsHelper.IsCustom(namespaceURI))
-                       {
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms", typeof (View).GetTypeInfo().Assembly.FullName));
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms.Xaml", typeof (XamlLoader).GetTypeInfo().Assembly.FullName));
-                       }
-                       else if (namespaceURI == "http://schemas.microsoft.com/winfx/2009/xaml" ||
-                                namespaceURI == "http://schemas.microsoft.com/winfx/2006/xaml")
-                       {
-                               lookupAssemblies.Add(new Tuple<string, string>("Xamarin.Forms.Xaml", typeof (XamlLoader).GetTypeInfo().Assembly.FullName));
-                               lookupAssemblies.Add(new Tuple<string, string>("System", typeof (object).GetTypeInfo().Assembly.FullName)); //mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-                               lookupAssemblies.Add(new Tuple<string, string>("System", typeof (Uri).GetTypeInfo().Assembly.FullName)); //System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+                       foreach (var xmlnsDef in s_xmlnsDefinitions) {
+                               if (xmlnsDef.XmlNamespace != namespaceURI)
+                                       continue;
+                               lookupAssemblies.Add(xmlnsDef);
                        }
-                       else
-                       {
+
+                       if (lookupAssemblies.Count == 0) {
                                string ns, asmstring, _;
                                XmlnsHelper.ParseXmlns(namespaceURI, out _, out ns, out asmstring, out _);
-                               lookupAssemblies.Add(new Tuple<string, string>(ns, asmstring ?? currentAssembly.FullName));
+                               lookupAssemblies.Add(new XmlnsDefinitionAttribute(namespaceURI, ns) {
+                                       AssemblyName = asmstring ?? currentAssembly.FullName
+                               });
                        }
 
                        lookupNames.Add(elementName);
-                       if (namespaceURI == "http://schemas.microsoft.com/winfx/2009/xaml")
-                               lookupNames.Add(elementName + "Extension");
+                       lookupNames.Add(elementName + "Extension");
+
                        for (var i = 0; i < lookupNames.Count; i++)
                        {
                                var name = lookupNames[i];
@@ -329,7 +349,7 @@ namespace Xamarin.Forms.Xaml
                        Type type = null;
                        foreach (var asm in lookupAssemblies) {
                                foreach (var name in lookupNames)
-                                       if ((type = Type.GetType($"{asm.Item1}.{name}, {asm.Item2}")) != null)
+                                       if ((type = Type.GetType($"{asm.ClrNamespace}.{name}, {asm.AssemblyName}")) != null)
                                                break;
                                if (type != null)
                                        break;
index 5599cbb..19dd96f 100644 (file)
@@ -231,7 +231,7 @@ namespace Xamarin.Forms.Xaml.Internals
                                        xmlLineInfo = lineInfoProvider.XmlLineInfo;
                        }
 
-                       var namespaceuri = prefix == null ? "" : namespaceResolver.LookupNamespace(prefix);
+                       var namespaceuri = namespaceResolver.LookupNamespace(prefix);
                        if (namespaceuri == null)
                        {
                                exception = new XamlParseException(string.Format("No xmlns declaration for prefix \"{0}\"", prefix), xmlLineInfo);
index e3e37de..e29dbc0 100644 (file)
@@ -2,19 +2,8 @@ using System;
 
 namespace Xamarin.Forms.Xaml
 {
-       internal static class XmlnsHelper
+       static class XmlnsHelper
        {
-               public static bool IsCustom(string ns)
-               {
-                       switch (ns)
-                       {
-                               case "":
-                               case "http://xamarin.com/schemas/2014/forms":
-                                       return false;
-                       }
-                       return true;
-               }
-
                public static string ParseNamespaceFromXmlns(string xmlns)
                {
                        string typeName;
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/XmlnsDefinitionAttribute.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/XmlnsDefinitionAttribute.xml
new file mode 100644 (file)
index 0000000..2c20764
--- /dev/null
@@ -0,0 +1,92 @@
+<Type Name="XmlnsDefinitionAttribute" FullName="Xamarin.Forms.XmlnsDefinitionAttribute">
+  <TypeSignature Language="C#" Value="public sealed class XmlnsDefinitionAttribute : Attribute" />
+  <TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit XmlnsDefinitionAttribute extends System.Attribute" />
+  <AssemblyInfo>
+    <AssemblyName>Xamarin.Forms.Core</AssemblyName>
+    <AssemblyVersion>2.0.0.0</AssemblyVersion>
+  </AssemblyInfo>
+  <Base>
+    <BaseTypeName>System.Attribute</BaseTypeName>
+  </Base>
+  <Interfaces />
+  <Attributes>
+    <Attribute>
+      <AttributeName>System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true)</AttributeName>
+    </Attribute>
+    <Attribute>
+      <AttributeName>System.Diagnostics.DebuggerDisplay("{XmlNamespace}, {ClrNamespace}, {AssemblyName}")</AttributeName>
+    </Attribute>
+  </Attributes>
+  <Docs>
+    <summary>To be added.</summary>
+    <remarks>To be added.</remarks>
+  </Docs>
+  <Members>
+    <Member MemberName=".ctor">
+      <MemberSignature Language="C#" Value="public XmlnsDefinitionAttribute (string xmlNamespace, string clrNamespace);" />
+      <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string xmlNamespace, string clrNamespace) cil managed" />
+      <MemberType>Constructor</MemberType>
+      <AssemblyInfo>
+        <AssemblyVersion>2.0.0.0</AssemblyVersion>
+      </AssemblyInfo>
+      <Parameters>
+        <Parameter Name="xmlNamespace" Type="System.String" />
+        <Parameter Name="clrNamespace" Type="System.String" />
+      </Parameters>
+      <Docs>
+        <param name="xmlNamespace">To be added.</param>
+        <param name="clrNamespace">To be added.</param>
+        <summary>To be added.</summary>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="AssemblyName">
+      <MemberSignature Language="C#" Value="public string AssemblyName { get; set; }" />
+      <MemberSignature Language="ILAsm" Value=".property instance string AssemblyName" />
+      <MemberType>Property</MemberType>
+      <AssemblyInfo>
+        <AssemblyVersion>2.0.0.0</AssemblyVersion>
+      </AssemblyInfo>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="ClrNamespace">
+      <MemberSignature Language="C#" Value="public string ClrNamespace { get; }" />
+      <MemberSignature Language="ILAsm" Value=".property instance string ClrNamespace" />
+      <MemberType>Property</MemberType>
+      <AssemblyInfo>
+        <AssemblyVersion>2.0.0.0</AssemblyVersion>
+      </AssemblyInfo>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+    <Member MemberName="XmlNamespace">
+      <MemberSignature Language="C#" Value="public string XmlNamespace { get; }" />
+      <MemberSignature Language="ILAsm" Value=".property instance string XmlNamespace" />
+      <MemberType>Property</MemberType>
+      <AssemblyInfo>
+        <AssemblyVersion>2.0.0.0</AssemblyVersion>
+      </AssemblyInfo>
+      <ReturnValue>
+        <ReturnType>System.String</ReturnType>
+      </ReturnValue>
+      <Docs>
+        <summary>To be added.</summary>
+        <value>To be added.</value>
+        <remarks>To be added.</remarks>
+      </Docs>
+    </Member>
+  </Members>
+</Type>
index f13fd56..7d6b907 100644 (file)
         <Attribute>
           <AttributeName>Xamarin.Forms.Internals.Preserve</AttributeName>
         </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms")</AttributeName>
+        </Attribute>
       </Attributes>
     </Assembly>
   </Assemblies>
       <Type Name="WebView" Kind="Class" />
       <Type Name="WebViewSource" Kind="Class" />
       <Type Name="WebViewSourceTypeConverter" Kind="Class" />
+      <Type Name="XmlnsDefinitionAttribute" Kind="Class" />
     </Namespace>
     <Namespace Name="Xamarin.Forms.Internals">
       <Type Name="CellExtensions" Kind="Class" />
index 7f8a955..6121f09 100644 (file)
         <Attribute>
           <AttributeName>Xamarin.Forms.Internals.Preserve</AttributeName>
         </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://xamarin.com/schemas/2014/forms", "Xamarin.Forms.Xaml")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "Xamarin.Forms.Xaml")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System", AssemblyName="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System", AssemblyName="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "Xamarin.Forms.Xaml")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "System", AssemblyName="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")</AttributeName>
+        </Attribute>
+        <Attribute>
+          <AttributeName>Xamarin.Forms.XmlnsDefinition("http://schemas.microsoft.com/winfx/2009/xaml", "System", AssemblyName="System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")</AttributeName>
+        </Attribute>
       </Attributes>
     </Assembly>
   </Assemblies>