From: Stephane Delcroix Date: Tue, 25 Apr 2017 18:06:29 +0000 (+0200) Subject: [Xaml] OnPlatform.Default value (#873) X-Git-Tag: accepted/tizen/4.0/unified/20170816.011313~260 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83da90f1e89a98207fb9d88699f863d41983374b;p=platform%2Fupstream%2Fxamarin-forms.git [Xaml] OnPlatform.Default value (#873) * [Xaml] OnPlatform.Default value * docs --- diff --git a/Xamarin.Forms.Core/OnPlatform.cs b/Xamarin.Forms.Core/OnPlatform.cs index 6862113..c179dc5 100644 --- a/Xamarin.Forms.Core/OnPlatform.cs +++ b/Xamarin.Forms.Core/OnPlatform.cs @@ -43,9 +43,21 @@ namespace Xamarin.Forms } } + bool hasDefault; + T @default; + public T Default { + get { return @default; } + set { + hasDefault = true; + @default = value; + } + } + public IList Platforms { get; private set; } +#pragma warning disable RECS0108 // Warns about static fields in generic types static readonly IValueConverterProvider s_valueConverter = DependencyService.Get(); +#pragma warning restore RECS0108 // Warns about static fields in generic types public static implicit operator T(OnPlatform onPlatform) { @@ -60,7 +72,7 @@ namespace Xamarin.Forms } if (!onPlatform.useLegacyFallback) - return default(T); + return onPlatform.hasDefault ? onPlatform.@default : default(T); //legacy fallback #pragma warning disable 0618, 0612 diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml index de9a1e6..5c3cd3d 100644 --- a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml +++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml @@ -37,7 +37,7 @@ - + 21 42 diff --git a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs index edfb695..23ebe92 100644 --- a/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs +++ b/Xamarin.Forms.Xaml.UnitTests/OnPlatform.xaml.cs @@ -121,7 +121,15 @@ namespace Xamarin.Forms.Xaml.UnitTests ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "FooBar"; layout = new OnPlatform(useCompiledXaml); Assert.AreEqual(42, layout.label0.HeightRequest); + } + [TestCase(false)] + [TestCase(true)] + public void OnPlatformDefault(bool useCompiledXaml) + { + ((MockPlatformServices)Device.PlatformServices).RuntimePlatform = "\ud83d\ude80"; + var layout = new OnPlatform(useCompiledXaml); + Assert.AreEqual(63, layout.label0.HeightRequest); } } } diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/OnPlatform`1.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/OnPlatform`1.xml index e703a91..4addd77 100644 --- a/docs/Xamarin.Forms.Core/Xamarin.Forms/OnPlatform`1.xml +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/OnPlatform`1.xml @@ -75,6 +75,22 @@ To be added. + + + + Property + + 2.0.0.0 + + + T + + + To be added. + To be added. + To be added. + +