[XamlC] comp binding to generic properties (#4483)

- fixes #4438
This commit is contained in:
Stephane Delcroix 2018-11-21 08:32:09 +01:00 коммит произвёл GitHub
Родитель e38776cdec
Коммит 3b6374893b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 76 добавлений и 1 удалений

Просмотреть файл

@ -392,7 +392,11 @@ namespace Xamarin.Forms.Build.Tasks
yield break; //throw
var properties = ParsePath(path, tSourceRef, node as IXmlLineInfo, module);
var tPropertyRef = properties != null && properties.Any() ? properties.Last().Item1.PropertyType : tSourceRef;
TypeReference tPropertyRef = tSourceRef;
if (properties != null && properties.Count > 0) {
var lastProp = properties[properties.Count - 1];
tPropertyRef = lastProp.property.ResolveGenericPropertyType(lastProp.propDeclTypeRef, module);
}
tPropertyRef = module.ImportReference(tPropertyRef);
var funcRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));

Просмотреть файл

@ -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.Gh4438"
x:DataType="local:Gh4438VM">
<Label x:Name="label" Text="{Binding SelectedItem}" />
</ContentPage>

Просмотреть файл

@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
public class Gh4438VM : Gh4438VMBase<string>
{
public Gh4438VM()
{
Add("test");
SelectedItem = this.First();
}
}
public class Gh4438VMBase<T> : Collection<string>
{
public virtual T SelectedItem { get; set; }
}
public partial class Gh4438 : ContentPage
{
public Gh4438()
{
InitializeComponent();
}
public Gh4438(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 GenericBaseClassResolution(bool useCompiledXaml)
{
if (useCompiledXaml)
Assert.DoesNotThrow(() => MockCompiler.Compile(typeof(Gh4438)));
var layout = new Gh4438(useCompiledXaml) { BindingContext = new Gh4438VM() };
Assert.That(layout.label.Text, Is.EqualTo("test"));
}
}
}
}