summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs8
-rw-r--r--Xamarin.Forms.Build.Tasks/XamlGTask.cs8
-rw-r--r--Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs66
-rw-r--r--Xamarin.Forms.Core/Properties/AssemblyInfo.cs4
-rw-r--r--Xamarin.Forms.Core/Xamarin.Forms.Core.csproj3
-rw-r--r--Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs25
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs2
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs10
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs7
-rw-r--r--Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs11
-rw-r--r--Xamarin.Forms.Xaml/TypeArgumentsParser.cs18
-rw-r--r--Xamarin.Forms.Xaml/XamlParser.cs64
-rw-r--r--Xamarin.Forms.Xaml/XamlServiceProvider.cs2
-rw-r--r--Xamarin.Forms.Xaml/XmlnsHelper.cs13
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/XmlnsDefinitionAttribute.xml92
-rw-r--r--docs/Xamarin.Forms.Core/index.xml4
-rw-r--r--docs/Xamarin.Forms.Xaml/index.xml21
17 files changed, 279 insertions, 79 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
index 6d6405e1..4e1372c5 100644
--- a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
@@ -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")))
diff --git a/Xamarin.Forms.Build.Tasks/XamlGTask.cs b/Xamarin.Forms.Build.Tasks/XamlGTask.cs
index ada6bb68..85a400a8 100644
--- a/Xamarin.Forms.Build.Tasks/XamlGTask.cs
+++ b/Xamarin.Forms.Build.Tasks/XamlGTask.cs
@@ -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";
diff --git a/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs b/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
index db182847..185c2722 100644
--- a/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
@@ -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();
}
diff --git a/Xamarin.Forms.Core/Properties/AssemblyInfo.cs b/Xamarin.Forms.Core/Properties/AssemblyInfo.cs
index 49bc4e67..6bbdb600 100644
--- a/Xamarin.Forms.Core/Properties/AssemblyInfo.cs
+++ b/Xamarin.Forms.Core/Properties/AssemblyInfo.cs
@@ -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
diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
index c2833641..a6540c1b 100644
--- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
+++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
@@ -444,6 +444,7 @@
<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>
@@ -458,4 +459,4 @@
</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
index 00000000..2d6b0758
--- /dev/null
+++ b/Xamarin.Forms.Core/XmlnsDefinitionAttribute.cs
@@ -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
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs
index f6083fb1..8fb1759a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Issue1637.cs
@@ -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>
diff --git a/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs b/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs
index f132b19c..4d3e004a 100644
--- a/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/LoaderTests.cs
@@ -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"" />
diff --git a/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs b/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs
index 49c4bb49..0eec655c 100644
--- a/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/TypeExtensionTests.cs
@@ -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 ());
diff --git a/Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs b/Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs
index 58c48d26..d6b8ae9c 100644
--- a/Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs
+++ b/Xamarin.Forms.Xaml/Properties/AssemblyInfo.cs
@@ -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
diff --git a/Xamarin.Forms.Xaml/TypeArgumentsParser.cs b/Xamarin.Forms.Xaml/TypeArgumentsParser.cs
index 59b2dd0a..525b4d74 100644
--- a/Xamarin.Forms.Xaml/TypeArgumentsParser.cs
+++ b/Xamarin.Forms.Xaml/TypeArgumentsParser.cs
@@ -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
diff --git a/Xamarin.Forms.Xaml/XamlParser.cs b/Xamarin.Forms.Xaml/XamlParser.cs
index f2ac3197..9e841b9f 100644
--- a/Xamarin.Forms.Xaml/XamlParser.cs
+++ b/Xamarin.Forms.Xaml/XamlParser.cs
@@ -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;
diff --git a/Xamarin.Forms.Xaml/XamlServiceProvider.cs b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
index 5599cbbc..19dd96f5 100644
--- a/Xamarin.Forms.Xaml/XamlServiceProvider.cs
+++ b/Xamarin.Forms.Xaml/XamlServiceProvider.cs
@@ -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);
diff --git a/Xamarin.Forms.Xaml/XmlnsHelper.cs b/Xamarin.Forms.Xaml/XmlnsHelper.cs
index e3e37de4..e29dbc0c 100644
--- a/Xamarin.Forms.Xaml/XmlnsHelper.cs
+++ b/Xamarin.Forms.Xaml/XmlnsHelper.cs
@@ -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
index 00000000..2c20764b
--- /dev/null
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/XmlnsDefinitionAttribute.xml
@@ -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>
diff --git a/docs/Xamarin.Forms.Core/index.xml b/docs/Xamarin.Forms.Core/index.xml
index f13fd562..7d6b9079 100644
--- a/docs/Xamarin.Forms.Core/index.xml
+++ b/docs/Xamarin.Forms.Core/index.xml
@@ -143,6 +143,9 @@
<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>
@@ -438,6 +441,7 @@
<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" />
diff --git a/docs/Xamarin.Forms.Xaml/index.xml b/docs/Xamarin.Forms.Xaml/index.xml
index 7f8a955b..6121f09b 100644
--- a/docs/Xamarin.Forms.Xaml/index.xml
+++ b/docs/Xamarin.Forms.Xaml/index.xml
@@ -50,6 +50,27 @@
<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>