This repository has been archived by the owner on May 1, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a missing TypeConverter attribute to Size struct. - fixes #3280
- Loading branch information
1 parent
5577429
commit 91a6990
Showing
6 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace Xamarin.Forms | ||
{ | ||
[Xaml.TypeConversion(typeof(Size))] | ||
public class SizeTypeConverter : TypeConverter | ||
{ | ||
public override object ConvertFromInvariantString(string value) | ||
{ | ||
if (value != null) { | ||
string[] wh = value.Split(','); | ||
if (wh.Length == 2 | ||
&& double.TryParse(wh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out double w) | ||
&& double.TryParse(wh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out double h)) | ||
return new Size(w, h); | ||
} | ||
|
||
throw new InvalidOperationException(string.Format("Cannot convert \"{0}\" into {1}", value, typeof(Size))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?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.Gh3280" Foo="15,25"> | ||
</ContentPage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
using Xamarin.Forms; | ||
using Xamarin.Forms.Core.UnitTests; | ||
|
||
namespace Xamarin.Forms.Xaml.UnitTests | ||
{ | ||
public partial class Gh3280 : ContentPage | ||
{ | ||
public Gh3280() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public Size Foo { get; set; } | ||
|
||
public Gh3280(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(false), TestCase(true)] | ||
public void SizeHasConverter(bool useCompiledXaml) | ||
{ | ||
Gh3280 layout = null; | ||
Assert.DoesNotThrow(() => layout = new Gh3280(useCompiledXaml)); | ||
Assert.That(layout.Foo, Is.EqualTo(new Size(15, 25))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters