summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Delcroix <stephane@delcroix.org>2016-12-23 07:50:02 (GMT)
committerGitHub <noreply@github.com>2016-12-23 07:50:02 (GMT)
commit2c91b0facd2a25d0de9a283b44cf818329d4c06f (patch)
treea1e659906258f2fc5c8c67d825a229ecf82db67b
parent0c87fcff41bef841f83ef62de5cdc3d821980d33 (diff)
downloadxamarin-forms-2c91b0facd2a25d0de9a283b44cf818329d4c06f.zip
xamarin-forms-2c91b0facd2a25d0de9a283b44cf818329d4c06f.tar.gz
xamarin-forms-2c91b0facd2a25d0de9a283b44cf818329d4c06f.tar.bz2
[XamlC] import members on x:Static and factories (#642)
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs6
-rw-r--r--Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs10
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/BuiltInConversions.xaml.cs32
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml23
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml.cs46
-rw-r--r--Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj6
8 files changed, 117 insertions, 14 deletions
diff --git a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
index 014fb82..464eeac 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
@@ -26,7 +26,7 @@ namespace Xamarin.Forms.Build.Tasks
var typename = member.Substring(0, dotIdx);
var membername = member.Substring(dotIdx + 1);
- var typeRef = GetTypeReference(typename, module, node);
+ var typeRef = module.Import(GetTypeReference(typename, module, node));
var fieldRef = GetFieldReference(typeRef, membername, module);
var propertyDef = GetPropertyDefinition(typeRef, membername, module);
@@ -75,7 +75,7 @@ namespace Xamarin.Forms.Build.Tasks
}
memberRef = propertyDef.PropertyType;
- var getterDef = propertyDef.GetMethod;
+ var getterDef = module.Import(propertyDef.GetMethod);
return new [] { Instruction.Create(OpCodes.Call, getterDef) };
}
diff --git a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
index ac53021..ff8f84f 100644
--- a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
@@ -48,7 +48,7 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ElementNode node, INode parentNode)
{
- var typeref = node.XmlType.GetTypeReference(Module, node);
+ var typeref = Module.Import(node.XmlType.GetTypeReference(Module, node));
TypeDefinition typedef = typeref.Resolve();
if (IsXaml2009LanguagePrimitive(node)) {
@@ -65,6 +65,7 @@ namespace Xamarin.Forms.Build.Tasks
var markupProvider = new StaticExtension();
var il = markupProvider.ProvideValue(node, Module, Context, out typeref);
+ typeref = Module.Import(typeref);
var vardef = new VariableDefinition(typeref);
Context.Variables [node] = vardef;
@@ -154,8 +155,7 @@ namespace Xamarin.Forms.Build.Tasks
Context.IL.Emit(OpCodes.Call, implicitOperator);
Context.IL.Emit(OpCodes.Stloc, vardef);
} else if (factorymethodinforef != null) {
- var factory = Module.Import(factorymethodinforef);
- Context.IL.Emit(OpCodes.Call, factory);
+ Context.IL.Emit(OpCodes.Call, Module.Import(factorymethodinforef));
Context.IL.Emit(OpCodes.Stloc, vardef);
} else if (!typedef.IsValueType) {
var ctor = Module.Import(ctorinforef);
diff --git a/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
index 13b4aaf..e3b2f3a 100644
--- a/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
@@ -13,9 +13,9 @@ namespace Xamarin.Forms.Build.Tasks
if (declaringTypeRef == null)
throw new ArgumentNullException(nameof(declaringTypeRef));
- var reference = new MethodReference(self.Name, self.ReturnType)
+ var reference = new MethodReference(self.Name, module.Import(self.ReturnType))
{
- DeclaringType = declaringTypeRef,
+ DeclaringType = module.Import(declaringTypeRef),
HasThis = self.HasThis,
ExplicitThis = self.ExplicitThis,
CallingConvention = self.CallingConvention
diff --git a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
index 9e1cc16..a347c2f 100644
--- a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
@@ -21,7 +21,15 @@ namespace Xamarin.Forms.Build.Tasks
public bool Equals(TypeReference x, TypeReference y)
{
- return GetAssembly(x) == GetAssembly(y) && x.FullName == y.FullName;
+ if (x.FullName != y.FullName)
+ return false;
+ var xasm = GetAssembly(x);
+ if (xasm.StartsWith("System.Runtime", StringComparison.Ordinal) || xasm.StartsWith("mscorlib", StringComparison.Ordinal))
+ xasm = "mscorlib";
+ var yasm = GetAssembly(y);
+ if (yasm.StartsWith("System.Runtime", StringComparison.Ordinal) || yasm.StartsWith("mscorlib", StringComparison.Ordinal))
+ yasm = "mscorlib";
+ return xasm == yasm;
}
public int GetHashCode(TypeReference obj)
diff --git a/Xamarin.Forms.Xaml.UnitTests/BuiltInConversions.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/BuiltInConversions.xaml.cs
index 20d4afd..2299928 100644
--- a/Xamarin.Forms.Xaml.UnitTests/BuiltInConversions.xaml.cs
+++ b/Xamarin.Forms.Xaml.UnitTests/BuiltInConversions.xaml.cs
@@ -1,6 +1,7 @@
´╗┐using System;
using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
@@ -11,22 +12,41 @@ namespace Xamarin.Forms.Xaml.UnitTests
InitializeComponent ();
}
+ public BuiltInConversions(bool useCompiledXaml)
+ {
+ //this stub will be replaced at compile time
+ }
+
[TestFixture]
public class Tests
{
- [Test]
- public void Datetime ()
+ [SetUp]
+ public void Setup()
+ {
+ Device.PlatformServices = new MockPlatformServices();
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(false)]
+ [TestCase(true)]
+ public void Datetime (bool useCompiledXaml)
{
- var layout = new BuiltInConversions ();
+ var layout = new BuiltInConversions (useCompiledXaml);
Assert.AreEqual (new DateTime (2015, 01, 16), layout.datetime0.Date);
Assert.AreEqual (new DateTime (2015, 01, 16), layout.datetime1.Date);
}
- [Test]
- public void String ()
+ [TestCase(false)]
+ [TestCase(true)]
+ public void String (bool useCompiledXaml)
{
- var layout = new BuiltInConversions ();
+ var layout = new BuiltInConversions (useCompiledXaml);
Assert.AreEqual ("foobar", layout.label0.Text);
Assert.AreEqual ("foobar", layout.label1.Text);
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml
new file mode 100644
index 0000000..77c2689
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml
@@ -0,0 +1,23 @@
+<?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:sys="clr-namespace:System;assembly=mscorlib"
+ x:Class="Xamarin.Forms.Xaml.UnitTests.Unreported008">
+ <DatePicker Date="{x:Static sys:DateTime.Now}" x:Name="picker0">
+ <DatePicker.Format>yyyy-MM-dd</DatePicker.Format>
+ <DatePicker.MinimumDate>
+ <sys:DateTime x:FactoryMethod="Parse">
+ <x:Arguments>
+ <x:String>Jan 1 2000</x:String>
+ </x:Arguments>
+ </sys:DateTime>
+ </DatePicker.MinimumDate>
+ <DatePicker.MaximumDate>
+ <sys:DateTime x:FactoryMethod="Parse">
+ <x:Arguments>
+ <x:String>Dec 31 2050</x:String>
+ </x:Arguments>
+ </sys:DateTime>
+ </DatePicker.MaximumDate>
+ </DatePicker>
+</ContentPage> \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml.cs
new file mode 100644
index 0000000..d5f84d4
--- /dev/null
+++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Unreported008.xaml.cs
@@ -0,0 +1,46 @@
+´╗┐using System;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UnitTests;
+
+namespace Xamarin.Forms.Xaml.UnitTests
+{
+ [XamlCompilation(XamlCompilationOptions.Skip)]
+ public partial class Unreported008 : ContentPage
+ {
+ public Unreported008()
+ {
+ InitializeComponent();
+ }
+
+ public Unreported008(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()
+ {
+ Device.PlatformServices = null;
+ }
+
+ [TestCase(true), TestCase(false)]
+ public void PickerDateTimesAndXamlC(bool useCompiledXaml)
+ {
+ var page = new Unreported008(useCompiledXaml);
+ var picker = page.picker0;
+ Assert.AreEqual(DateTime.Today, picker.Date.Date);
+ Assert.AreEqual(new DateTime(2000, 1, 1), picker.MinimumDate);
+ Assert.AreEqual(new DateTime(2050, 12, 31), picker.MaximumDate);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
index 4f14fd3..8864a38 100644
--- a/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
+++ b/Xamarin.Forms.Xaml.UnitTests/Xamarin.Forms.Xaml.UnitTests.csproj
@@ -406,6 +406,9 @@
<Compile Include="Issues\Bz49307.xaml.cs">
<DependentUpon>Bz49307.xaml</DependentUpon>
</Compile>
+ <Compile Include="Issues\Unreported008.xaml.cs">
+ <DependentUpon>Unreported008.xaml</DependentUpon>
+ </Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@@ -733,6 +736,9 @@
<EmbeddedResource Include="Issues\Bz49307.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
+ <EmbeddedResource Include="Issues\Unreported008.xaml">
+ <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
+ </EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />