Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit cdbb9ee

Browse files
[X] Find most derived ABP (#12085)
- fixes #12025
1 parent 7c2cc59 commit cdbb9ee

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static TypeReference GetBindablePropertyType(this FieldReference bpRef, I
2626
md.IsStatic &&
2727
md.IsPublic &&
2828
md.Parameters.Count == 1 &&
29-
md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).SingleOrDefault()?.Item1;
29+
md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).FirstOrDefault()?.Item1;
3030
if (getter == null)
3131
throw new BuildException(BuildExceptionCode.BPName, iXmlLineInfo, null, bpName, bpRef.DeclaringType);
3232

@@ -43,7 +43,7 @@ public static TypeReference GetBindablePropertyTypeConverter(this FieldReference
4343
md.IsStatic &&
4444
md.IsPublic &&
4545
md.Parameters.Count == 1 &&
46-
md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).SingleOrDefault()?.Item1;
46+
md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))), module).FirstOrDefault()?.Item1;
4747

4848
var attributes = new List<CustomAttribute>();
4949
if (property != null && property.HasCustomAttributes)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
5+
xmlns:local="using:Xamarin.Forms.Xaml.UnitTests"
6+
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh12025"
7+
local:Gh12025NavPage.IconColor="HotPink">
8+
</ContentPage>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using NUnit.Framework;
4+
using Xamarin.Forms;
5+
using Xamarin.Forms.Core.UnitTests;
6+
7+
namespace Xamarin.Forms.Xaml.UnitTests
8+
{
9+
public class Gh12025NavPage : NavigationPage
10+
{
11+
public static new readonly BindableProperty IconColorProperty = BindableProperty.CreateAttached("IconColor", typeof(Color), typeof(Page), Color.Default);
12+
public static void SetIconColor(Page page, Color barTintColor) => page.SetValue(IconColorProperty, barTintColor);
13+
public static Color GetIconColor(Page page) => (Color)page.GetValue(IconColorProperty);
14+
}
15+
16+
public partial class Gh12025 : ContentPage
17+
{
18+
public Gh12025() => InitializeComponent();
19+
public Gh12025(bool useCompiledXaml)
20+
{
21+
//this stub will be replaced at compile time
22+
}
23+
24+
[TestFixture]
25+
class Tests
26+
{
27+
[SetUp] public void Setup() => Device.PlatformServices = new MockPlatformServices();
28+
[TearDown] public void TearDown() => Device.PlatformServices = null;
29+
30+
[Test]
31+
public void FindMostDerivedABP([Values(false, true)] bool useCompiledXaml)
32+
{
33+
if (useCompiledXaml)
34+
Assert.DoesNotThrow(() => MockCompiler.Compile(typeof(Gh12025)));
35+
var layout = new Gh12025(useCompiledXaml);
36+
Assert.That(NavigationPage.GetIconColor(layout), Is.EqualTo(NavigationPage.IconColorProperty.DefaultValue));
37+
Assert.That(Gh12025NavPage.GetIconColor(layout), Is.EqualTo(Color.HotPink));
38+
}
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)