[XamlC] better error reporting on missing Add()er (#1982)

- fixes #1978
This commit is contained in:
Stephane Delcroix 2018-02-27 19:39:48 +01:00 коммит произвёл Rui Marinho
Родитель d32e6eefba
Коммит 056f66e2dd
4 изменённых файлов: 57 добавлений и 1 удалений

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

@ -184,7 +184,9 @@ namespace Xamarin.Forms.Build.Tasks
Context.IL.Append(AddToResourceDictionary(node, node, Context));
return;
}
var adderTuple = propertyType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).First();
var adderTuple = propertyType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).FirstOrDefault();
if (adderTuple == null)
throw new XamlParseException($"Can not Add() elements to {parent.VariableType}.{localname}", node);
var adderRef = Module.ImportReference(adderTuple.Item1);
adderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));

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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Xaml.UnitTests.Gh1978">
<ContentPage.ToolbarItems>
<ToolbarItem>
<ToolbarItem.Text>
<!--Forgot the OnPlatform tag-->
<On Platform="Android,iOS" Value="+" />
<On Platform="UWP" Value="Add" />
</ToolbarItem.Text>
</ToolbarItem>
</ContentPage.ToolbarItems>
</ContentPage>

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

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
namespace Xamarin.Forms.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Gh1978 : ContentPage
{
public Gh1978()
{
InitializeComponent();
}
public Gh1978(bool useCompiledXaml)
{
//this stub will be replaced at compile time
}
[TestFixture]
class Tests
{
[TestCase(true)]
public void ReportError(bool useCompiledXaml)
{
if (!useCompiledXaml)
return;
Assert.Throws<XamlParseException>(() => MockCompiler.Compile(typeof(Gh1978)));
}
}
}
}

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

@ -576,6 +576,9 @@
<Compile Include="Issues\Gh1766.xaml.cs">
<DependentUpon>Gh1766.xaml</DependentUpon>
</Compile>
<Compile Include="Issues\Gh1978.xaml.cs">
<DependentUpon>Gh1978.xaml</DependentUpon>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\.nuspec\Xamarin.Forms.Debug.targets" />
@ -1029,6 +1032,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="Issues\Gh1978.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />