Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Fix version parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Aug 23, 2018
1 parent a80a6be commit 026851b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 96 deletions.
22 changes: 6 additions & 16 deletions src/DeviceInfo.Plugin/DeviceInfo.Plugin.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="MSBuild.Sdk.Extras/1.6.47">
<PropertyGroup>
<TargetFrameworks>netstandard1.0;netstandard2.0;net45;MonoAndroid71;Xamarin.iOS10;uap10.0.15063;Xamarin.TVOS10;Xamarin.WatchOS10;Xamarin.Mac20;Tizen40</TargetFrameworks>
<TargetFrameworks>netstandard1.0;netstandard2.0;net45;MonoAndroid71;Xamarin.iOS10;uap10.0.16299;Xamarin.TVOS10;Xamarin.WatchOS10;Xamarin.Mac20;Tizen40</TargetFrameworks>
<AssemblyName>Plugin.DeviceInfo</AssemblyName>
<RootNamespace>Plugin.DeviceInfo</RootNamespace>
<Product>$(AssemblyName) ($(TargetFramework))</Product>
Expand All @@ -19,7 +18,7 @@
<PackageTags>xamarin, pcl, xam.pcl, settings, windows phone, winphone, wp8, winrt, android, xamarin.forms, ios</PackageTags>
<Title>Device Information Plugin for Xamarin and Windows</Title>
<Description>
Receive information about the device that you are using. Properties such as Model, Operatin System, Version, Id, and even the ability to generate a unique Id for your application based off of these properties.
Receive information about the device that you are using. Properties such as Model, Operating System, Version, Id, and even the ability to generate a unique Id for your application based off of these properties.
</Description>
<Copyright>Copyright 2018</Copyright>
<RepositoryUrl>https://github.com/jamesmontemagno/DeviceInfoPlugin</RepositoryUrl>
Expand All @@ -42,19 +41,18 @@
</PropertyGroup>
<ItemGroup>
<None Include="..\..\nuget\readme.txt" PackagePath="readme.txt" Pack="true" />
<PackageReference Include="MSBuild.Sdk.Extras" Version="1.4.0" PrivateAssets="All" />
<Compile Include="**\*.shared.cs" />
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('netstandard')) ">
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('uap10.0')) ">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="5.2.3" />
<SDKReference Include="WindowsDesktop, Version=10.0.15063.0">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.1.5" />
<SDKReference Include="WindowsDesktop, Version=10.0.16299.0">
<Name>Windows Desktop Extensions for the UWP</Name>
</SDKReference>
<SDKReference Include="WindowsMobile, Version=10.0.15063.0">
<SDKReference Include="WindowsMobile, Version=10.0.16299.0">
<Name>Windows Mobile Extensions for the UWP</Name>
</SDKReference>
<Compile Include="**\*.uwp.cs" />
Expand Down Expand Up @@ -87,16 +85,8 @@
<Compile Include="**\*.apple.cs" />
</ItemGroup>





<ItemGroup Condition=" $(TargetFramework.StartsWith('Tizen')) ">
<Compile Include="**\*.tizen.cs" />
<PackageReference Include="Tizen.NET" Version="4.0.0" />
</ItemGroup>



<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
</Project>
19 changes: 3 additions & 16 deletions src/DeviceInfo.Plugin/DeviceInfo.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,10 @@ public string Id
public string Version => Build.VERSION.Release;

/// <inheritdoc/>
public Platform Platform => Platform.Android;
public Platform Platform => Platform.Android;

/// <inheritdoc/>
public Version VersionNumber
{
get
{
try
{
return new Version(Version);
}
catch
{
return new Version();
}
}
}
/// <inheritdoc/>
public Version VersionNumber => Utils.ParseVersion(Version);

/// <summary>
/// Returns the current version of the app, as defined in the metadata, e.g. "4.3".
Expand Down
15 changes: 1 addition & 14 deletions src/DeviceInfo.Plugin/DeviceInfo.apple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,7 @@ string GetModel()


/// <inheritdoc/>
public Version VersionNumber
{
get
{
try
{
return new Version(Version);
}
catch
{
return new Version();
}
}
}
public Version VersionNumber => Utils.ParseVersion(Version);

/// <summary>
/// Returns the current version of the app, as defined in the PList, e.g. "4.3".
Expand Down
25 changes: 6 additions & 19 deletions src/DeviceInfo.Plugin/DeviceInfo.tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,14 @@ public string Version
}
}

public Version VersionNumber
{
get
{
try
{
return new Version(Version);
}
catch
{
return new Version();
}
}
}
public Version VersionNumber => Utils.ParseVersion(Version);


/// <summary>
/// Returns the current build of the app, as defined in the PList, e.g. "4300".
/// </summary>
/// <value>The current build.</value>
public string AppBuild => string.Empty;
/// <summary>
/// Returns the current build of the app, as defined in the PList, e.g. "4300".
/// </summary>
/// <value>The current build.</value>
public string AppBuild => string.Empty;

/// <summary>
/// Returns the current version of the app, as defined in the PList, e.g. "4.3".
Expand Down
15 changes: 1 addition & 14 deletions src/DeviceInfo.Plugin/DeviceInfo.uwp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,7 @@ public Abstractions.Platform Platform
}
}
/// <inheritdoc/>
public Version VersionNumber
{
get
{
try
{
return new Version(Version);
}
catch
{
return new Version(10, 0);
}
}
}
public Version VersionNumber => Utils.ParseVersion(Version);

/// <summary>
/// Returns the current version of the app, as defined in the PList, e.g. "4.3".
Expand Down
47 changes: 30 additions & 17 deletions src/DeviceInfo.Plugin/Platform.shared.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
namespace Plugin.DeviceInfo.Abstractions
using System;
namespace Plugin.DeviceInfo.Abstractions
{
public enum Platform
{
Android,
iOS,
WindowsPhone,
Windows,
WindowsTablet,
SurfaceHub,
Xbox,
IoT,
Unknown,
tvOS,
watchOS,
macOS,
Tizen
}

public enum Platform
{
Android,
iOS,
WindowsPhone,
Windows,
WindowsTablet,
SurfaceHub,
Xbox,
IoT,
Unknown,
tvOS,
watchOS,
macOS,
Tizen
}
class Utils
{
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);
}
}
}

0 comments on commit 026851b

Please sign in to comment.