[X] wrap typeconverter exceptions in XPE (#5388)

- fixes #5378
This commit is contained in:
Stephane Delcroix 2019-02-26 20:07:17 +01:00 коммит произвёл GitHub
Родитель f30d5aec00
Коммит a6c08d577e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 89 добавлений и 2 удалений

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

@ -114,8 +114,14 @@ namespace Xamarin.Forms.Xaml
var xfExtendedTypeConverter = xfTypeConverter as IExtendedTypeConverter;
if (xfExtendedTypeConverter != null)
return value = xfExtendedTypeConverter.ConvertFromInvariantString(str, serviceProvider);
if (xfTypeConverter != null)
return value = xfTypeConverter.ConvertFromInvariantString(str);
if (xfTypeConverter != null) {
try {
return value = xfTypeConverter.ConvertFromInvariantString(str);
}
catch (Exception e) {
throw new XamlParseException("Type conversion failed", serviceProvider, e);
}
}
var converterType = converter?.GetType();
if (converterType != null)
{

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

@ -0,0 +1,7 @@
<?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.Gh5378_1">
<Label Margin="1,2,3," />
</ContentPage>

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

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Gh5378_1 : ContentPage
{
public Gh5378_1() => InitializeComponent();
public Gh5378_1(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 ReportSyntaxError([Values(false, true)]bool useCompiledXaml)
{
if (useCompiledXaml)
Assert.Throws<XamlParseException>(() => MockCompiler.Compile(typeof(Gh5378_1)));
else
Assert.Throws<XamlParseException>(() => new Gh5378_1(useCompiledXaml));
}
}
}
}

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

@ -0,0 +1,4 @@
<?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.Gh5378_2">
<Button Clicked="{Binding FooBar}" />
</ContentPage>

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

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using Xamarin.Forms;
using Xamarin.Forms.Core.UnitTests;
namespace Xamarin.Forms.Xaml.UnitTests
{
[XamlCompilation(XamlCompilationOptions.Skip)]
public partial class Gh5378_2 : ContentPage
{
public Gh5378_2()
{
InitializeComponent();
}
public Gh5378_2(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 ReportSyntaxError([Values(false, true)]bool useCompiledXaml)
{
if (useCompiledXaml)
Assert.Throws<XamlParseException>(() => MockCompiler.Compile(typeof(Gh5378_2)));
else
Assert.Throws<XamlParseException>(() => new Gh5378_2(useCompiledXaml));
}
}
}
}