[XamlC] use TypeRefComparer to compare TypeRef from different assemblies (#710)
authorStephane Delcroix <stephane@delcroix.org>
Wed, 25 Jan 2017 16:03:30 +0000 (17:03 +0100)
committerStephane Delcroix <stephane@delcroix.org>
Wed, 25 Jan 2017 16:04:10 +0000 (17:04 +0100)
Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
Xamarin.Forms.Xaml.UnitTests/XStatic.xaml
Xamarin.Forms.Xaml.UnitTests/XStatic.xaml.cs

index 464eeac..b7386a8 100644 (file)
@@ -40,25 +40,25 @@ namespace Xamarin.Forms.Build.Tasks
                                        return new [] { Instruction.Create(OpCodes.Ldsfld, fieldRef) };
 
                                //Constants can be numbers, Boolean values, strings, or a null reference. (https://msdn.microsoft.com/en-us/library/e6w8fe1b.aspx)
-                               if (memberRef == module.TypeSystem.Boolean)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Boolean))
                                        return new [] { Instruction.Create(((bool)fieldDef.Constant) ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0) };
-                               if (memberRef == module.TypeSystem.String)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.String))
                                        return new [] { Instruction.Create(OpCodes.Ldstr, (string)fieldDef.Constant) };
                                if (fieldDef.Constant == null)
                                        return new [] { Instruction.Create(OpCodes.Ldnull) };
-                               if (memberRef == module.TypeSystem.Char)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Char))
                                        return new [] { Instruction.Create(OpCodes.Ldc_I4, (char)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.Single)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Single))
                                        return new [] { Instruction.Create(OpCodes.Ldc_R4, (float)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.Double)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Double))
                                        return new [] { Instruction.Create(OpCodes.Ldc_R8, (double)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.Byte || memberRef == module.TypeSystem.Int16 || memberRef == module.TypeSystem.Int32)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Byte) || TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Int16) || TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Int32))
                                        return new [] { Instruction.Create(OpCodes.Ldc_I4, (int)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.SByte || memberRef == module.TypeSystem.UInt16 || memberRef == module.TypeSystem.UInt32)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.SByte) || TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.UInt16) || TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.UInt32))
                                        return new [] { Instruction.Create(OpCodes.Ldc_I4, (uint)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.Int64)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.Int64))
                                        return new [] { Instruction.Create(OpCodes.Ldc_I8, (long)fieldDef.Constant) };
-                               if (memberRef == module.TypeSystem.UInt64)
+                               if (TypeRefComparer.Default.Equals(memberRef, module.TypeSystem.UInt64))
                                        return new [] { Instruction.Create(OpCodes.Ldc_I8, (ulong)fieldDef.Constant) };
 
                                //enum values
index cf68525..2627ae3 100644 (file)
@@ -2,6 +2,7 @@
 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                         xmlns:local="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
+                        xmlns:remote="clr-namespace:Xamarin.Forms.Controls;assembly=Xamarin.Forms.Controls"
                         x:Class="Xamarin.Forms.Xaml.UnitTests.XStatic">
        <ContentPage.ToolbarItems>
                <ToolbarItem Icon="{x:Static local:MockxStatic.MockFieldRef}" />
@@ -15,6 +16,8 @@
                           TextColor="{x:Static local:MockxStatic.BackgroundColor}" />
                <Label x:Name="constant"
                                Text="{x:Static local:MockxStatic.MockConstant}"/>
+               <Label x:Name="remoteConstant"
+                               Text="{x:Static remote:App.AppName}"/>
                <Label x:Name="field"
                                Text="{x:Static local:MockxStatic.MockField}"/>
                <ScrollView x:Name="enuM"
index 19c6263..63854e1 100644 (file)
@@ -96,6 +96,15 @@ namespace Xamarin.Forms.Xaml.UnitTests
 
                        [TestCase(false)]
                        [TestCase(true)]
+                       //https://bugzilla.xamarin.com/show_bug.cgi?id=49228
+                       public void ConstantInARemoteAssembly(bool useCompiledXaml)
+                       {
+                               var layout = new XStatic(useCompiledXaml);
+                               Assert.AreEqual("XamarinFormsControls", layout.remoteConstant.Text);
+                       }
+
+                       [TestCase(false)]
+                       [TestCase(true)]
                        public void Field(bool useCompiledXaml)
                        {
                                var layout = new XStatic(useCompiledXaml);