-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve net core shared nullability (#85)
* Use conditional access to avoid nullability issues
- Loading branch information
Showing
2 changed files
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |