Skip to content

Commit

Permalink
Update to net46
Browse files Browse the repository at this point in the history
  • Loading branch information
danmoseley committed Nov 27, 2022
1 parent dd5de06 commit ea50465
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Abstractions/ValueParserProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static readonly MethodInfo s_getParserGeneric
public IValueParser GetParser(Type type)
{
var method = s_getParserGeneric.MakeGenericMethod(type);
return (IValueParser)method.Invoke(this, Util.EmptyArray<object>());
return (IValueParser)method.Invoke(this, Array.Empty<object>());
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLineUtils/Attributes/CommandAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace McMaster.Extensions.CommandLineUtils
[AttributeUsage(AttributeTargets.Class)]
public sealed class CommandAttribute : Attribute
{
private string[] _names = Util.EmptyArray<string>();
private string[] _names = Array.Empty<string>();

/// <summary>
/// Initializes a new <see cref="CommandAttribute"/>.
Expand Down Expand Up @@ -55,7 +55,7 @@ public string? Name
}
else
{
_names = Util.EmptyArray<string>();
_names = Array.Empty<string>();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal CommandOption Configure(CommandLineApplication app, Type type, Func<obj

shortFormGetter = () =>
{
return (string)methods[0].Invoke(targetInstanceFactory.Invoke(), Util.EmptyArray<object>());
return (string)methods[0].Invoke(targetInstanceFactory.Invoke(), Array.Empty<object>());
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/CommandLineUtils/CommandLineApplication.Execute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static int Execute<TApp>(params string[] args)
public static int Execute<TApp>(IConsole console, params string[] args)
where TApp : class
{
args ??= Util.EmptyArray<string>();
args ??= Array.Empty<string>();
var context = new DefaultCommandLineContext(console, Directory.GetCurrentDirectory(), args);
return Execute<TApp>(context);
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public static Task<int> ExecuteAsync<TApp>(string[] args, CancellationToken canc
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
where TApp : class
{
args ??= Util.EmptyArray<string>();
args ??= Array.Empty<string>();
var context = new DefaultCommandLineContext(PhysicalConsole.Singleton, Directory.GetCurrentDirectory(), args);
return ExecuteAsync<TApp>(context, cancellationToken);
}
Expand All @@ -189,7 +189,7 @@ public static Task<int> ExecuteAsync<TApp>(string[] args, CancellationToken canc
public static Task<int> ExecuteAsync<TApp>(IConsole console, params string[] args)
where TApp : class
{
args ??= Util.EmptyArray<string>();
args ??= Array.Empty<string>();
var context = new DefaultCommandLineContext(console, Directory.GetCurrentDirectory(), args);
return ExecuteAsync<TApp>(context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/CommandLineApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ public ParseResult Parse(params string[] args)
{
Reset();

args ??= Util.EmptyArray<string>();
args ??= Array.Empty<string>();

var processor = new CommandLineProcessor(this, args);
var result = processor.Process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private protected void AddOption(ConventionContext context, CommandOption option
{
if (!option.HasValue())
{
setter.Invoke(modelAccessor.GetModel(), Util.EmptyArray<bool>());
setter.Invoke(modelAccessor.GetModel(), Array.Empty<bool>());
}
var count = new bool[option.Values.Count];
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLineUtils/HelpText/DefaultHelpTextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ private string[] ExtractNamesFromEnum(Type? type)
{
if (type == null)
{
return Util.EmptyArray<string>();
return Array.Empty<string>();
}

if (ReflectionHelper.IsNullableType(type, out var wrappedType))
Expand All @@ -431,7 +431,7 @@ private string[] ExtractNamesFromEnum(Type? type)
return Enum.GetNames(type);
}

return Util.EmptyArray<string>();
return Array.Empty<string>();
}
}
}
6 changes: 3 additions & 3 deletions src/CommandLineUtils/IO/Pager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public Pager(IConsole console)
throw new ArgumentNullException(nameof(console));
}

#if NET45
#if NET46_OR_GREATER
// if .NET Framework, assume we're on Windows unless it's running on Mono.
_enabled = Type.GetType("Mono.Runtime") != null;
#elif NETSTANDARD2_0 || NETSTANDARD2_1
#elif NETSTANDARD2_0_OR_GREATER
_enabled = !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && !console.IsOutputRedirected;
#else
#error Update target frameworks
Expand Down Expand Up @@ -130,7 +130,7 @@ public void Kill()
FileName = "less",
Arguments = ArgumentEscaper.EscapeAndConcatenate(args),
RedirectStandardInput = true,
#if NET45
#if NET46_OR_GREATER
UseShellExecute = false,
#endif
}
Expand Down
25 changes: 0 additions & 25 deletions src/CommandLineUtils/Internal/Util.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public HashSetParser(Type elementType, IValueParser elementParser, CultureInfo p

public object Parse(string? argName, IReadOnlyList<string?> values)
{
var set = Activator.CreateInstance(_listType, Util.EmptyArray<object>());
var set = Activator.CreateInstance(_listType, Array.Empty<object>());
foreach (var t in values)
{
_addMethod.Invoke(set, new[] { _elementParser.Parse(argName, t, _parserCulture) });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net45</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
<Nullable Condition="'$(TargetFramework)' != 'netstandard2.1'">annotations</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsPackable>true</IsPackable>
Expand All @@ -26,7 +26,7 @@ McMaster.Extensions.CommandLineUtils.ArgumentEscaper
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
<Reference Include="System.ComponentModel.DataAnnotations" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Properties/NullabilityHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

// Files here are for simplify annotations of nullable code and are not functional in .NET Standard 2.0
#if NETSTANDARD2_0 || NET45
#if NETSTANDARD2_0 || NET46_OR_GREATER
namespace System.Diagnostics.CodeAnalysis
{
// https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.notnullwhenattribute?
Expand Down
17 changes: 12 additions & 5 deletions src/CommandLineUtils/Utilities/DotNetExe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static string FullPathOrDefault()
private static string? TryFindDotNetExePath()
{
var fileName = FileName;
#if NET45
#if NET46_OR_GREATER
fileName += ".exe";
#elif NETSTANDARD2_0 || NETSTANDARD2_1
#elif NETSTANDARD2_0_OR_GREATER
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
fileName += ".exe";
Expand All @@ -60,10 +60,17 @@ public static string FullPathOrDefault()
#else
#error Update target frameworks
#endif
// DOTNET_ROOT specifies the location of the .NET runtimes, if they are not installed in the default location.
var dotnetRoot = Environment.GetEnvironmentVariable("DOTNET_ROOT");
return !string.IsNullOrEmpty(dotnetRoot)
? Path.Combine(dotnetRoot, fileName)
: null;

if (string.IsNullOrEmpty(dotnetRoot))
{
// fall back to default location
// https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_root-dotnet_rootx86
dotnetRoot = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\Program Files\\dotnet" : "/usr/local/share/dotnet";
}

return Path.Combine(dotnetRoot, fileName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void OnExecuteIsExecutedOnSelectedSubcommand(string? args, int expectedRe
app.Conventions.UseCommandAttribute();
app.Conventions.UseOnExecuteMethodFromModel();

var result = app.Execute(args?.Split(' ') ?? Util.EmptyArray<string>());
var result = app.Execute(args?.Split(' ') ?? Array.Empty<string>());
Assert.Equal(expectedResult, result);
}

Expand Down
2 changes: 1 addition & 1 deletion test/CommandLineUtils.Tests/OptionAttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ private CommandOption CreateOption(Type propType, string propName)
pb.SetCustomAttribute(ab);
var program = tb.CreateType();
var appBuilder = typeof(CommandLineApplication<>).MakeGenericType(program);
var app = (CommandLineApplication)Activator.CreateInstance(appBuilder, Util.EmptyArray<object>());
var app = (CommandLineApplication)Activator.CreateInstance(appBuilder, Array.Empty<object>());
app.Conventions.UseOptionAttributes();
return app.Options.First();
}
Expand Down

0 comments on commit ea50465

Please sign in to comment.