diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2017-04-06 23:22:50 +0200 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2017-04-06 22:22:50 +0100 |
commit | ab0fabac610b5c24c086c1cbf5e88b1d48511f2a (patch) | |
tree | c5715dc2432c434e8474d178f50ec398031c331e | |
parent | 0ee636003b6d1083ea4caeed85ef3efbc815ed06 (diff) | |
download | xamarin-forms-ab0fabac610b5c24c086c1cbf5e88b1d48511f2a.tar.gz xamarin-forms-ab0fabac610b5c24c086c1cbf5e88b1d48511f2a.tar.bz2 xamarin-forms-ab0fabac610b5c24c086c1cbf5e88b1d48511f2a.zip |
[Xaml[C]] supports 'using:' xmlns declarations (#851)
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml | 9 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml.cs | 47 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj | 6 | ||||
-rw-r--r-- | Xamarin.Forms.Xaml/XmlnsHelper.cs | 25 |
4 files changed, 87 insertions, 0 deletions
diff --git a/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml b/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml new file mode 100644 index 00000000..f48dfdf2 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" + xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" + xmlns:local="using:Xamarin.Forms.Xaml.UnitTests" + x:Class="Xamarin.Forms.Xaml.UnitTests.TestXmlnsUsing"> + <ContentPage.Content> + <local:CustomXamlView /> + </ContentPage.Content> +</ContentPage> diff --git a/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml.cs new file mode 100644 index 00000000..15eb0ff5 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/TestXmlnsUsing.xaml.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public partial class TestXmlnsUsing : ContentPage + { + public TestXmlnsUsing() + { + InitializeComponent(); + } + + public TestXmlnsUsing(bool useCompiledXaml) + { + //this stub will be replaced at compile time + } + + [TestFixture] + class Tests + { + [SetUp] + public void Setup() + { + Device.PlatformServices = new MockPlatformServices(); + } + + [TearDown] + public void TearDown() + { + Application.Current = null; + Device.PlatformServices = null; + } + + [TestCase(true)] + [TestCase(false)] + public void SupportUsingXmlns(bool useCompiledXaml) + { + var page = new TestXmlnsUsing(useCompiledXaml); + Assert.That(page.Content, Is.Not.Null); + Assert.That(page.Content, Is.TypeOf<CustomXamlView>()); + } + } + } +} diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj index 7041001c..24d2bbde 100644 --- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj +++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj @@ -461,6 +461,9 @@ <Compile Include="Issues\Bz53203.xaml.cs"> <DependentUpon>Bz53203.xaml</DependentUpon> </Compile> + <Compile Include="TestXmlnsUsing.xaml.cs"> + <DependentUpon>TestXmlnsUsing.xaml</DependentUpon> + </Compile> <Compile Include="Issues\Bz54334.xaml.cs"> <DependentUpon>Bz54334.xaml</DependentUpon> </Compile> @@ -848,6 +851,9 @@ <EmbeddedResource Include="Issues\Bz53203.xaml"> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> + <EmbeddedResource Include="TestXmlnsUsing.xaml"> + <Generator>MSBuild:UpdateDesignTimeXaml</Generator> + </EmbeddedResource> <EmbeddedResource Include="Issues\Bz54334.xaml"> <Generator>MSBuild:UpdateDesignTimeXaml</Generator> </EmbeddedResource> diff --git a/Xamarin.Forms.Xaml/XmlnsHelper.cs b/Xamarin.Forms.Xaml/XmlnsHelper.cs index e29dbc0c..5f7efd48 100644 --- a/Xamarin.Forms.Xaml/XmlnsHelper.cs +++ b/Xamarin.Forms.Xaml/XmlnsHelper.cs @@ -20,6 +20,19 @@ namespace Xamarin.Forms.Xaml { typeName = ns = asm = targetPlatform = null; + xmlns = xmlns.Trim(); + + if (xmlns.StartsWith("using:", StringComparison.Ordinal)) { + ParseUsing(xmlns, out typeName, out ns, out asm, out targetPlatform); + return; + } + ParseClrNamespace(xmlns, out typeName, out ns, out asm, out targetPlatform); + } + + static void ParseClrNamespace(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform) + { + typeName = ns = asm = targetPlatform = null; + foreach (var decl in xmlns.Split(';')) { if (decl.StartsWith("clr-namespace:", StringComparison.Ordinal)) @@ -46,5 +59,17 @@ namespace Xamarin.Forms.Xaml typeName = decl; } } + + static void ParseUsing(string xmlns, out string typeName, out string ns, out string asm, out string targetPlatform) + { + typeName = ns = asm = targetPlatform = null; + + foreach (var decl in xmlns.Split(';')) { + if (decl.StartsWith("using:", StringComparison.Ordinal)) { + ns = decl.Substring(6, decl.Length - 6); + continue; + } + } + } } }
\ No newline at end of file |