diff --git a/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs index e91ac1e0d..4a55e0546 100644 --- a/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs +++ b/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs @@ -26,7 +26,7 @@ namespace Xamarin.Forms.Build.Tasks md.IsStatic && md.IsPublic && md.Parameters.Count == 1 && - md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).SingleOrDefault()?.Item1; + md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).FirstOrDefault()?.Item1; if (getter == null) throw new BuildException(BuildExceptionCode.BPName, iXmlLineInfo, null, bpName, bpRef.DeclaringType); @@ -43,7 +43,7 @@ namespace Xamarin.Forms.Build.Tasks md.IsStatic && md.IsPublic && md.Parameters.Count == 1 && - md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).SingleOrDefault()?.Item1; + md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).FirstOrDefault()?.Item1; var attributes = new List(); if (property != null && property.HasCustomAttributes) diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml new file mode 100644 index 000000000..47ea3b2a0 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml @@ -0,0 +1,8 @@ + + + diff --git a/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml.cs new file mode 100644 index 000000000..c5bc67959 --- /dev/null +++ b/Xamarin.Forms.Xaml.UnitTests/Issues/Gh12025.xaml.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Xamarin.Forms; +using Xamarin.Forms.Core.UnitTests; + +namespace Xamarin.Forms.Xaml.UnitTests +{ + public class Gh12025NavPage : NavigationPage + { + public static new readonly BindableProperty IconColorProperty = BindableProperty.CreateAttached("IconColor", typeof(Color), typeof(Page), Color.Default); + public static void SetIconColor(Page page, Color barTintColor) => page.SetValue(IconColorProperty, barTintColor); + public static Color GetIconColor(Page page) => (Color)page.GetValue(IconColorProperty); + } + + public partial class Gh12025 : ContentPage + { + public Gh12025() => InitializeComponent(); + public Gh12025(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; + + [Test] + public void FindMostDerivedABP([Values(false, true)] bool useCompiledXaml) + { + if (useCompiledXaml) + Assert.DoesNotThrow(() => MockCompiler.Compile(typeof(Gh12025))); + var layout = new Gh12025(useCompiledXaml); + Assert.That(NavigationPage.GetIconColor(layout), Is.EqualTo(NavigationPage.IconColorProperty.DefaultValue)); + Assert.That(Gh12025NavPage.GetIconColor(layout), Is.EqualTo(Color.HotPink)); + } + } + } +} \ No newline at end of file