[Xaml] OnPlatform.Default value (#873)
* [Xaml] OnPlatform.Default value * docs
This commit is contained in:
Родитель
8e567b9ad1
Коммит
9b49e3f1c1
|
@ -43,9 +43,21 @@ namespace Xamarin.Forms
|
|||
}
|
||||
}
|
||||
|
||||
bool hasDefault;
|
||||
T @default;
|
||||
public T Default {
|
||||
get { return @default; }
|
||||
set {
|
||||
hasDefault = true;
|
||||
@default = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IList<On> Platforms { get; private set; }
|
||||
|
||||
#pragma warning disable RECS0108 // Warns about static fields in generic types
|
||||
static readonly IValueConverterProvider s_valueConverter = DependencyService.Get<IValueConverterProvider>();
|
||||
#pragma warning restore RECS0108 // Warns about static fields in generic types
|
||||
|
||||
public static implicit operator T(OnPlatform<T> 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
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
</OnPlatform>
|
||||
</Label.Text>
|
||||
<Label.HeightRequest>
|
||||
<OnPlatform x:TypeArguments="x:Double">
|
||||
<OnPlatform x:TypeArguments="x:Double" Default="63">
|
||||
<On Platform="iOS">21</On>
|
||||
<On Platform="Android, FooBar">42</On>
|
||||
</OnPlatform>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,22 @@
|
|||
<remarks>To be added.</remarks>
|
||||
</Docs>
|
||||
</Member>
|
||||
<Member MemberName="Default">
|
||||
<MemberSignature Language="C#" Value="public T Default { get; set; }" />
|
||||
<MemberSignature Language="ILAsm" Value=".property instance !T Default" />
|
||||
<MemberType>Property</MemberType>
|
||||
<AssemblyInfo>
|
||||
<AssemblyVersion>2.0.0.0</AssemblyVersion>
|
||||
</AssemblyInfo>
|
||||
<ReturnValue>
|
||||
<ReturnType>T</ReturnType>
|
||||
</ReturnValue>
|
||||
<Docs>
|
||||
<summary>To be added.</summary>
|
||||
<value>To be added.</value>
|
||||
<remarks>To be added.</remarks>
|
||||
</Docs>
|
||||
</Member>
|
||||
<Member MemberName="iOS">
|
||||
<MemberSignature Language="C#" Value="public T iOS { get; set; }" />
|
||||
<MemberSignature Language="ILAsm" Value=".property instance !T iOS" />
|
||||
|
|
Загрузка…
Ссылка в новой задаче