Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

GH-491: Fix version parsing #492

Merged
merged 2 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Samples/Samples/View/DeviceInfoPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Label Text="{Binding Model, StringFormat='Model: {0}'}" />
<Label Text="{Binding Manufacturer, StringFormat='Manufacturer: {0}'}" />
<Label Text="{Binding Name, StringFormat='Device Name: {0}'}" />
<Label Text="{Binding VersionString, StringFormat='Version: {0}'}" />
<Label Text="{Binding Version, StringFormat='Version: {0}'}" />
<Label Text="{Binding Platform, StringFormat='Platform: {0}'}" />
<Label Text="{Binding Idiom, StringFormat='Idiom: {0}'}" />
Expand Down
4 changes: 3 additions & 1 deletion Samples/Samples/ViewModel/DeviceInfoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public class DeviceInfoViewModel : BaseViewModel

public string Name => DeviceInfo.Name;

public string Version => DeviceInfo.VersionString;
public string VersionString => DeviceInfo.VersionString;

public string Version => DeviceInfo.Version.ToString();

public string Platform => DeviceInfo.Platform;

Expand Down
19 changes: 19 additions & 0 deletions Tests/Utils_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Xamarin.Essentials;
using Xunit;

namespace Tests
{
public class Utils_Tests
{
[Theory]
[InlineData("9", "9.0", 9, 0)]
[InlineData("9.0", "9.0", 9, 0)]
public void ParseVersion(string input, string expected, int major, int minor)
{
var version = Utils.ParseVersion(input);
Assert.Equal(expected, version.ToString());
Assert.Equal(major, version.Major);
Assert.Equal(minor, version.Minor);
}
}
}
3 changes: 3 additions & 0 deletions Xamarin.Essentials/Types/Shared/Utils.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ internal static Version ParseVersion(string version)
if (Version.TryParse(version, out var number))
return number;

if (int.TryParse(version, out var major))
return new Version(major, 0);

return new Version(0, 0);
}

Expand Down