[XamlC] resolve generic types with generic and non-generic parameters (#1533)
fixes #1497
This commit is contained in:
Родитель
3490f61c65
Коммит
0618c35de2
|
@ -326,8 +326,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return self;
|
||||
|
||||
List<TypeReference> args = new List<TypeReference>();
|
||||
for (var i = 0; i < genericself.GenericArguments.Count; i++)
|
||||
args.Add(genericdeclType.GenericArguments[(genericself.GenericArguments[i] as GenericParameter).Position]);
|
||||
for (var i = 0; i < genericself.GenericArguments.Count; i++) {
|
||||
if (!genericself.GenericArguments[i].IsGenericParameter)
|
||||
args.Add(genericself.GenericArguments[i]);
|
||||
else
|
||||
args.Add(genericdeclType.GenericArguments[(genericself.GenericArguments[i] as GenericParameter).Position]);
|
||||
}
|
||||
return self.GetElementType().MakeGenericInstanceType(args.ToArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?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="clr-namespace:Xamarin.Forms.Xaml.UnitTests"
|
||||
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh1497">
|
||||
<Entry x:Name="entry">
|
||||
<Entry.Behaviors>
|
||||
<local:Gh1497EntryValidationBehavior x:TypeArguments="Entry"/>
|
||||
</Entry.Behaviors>
|
||||
</Entry>
|
||||
</ContentPage>
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.Forms.Core.UnitTests;
|
||||
|
||||
namespace Xamarin.Forms.Xaml.UnitTests
|
||||
{
|
||||
abstract class Gh1497BaseValidationBehavior<TBindable, TModel> : Behavior<TBindable> where TBindable : BindableObject
|
||||
{
|
||||
}
|
||||
|
||||
sealed class Gh1497EntryValidationBehavior<TModel> : Gh1497BaseValidationBehavior<Entry, TModel>
|
||||
{
|
||||
}
|
||||
|
||||
public partial class Gh1497 : ContentPage
|
||||
{
|
||||
public Gh1497()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public Gh1497(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 GenericsIssue(bool useCompiledXaml)
|
||||
{
|
||||
var layout = new Gh1497(useCompiledXaml);
|
||||
Assert.That(layout.entry.Behaviors[0], Is.TypeOf(typeof(Gh1497EntryValidationBehavior<Entry>)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -564,6 +564,9 @@
|
|||
<Compile Include="InlineCSS.xaml.cs">
|
||||
<DependentUpon>InlineCSS.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Issues\Gh1497.xaml.cs">
|
||||
<DependentUpon>Gh1497.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
|
||||
|
@ -1004,6 +1007,9 @@
|
|||
<EmbeddedResource Include="Issues\Gh1346.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Issues\Gh1497.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
|
|
|
@ -27,6 +27,14 @@ namespace Xamarin.Forms.Xaml.XamlcUnitTests
|
|||
{
|
||||
}
|
||||
|
||||
class Baz<T1, T2> : Foo<T1>
|
||||
{
|
||||
}
|
||||
|
||||
class Qux<T> : Baz<int, T>
|
||||
{
|
||||
}
|
||||
|
||||
ModuleDefinition module;
|
||||
|
||||
[SetUp]
|
||||
|
@ -96,6 +104,7 @@ namespace Xamarin.Forms.Xaml.XamlcUnitTests
|
|||
[TestCase(typeof(Foo<string>), typeof(Foo), ExpectedResult = true)]
|
||||
[TestCase(typeof(Bar<string>), typeof(Foo), ExpectedResult = true)]
|
||||
[TestCase(typeof(Bar<string>), typeof(Foo<string>), ExpectedResult = true)]
|
||||
[TestCase(typeof(Qux<string>), typeof(double), ExpectedResult = false)] //https://github.com/xamarin/Xamarin.Forms/issues/1497
|
||||
public bool TestInheritsFromOrImplements(Type typeRef, Type baseClass)
|
||||
{
|
||||
return TypeReferenceExtensions.InheritsFromOrImplements(module.ImportReference(typeRef), module.ImportReference(baseClass));
|
||||
|
|
Загрузка…
Ссылка в новой задаче