Skip to content

Commit

Permalink
Resolve net core shared nullability (#85)
Browse files Browse the repository at this point in the history
* Use conditional access to avoid nullability issues
  • Loading branch information
COsborn2 authored Aug 20, 2019
1 parent 0432e9f commit ff46a4c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void Main_GoodArgs_DownloadFile()
{
Assert.AreEqual(0, Program.Main(args));
}
catch (AggregateException exception) when(exception.InnerException.GetType() == typeof(System.Net.Http.HttpRequestException))
catch (AggregateException exception) when(exception.InnerException?.GetType() == typeof(System.Net.Http.HttpRequestException))
{
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
}
Expand Down
31 changes: 16 additions & 15 deletions src/Shared/NetCore.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.Reflection;

public class NetCore
{
public static string GetNetCoreVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
throw new Exception("Unable to determine .NET Core version.");
}
}
using System;
using System.Reflection;

public class NetCore
{
public static string GetNetCoreVersion()
{
Assembly assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyCodeBase = assembly.CodeBase ?? throw new ArgumentNullException("assemblyCodeBase");
string[] assemblyPath = assemblyCodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];
throw new Exception("Unable to determine .NET Core version.");
}
}

0 comments on commit ff46a4c

Please sign in to comment.