diff --git a/build/_build.csproj b/build/_build.csproj
index 38873bea..3cd974b1 100644
--- a/build/_build.csproj
+++ b/build/_build.csproj
@@ -13,7 +13,7 @@
-
+
diff --git a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj
index c138f28f..686eabe4 100644
--- a/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj
+++ b/samples/BlazorWebAssemblySampleApp/BlazorWebAssemblySampleApp.csproj
@@ -5,9 +5,10 @@
-
-
-
+
+
+
+
diff --git a/samples/NetSampleApp/NetSampleApp.csproj b/samples/NetSampleApp/NetSampleApp.csproj
index 8c0a80a0..f455010b 100644
--- a/samples/NetSampleApp/NetSampleApp.csproj
+++ b/samples/NetSampleApp/NetSampleApp.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj b/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj
index 628adbc4..d83e26c7 100644
--- a/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj
+++ b/samples/ProcessUtilsSampleApp/ProcessUtilsSampleApp.csproj
@@ -7,8 +7,8 @@
-
-
+
+
diff --git a/samples/WebApiSampleApp/WebApiSampleApp.csproj b/samples/WebApiSampleApp/WebApiSampleApp.csproj
index a0a93b11..7385823e 100644
--- a/samples/WebApiSampleApp/WebApiSampleApp.csproj
+++ b/samples/WebApiSampleApp/WebApiSampleApp.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj
index 8f189772..8ac2b29c 100644
--- a/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj
+++ b/source/AspNetCore/CreativeCoders.AspNetCore.Blazor/CreativeCoders.AspNetCore.Blazor.csproj
@@ -7,9 +7,9 @@
-
-
-
+
+
+
diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj
index 517d0e49..db97aea3 100644
--- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj
+++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuth.Jwt/CreativeCoders.AspNetCore.TokenAuth.Jwt.csproj
@@ -7,8 +7,8 @@
-
-
+
+
diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj
index aa078a26..9710e1fa 100644
--- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj
+++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi.Jwt/CreativeCoders.AspNetCore.TokenAuthApi.Jwt.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj
index 42697242..09f4151b 100644
--- a/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj
+++ b/source/AspNetCore/CreativeCoders.AspNetCore.TokenAuthApi/CreativeCoders.AspNetCore.TokenAuthApi.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj
index e7285346..e5f99f0e 100644
--- a/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj
+++ b/source/Cli/CreativeCoders.Cli.Hosting/CreativeCoders.Cli.Hosting.csproj
@@ -13,8 +13,8 @@
-
-
+
+
diff --git a/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs b/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs
index 70bdfa4b..18b7226a 100644
--- a/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs
+++ b/source/Cli/CreativeCoders.Cli.Hosting/DefaultCliHostBuilder.cs
@@ -1,3 +1,4 @@
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using CreativeCoders.Cli.Core;
using CreativeCoders.Cli.Hosting.Commands;
@@ -86,6 +87,7 @@ public ICliHostBuilder SkipScanEntryAssembly(bool skipScanEntryAssembly = true)
return this;
}
+ [SuppressMessage("Performance", "CA1859:Use concrete types when possible for improved performance")]
private IServiceProvider BuildServiceProvider()
{
var services = new ServiceCollection();
diff --git a/source/Cli/CreativeCoders.Cli.Hosting/ICliHost.cs b/source/Cli/CreativeCoders.Cli.Hosting/ICliHost.cs
index c083b8c1..9a364536 100644
--- a/source/Cli/CreativeCoders.Cli.Hosting/ICliHost.cs
+++ b/source/Cli/CreativeCoders.Cli.Hosting/ICliHost.cs
@@ -1,9 +1,12 @@
+using JetBrains.Annotations;
+
namespace CreativeCoders.Cli.Hosting;
///
/// Represents a Command Line Interface (CLI) host that provides functionality to execute
/// commands and handle related tasks.
///
+[PublicAPI]
public interface ICliHost
{
///
diff --git a/source/CodeCompilation/CreativeCoders.CodeCompilation.Roslyn/CreativeCoders.CodeCompilation.Roslyn.csproj b/source/CodeCompilation/CreativeCoders.CodeCompilation.Roslyn/CreativeCoders.CodeCompilation.Roslyn.csproj
index b71ab195..90cc1e3e 100644
--- a/source/CodeCompilation/CreativeCoders.CodeCompilation.Roslyn/CreativeCoders.CodeCompilation.Roslyn.csproj
+++ b/source/CodeCompilation/CreativeCoders.CodeCompilation.Roslyn/CreativeCoders.CodeCompilation.Roslyn.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj b/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj
index d7fd88fa..4fded7a2 100644
--- a/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj
+++ b/source/Config/CreativeCoders.Config/CreativeCoders.Config.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj b/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj
index 847fc4ff..4b7c18f0 100644
--- a/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj
+++ b/source/Core/CreativeCoders.Core/CreativeCoders.Core.csproj
@@ -7,8 +7,8 @@
-
-
+
+
diff --git a/source/Core/CreativeCoders.Core/Ensure.cs b/source/Core/CreativeCoders.Core/Ensure.cs
index 06040c7b..78215ee5 100644
--- a/source/Core/CreativeCoders.Core/Ensure.cs
+++ b/source/Core/CreativeCoders.Core/Ensure.cs
@@ -17,6 +17,8 @@ namespace CreativeCoders.Core;
[PublicAPI]
public static class Ensure
{
+ private const string UnkownParamName = "[unknown]";
+
///-------------------------------------------------------------------------------------------------
/// Ensures that is not null.
///
@@ -32,21 +34,16 @@ public static class Ensure
[ContractAnnotation("value: null => halt; value: notnull => notnull")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[return: System.Diagnostics.CodeAnalysis.NotNull]
- public static T NotNull([System.Diagnostics.CodeAnalysis.NotNull][NoEnumeration] T? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ public static T NotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumeration] T? value,
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
- if (value is null)
- {
- throw new ArgumentNullException(paramName);
- }
-
- return value;
+ return value ?? throw new ArgumentNullException(paramName);
}
[ContractAnnotation("value: null => halt")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull][NoEnumeration] object? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumeration] object? value,
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
if (value is null)
{
@@ -64,7 +61,7 @@ public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull][NoEnumera
///-------------------------------------------------------------------------------------------------
[ContractAnnotation("halt <= value: null")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull][NoEnumeration] object? value,
+ public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull] [NoEnumeration] object? value,
Func createException) where T : Exception
{
if (value == null)
@@ -87,14 +84,11 @@ public static void IsNotNull([System.Diagnostics.CodeAnalysis.NotNull][NoEnum
[ContractAnnotation("halt <= value: null; value: notnull => notnull")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string IsNotNullOrEmpty([System.Diagnostics.CodeAnalysis.NotNull] string? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
- if (string.IsNullOrEmpty(value))
- {
- throw new ArgumentException("Must not be null or empty", paramName);
- }
-
- return value;
+ return string.IsNullOrEmpty(value)
+ ? throw new ArgumentException("Must not be null or empty", paramName)
+ : value;
}
///-------------------------------------------------------------------------------------------------
@@ -110,7 +104,7 @@ public static string IsNotNullOrEmpty([System.Diagnostics.CodeAnalysis.NotNull]
[ContractAnnotation("halt <= value: null")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IsNotNullOrEmpty(IEnumerable? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
if (value == null || !value.Any())
{
@@ -132,14 +126,11 @@ public static void IsNotNullOrEmpty(IEnumerable? value,
[ContractAnnotation("halt <= value: null; value: notnull => notnull")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string IsNotNullOrWhitespace(string? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
- if (string.IsNullOrWhiteSpace(value))
- {
- throw new ArgumentException("Must not be null or whitespace", paramName);
- }
-
- return value;
+ return string.IsNullOrWhiteSpace(value)
+ ? throw new ArgumentException("Must not be null or whitespace", paramName)
+ : value;
}
/// -------------------------------------------------------------------------------------------------
@@ -152,7 +143,7 @@ public static string IsNotNullOrWhitespace(string? value,
/// Name of the parameter.
/// -------------------------------------------------------------------------------------------------
public static void FileExists(string? fileName,
- [CallerArgumentExpression("fileName")] string paramName = "[unknown]")
+ [CallerArgumentExpression("fileName")] string paramName = UnkownParamName)
{
if (!FileSys.File.Exists(fileName))
{
@@ -173,11 +164,13 @@ public static void FileExists(string? fileName,
/// Name of the parameter.
///-------------------------------------------------------------------------------------------------
public static void DirectoryExists(string? directoryName,
- [CallerArgumentExpression("directoryName")] string paramName = "[unknown]")
+ [CallerArgumentExpression("directoryName")]
+ string paramName = UnkownParamName)
{
if (!FileSys.Directory.Exists(directoryName))
{
- throw new DirectoryNotFoundException($"Directory parameter '{paramName}' not found: '{directoryName}'");
+ throw new DirectoryNotFoundException(
+ $"Directory parameter '{paramName}' not found: '{directoryName}'");
}
}
@@ -191,7 +184,7 @@ public static void DirectoryExists(string? directoryName,
///-------------------------------------------------------------------------------------------------
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void GuidIsNotEmpty(Guid guid,
- [CallerArgumentExpression("guid")] string paramName = "[unknown]")
+ [CallerArgumentExpression("guid")] string paramName = UnkownParamName)
{
if (guid.Equals(Guid.Empty))
{
@@ -199,17 +192,17 @@ public static void GuidIsNotEmpty(Guid guid,
}
}
- ///-------------------------------------------------------------------------------------------------
- /// Ensures that is true.
- ///
+ /// -------------------------------------------------------------------------------------------------
+ /// Ensures that is true.
/// The condition that gets checked.
- /// Name of the parameter that gets checked.
/// The message for the exception.
- ///-------------------------------------------------------------------------------------------------
+ /// Name of the parameter that gets checked.
+ /// -------------------------------------------------------------------------------------------------
[ContractAnnotation("halt <= condition: false")]
public static void That(bool condition,
- [CallerArgumentExpression("condition")] string paramName = "[unknown]",
- string message = "Assertion failed")
+ string message = "Assertion failed",
+ [CallerArgumentExpression("condition")]
+ string paramName = UnkownParamName)
{
if (!condition)
{
@@ -217,20 +210,20 @@ public static void That(bool condition,
}
}
- ///-------------------------------------------------------------------------------------------------
- /// Ensures that a index meets a condition.
- ///
- /// Thrown when is
- /// false, cause index not meets requirements.
+ /// -------------------------------------------------------------------------------------------------
+ /// Ensures that a index meets a condition.
///
+ /// Thrown when is
+ /// false, cause index not meets requirements.
/// The condition that gets checked.
- /// Name of the parameter that gets checked.
/// The message for the exception.
- ///-------------------------------------------------------------------------------------------------
+ /// Name of the parameter that gets checked.
+ /// -------------------------------------------------------------------------------------------------
[ContractAnnotation("halt <= condition: false")]
public static void ThatRange(bool condition,
- [CallerArgumentExpression("condition")] string paramName = "[unknown]",
- string message = "Assertion failed")
+ string message = "Assertion failed",
+ [CallerArgumentExpression("condition")]
+ string paramName = UnkownParamName)
{
if (!condition)
{
@@ -253,7 +246,7 @@ public static void ThatRange(bool condition,
///-------------------------------------------------------------------------------------------------
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IndexIsInRange(int index, int startIndex, int endIndex,
- [CallerArgumentExpression("index")] string paramName = "[unknown]")
+ [CallerArgumentExpression("index")] string paramName = UnkownParamName)
{
if (index < startIndex || index > endIndex)
{
@@ -276,7 +269,7 @@ public static void IndexIsInRange(int index, int startIndex, int endIndex,
///-------------------------------------------------------------------------------------------------
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void IndexIsInRange(int index, int collectionLength,
- [CallerArgumentExpression("index")] string paramName = "[unknown]")
+ [CallerArgumentExpression("index")] string paramName = UnkownParamName)
{
if (index < 0 || index >= collectionLength)
{
@@ -296,7 +289,7 @@ public static void IndexIsInRange(int index, int collectionLength,
///-------------------------------------------------------------------------------------------------
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Argument Argument(T? value,
- [CallerArgumentExpression("value")] string paramName = "[unknown]")
+ [CallerArgumentExpression("value")] string paramName = UnkownParamName)
{
return new Argument(value, paramName);
}
diff --git a/source/Core/CreativeCoders.Core/Text/TextSpan.cs b/source/Core/CreativeCoders.Core/Text/TextSpan.cs
index a0aec4dc..5845c81c 100644
--- a/source/Core/CreativeCoders.Core/Text/TextSpan.cs
+++ b/source/Core/CreativeCoders.Core/Text/TextSpan.cs
@@ -14,8 +14,8 @@ public class TextSpan
///-------------------------------------------------------------------------------------------------
public TextSpan(int start, int length)
{
- Ensure.That(start >= 0, nameof(start), "Start must not be less 0");
- Ensure.That(length >= 0, nameof(length), "Length must not be less 0");
+ Ensure.That(start >= 0, "Start must not be less 0");
+ Ensure.That(length >= 0, "Length must not be less 0");
Start = start;
Length = length;
diff --git a/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj b/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj
index feaa87ae..8d844bca 100644
--- a/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj
+++ b/source/Daemon/CreativeCoders.Daemon.Linux/CreativeCoders.Daemon.Linux.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj b/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj
index 4fd3b058..848c41e7 100644
--- a/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj
+++ b/source/Daemon/CreativeCoders.Daemon.Windows/CreativeCoders.Daemon.Windows.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj b/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj
index b7fe49b5..4c1a82f0 100644
--- a/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj
+++ b/source/Daemon/CreativeCoders.Daemon/CreativeCoders.Daemon.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj b/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj
index 025e764e..99f63b4d 100644
--- a/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj
+++ b/source/Data/CreativeCoders.Data.EfCore.SqlServer/CreativeCoders.Data.EfCore.SqlServer.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj b/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj
index 9bbd4121..34221f6c 100644
--- a/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj
+++ b/source/Data/CreativeCoders.Data.EfCore/CreativeCoders.Data.EfCore.csproj
@@ -6,8 +6,8 @@
-
-
+
+
diff --git a/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj b/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj
index 999bcb9d..09bb7859 100644
--- a/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj
+++ b/source/Data/CreativeCoders.Data.Nhibernate/CreativeCoders.Data.Nhibernate.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj b/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj
index 8c042911..72459f62 100644
--- a/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj
+++ b/source/Data/CreativeCoders.Data.NoSql/CreativeCoders.Data.NoSql.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj b/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj
index 44bf61b9..8d94c9c6 100644
--- a/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj
+++ b/source/DependencyInjection/CreativeCoders.DependencyInjection/CreativeCoders.DependencyInjection.csproj
@@ -7,8 +7,8 @@
-
-
+
+
diff --git a/source/IO/CreativeCoders.IO/CreativeCoders.IO.csproj b/source/IO/CreativeCoders.IO/CreativeCoders.IO.csproj
index bf49b8a1..3c7c17de 100644
--- a/source/IO/CreativeCoders.IO/CreativeCoders.IO.csproj
+++ b/source/IO/CreativeCoders.IO/CreativeCoders.IO.csproj
@@ -7,9 +7,9 @@
-
+
-
+
diff --git a/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj b/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj
index 87f1ac4d..d8831c3f 100644
--- a/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj
+++ b/source/Localization/CreativeCoders.Localization/CreativeCoders.Localization.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj b/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj
index 2f88033d..7690a83b 100644
--- a/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj
+++ b/source/Messaging/CreativeCoders.Messaging.DefaultMessageQueue/CreativeCoders.Messaging.DefaultMessageQueue.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj b/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj
index 5e75ef25..08573ab0 100644
--- a/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj
+++ b/source/Net/CreativeCoders.Net.JsonRpc/CreativeCoders.Net.JsonRpc.csproj
@@ -12,7 +12,7 @@
-
+
diff --git a/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj b/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj
index e9738af7..d2420a43 100644
--- a/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj
+++ b/source/Net/CreativeCoders.Net/CreativeCoders.Net.csproj
@@ -6,9 +6,9 @@
-
+
-
+
diff --git a/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj b/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj
index abe4144d..919ffdd9 100644
--- a/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj
+++ b/source/Options/CreativeCoders.Options.Core/CreativeCoders.Options.Core.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/Parsers/SplitLinesOutputParser.cs b/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/Parsers/SplitLinesOutputParser.cs
index eedef2b9..e56f63d4 100644
--- a/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/Parsers/SplitLinesOutputParser.cs
+++ b/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/Parsers/SplitLinesOutputParser.cs
@@ -1,7 +1,10 @@
+using System.Diagnostics.CodeAnalysis;
+
namespace CreativeCoders.ProcessUtils.Execution.Parsers;
public class SplitLinesOutputParser : IProcessOutputParser
{
+ [SuppressMessage("ReSharper", "ReturnTypeCanBeNotNullable")]
public string[]? ParseOutput(string? output)
{
if (string.IsNullOrEmpty(output))
@@ -18,7 +21,7 @@ public class SplitLinesOutputParser : IProcessOutputParser
public string[] Separators { get; set; } = [Environment.NewLine];
- public bool TrimLines { get; set; } = false;
+ public bool TrimLines { get; set; }
public StringSplitOptions SplitOptions { get; set; } = StringSplitOptions.None;
}
diff --git a/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/ProcessExecutorInfo.cs b/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/ProcessExecutorInfo.cs
index 00b9d5a4..fb1148b6 100644
--- a/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/ProcessExecutorInfo.cs
+++ b/source/ProcessUtils/CreativeCoders.ProcessUtils/Execution/ProcessExecutorInfo.cs
@@ -1,4 +1,5 @@
using System.Diagnostics;
+using JetBrains.Annotations;
namespace CreativeCoders.ProcessUtils.Execution;
@@ -8,9 +9,10 @@ public class ProcessExecutorInfo(
IProcessOutputParser outputParser)
: ProcessExecutorInfo(fileName, arguments)
{
- public IProcessOutputParser OutputParser { get; set; } = outputParser;
+ public IProcessOutputParser OutputParser { get; } = outputParser;
}
+[PublicAPI]
public class ProcessExecutorInfo(string fileName, string[] arguments)
{
public string FileName { get; } = fileName;
diff --git a/source/ProcessUtils/CreativeCoders.ProcessUtils/IProcess.cs b/source/ProcessUtils/CreativeCoders.ProcessUtils/IProcess.cs
index a3ad6cb5..9f862e2f 100644
--- a/source/ProcessUtils/CreativeCoders.ProcessUtils/IProcess.cs
+++ b/source/ProcessUtils/CreativeCoders.ProcessUtils/IProcess.cs
@@ -20,7 +20,7 @@ public interface IProcess : IDisposable
void WaitForExit(TimeSpan timeout);
- Task WaitForExitAsync(CancellationToken cancellationToken = default(CancellationToken));
+ Task WaitForExitAsync(CancellationToken cancellationToken = default);
void WaitForInputIdle();
diff --git a/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj b/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj
index aa4cb065..a9815d62 100644
--- a/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj
+++ b/source/SysConsole/CreativeCoders.SysConsole.App/CreativeCoders.SysConsole.App.csproj
@@ -6,9 +6,9 @@
-
-
-
+
+
+
diff --git a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj
index 18deda21..22e11379 100644
--- a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj
+++ b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/CreativeCoders.SysConsole.Cli.Parsing.csproj
@@ -6,7 +6,7 @@
-
+
diff --git a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/CliValueConverters.cs b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/CliValueConverters.cs
index 269f9af5..7e332968 100644
--- a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/CliValueConverters.cs
+++ b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/CliValueConverters.cs
@@ -9,16 +9,12 @@ public class CliValueConverters : ICliValueConverter
{
private readonly Dictionary _converters;
- private readonly ICliValueConverter _enumConverter;
+ private readonly EnumValueConverter _enumConverter = new EnumValueConverter();
- private readonly ICliValueConverter _enumerableConverter;
+ private readonly EnumerableValueConverter _enumerableConverter = new EnumerableValueConverter();
private CliValueConverters()
{
- _enumConverter = new EnumValueConverter();
-
- _enumerableConverter = new EnumerableValueConverter();
-
_converters = new Dictionary
{ { typeof(bool), new BooleanValueConverter() } };
}
@@ -37,10 +33,48 @@ private CliValueConverters()
return _enumerableConverter.Convert(value, targetType, optionAttribute);
}
+ if (targetType.IsGenericType && targetType.GetGenericTypeDefinition() == typeof(Nullable<>))
+ {
+ return ConvertNullable(value, targetType, optionAttribute);
+ }
+
+ if (value == null && targetType.IsValueType)
+ {
+ if (targetType == typeof(bool))
+ {
+ return true;
+ }
+
+ return Activator.CreateInstance(targetType);
+ }
+
return targetType.IsEnum
? _enumConverter.Convert(value, targetType, optionAttribute)
: InternalConvert(value, targetType, optionAttribute);
}
+ private object? ConvertNullable(object? value, Type targetType, OptionBaseAttribute optionAttribute)
+ {
+ var nullableType = targetType.GetGenericArguments()[0];
+
+ if (value == null)
+ {
+ if (nullableType != typeof(bool))
+ {
+ return Activator.CreateInstance(targetType);
+ }
+
+ var boolValue = Activator.CreateInstance(targetType, (object?)true);
+
+ return boolValue;
+ }
+
+ var valueConverted = InternalConvert(value, nullableType, optionAttribute);
+
+ return valueConverted == null
+ ? Activator.CreateInstance(targetType)
+ : Activator.CreateInstance(targetType, valueConverted);
+ }
+
public static ICliValueConverter Default { get; } = new CliValueConverters();
}
diff --git a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/OptionPropertyBase.cs b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/OptionPropertyBase.cs
index a9b69982..ee22cb28 100644
--- a/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/OptionPropertyBase.cs
+++ b/source/SysConsole/CreativeCoders.SysConsole.Cli.Parsing/OptionProperties/OptionPropertyBase.cs
@@ -35,10 +35,7 @@ protected bool SetPropertyValue(OptionArgument? optionArgument, object optionObj
: CliValueConverters.Default)
?? CliValueConverters.Default;
- if (optionArgument != null)
- {
- optionArgument.IsProcessed = true;
- }
+ optionArgument?.IsProcessed = true;
var propertyValue = converter.Convert(value, _propertyInfo.PropertyType, _optionAttribute);
diff --git a/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj b/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj
index 901f207b..e5f8ff50 100644
--- a/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj
+++ b/source/SysConsole/CreativeCoders.SysConsole.Core/CreativeCoders.SysConsole.Core.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj b/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj
index e05aa765..3c7f57c5 100644
--- a/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj
+++ b/source/UnitTests/CreativeCoders.UnitTests/CreativeCoders.UnitTests.csproj
@@ -7,8 +7,8 @@
-
-
+
+
diff --git a/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj b/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj
index 6de64fe6..7f098e87 100644
--- a/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj
+++ b/tests/CreativeCoders.AspNetCore.Blazor.UnitTests/CreativeCoders.AspNetCore.Blazor.UnitTests.csproj
@@ -17,7 +17,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj b/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj
index 0053c74b..fd48092a 100644
--- a/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj
+++ b/tests/CreativeCoders.AspNetCore.Tests/CreativeCoders.AspNetCore.Tests.csproj
@@ -10,9 +10,9 @@
-
-
-
+
+
+
@@ -23,7 +23,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj b/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj
index d6116dc2..41e54f16 100644
--- a/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj
+++ b/tests/CreativeCoders.Cli.Tests/CreativeCoders.Cli.Tests.csproj
@@ -10,8 +10,8 @@
-
-
+
+
@@ -22,7 +22,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj b/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj
index 6ffb6c91..b482c848 100644
--- a/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj
+++ b/tests/CreativeCoders.CodeCompilation.UnitTests/CreativeCoders.CodeCompilation.UnitTests.csproj
@@ -15,7 +15,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj b/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj
index 10506a09..b51018e0 100644
--- a/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj
+++ b/tests/CreativeCoders.Core.UnitTests/CreativeCoders.Core.UnitTests.csproj
@@ -8,8 +8,8 @@
-
-
+
+
@@ -20,7 +20,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj b/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj
index 98ce1d58..ee6ff5f8 100644
--- a/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj
+++ b/tests/CreativeCoders.Data.NoSql.LiteDb.Tests/CreativeCoders.Data.NoSql.LiteDb.Tests.csproj
@@ -9,10 +9,10 @@
-
-
-
-
+
+
+
+
@@ -23,7 +23,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj b/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj
index cc7427d6..54b34b79 100644
--- a/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj
+++ b/tests/CreativeCoders.DependencyInjection.UnitTests/CreativeCoders.DependencyInjection.UnitTests.csproj
@@ -9,7 +9,7 @@
-
+
@@ -20,7 +20,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj b/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj
index b646e700..33165a6f 100644
--- a/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj
+++ b/tests/CreativeCoders.IO.UnitTests/CreativeCoders.IO.UnitTests.csproj
@@ -10,7 +10,7 @@
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -20,7 +20,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj b/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj
index 62a71e20..aa5f39d9 100644
--- a/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj
+++ b/tests/CreativeCoders.Localization.UnitTests/CreativeCoders.Localization.UnitTests.csproj
@@ -7,8 +7,8 @@
-
-
+
+
@@ -19,7 +19,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj b/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj
index 6ade6acf..a2ac5f21 100644
--- a/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj
+++ b/tests/CreativeCoders.Messaging.UnitTests/CreativeCoders.Messaging.UnitTests.csproj
@@ -16,7 +16,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj
index 44b55a87..d35fcf4b 100644
--- a/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj
+++ b/tests/CreativeCoders.MiscTest.UnitTests/CreativeCoders.MiscTest.UnitTests.csproj
@@ -10,8 +10,8 @@
-
-
+
+
@@ -22,7 +22,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj b/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj
index 56711ef9..94a46fb9 100644
--- a/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj
+++ b/tests/CreativeCoders.Net.UnitTests/CreativeCoders.Net.UnitTests.csproj
@@ -17,7 +17,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj b/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj
index 5051ee2b..b6c59270 100644
--- a/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj
+++ b/tests/CreativeCoders.NukeBuild.Tests/CreativeCoders.NukeBuild.Tests.csproj
@@ -22,7 +22,7 @@
-
+
diff --git a/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj b/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj
index 8d7e5259..98a6c101 100644
--- a/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj
+++ b/tests/CreativeCoders.Reactive.UnitTests/CreativeCoders.Reactive.UnitTests.csproj
@@ -17,7 +17,7 @@
all
-
+
diff --git a/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj b/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj
index 81d7659e..e5823eb7 100644
--- a/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj
+++ b/tests/CreativeCoders.Scripting.UnitTests/CreativeCoders.Scripting.UnitTests.csproj
@@ -16,7 +16,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj b/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj
index 95b82dda..8a77f2d1 100644
--- a/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj
+++ b/tests/CreativeCoders.SysConsole.App.UnitTests/CreativeCoders.SysConsole.App.UnitTests.csproj
@@ -18,7 +18,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj b/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj
index d30e436b..16a3b071 100644
--- a/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj
+++ b/tests/CreativeCoders.SysConsole.Cli.Actions.UnitTests/CreativeCoders.SysConsole.Cli.Actions.UnitTests.csproj
@@ -13,8 +13,8 @@
-
-
+
+
@@ -25,7 +25,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj
index 75a01f3e..488f35b8 100644
--- a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj
+++ b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests.csproj
@@ -8,7 +8,7 @@
-
+
@@ -19,7 +19,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/OptionParserTests.cs b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/OptionParserTests.cs
index 1c8b3bc6..9351812e 100644
--- a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/OptionParserTests.cs
+++ b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/OptionParserTests.cs
@@ -12,7 +12,7 @@ public class OptionParserTests
[Fact]
public void Parse_ValueAndParameterWithLongName_PropertiesAreSetCorrect()
{
- var args = new[] {"hello", "--text", "TestText"};
+ var args = new[] { "hello", "--text", "TestText" };
var parser = new OptionParser(typeof(TestOptionForParser));
@@ -36,7 +36,7 @@ public void Parse_ValueAndParameterWithLongName_PropertiesAreSetCorrect()
[Fact]
public void Parse_ValueAndParameterWithShortName_PropertiesAreSetCorrect()
{
- var args = new[] {"hello", "-t", "TestText"};
+ var args = new[] { "hello", "-t", "TestText" };
var parser = new OptionParser(typeof(TestOptionForParser));
@@ -64,7 +64,7 @@ public void Parse_IntValueAndParameterWithLongName_PropertiesAreSetCorrect()
const int expectedValue1 = 4321;
var args = new[]
- {"hello", "--integer2", expectedValue1.ToString(), "--integer", expectedValue0.ToString()};
+ { "hello", "--integer2", expectedValue1.ToString(), "--integer", expectedValue0.ToString() };
var parser = new OptionParser(typeof(TestOptionWithInt));
@@ -91,7 +91,7 @@ public void Parse_IntValueAndParameterWithShortName_PropertiesAreSetCorrect()
const int expectedValue0 = 1234;
const int expectedValue1 = 4321;
- var args = new[] {"hello", "-j", expectedValue1.ToString(), "-i", expectedValue0.ToString()};
+ var args = new[] { "hello", "-j", expectedValue1.ToString(), "-i", expectedValue0.ToString() };
var parser = new OptionParser(typeof(TestOptionWithInt));
@@ -121,7 +121,7 @@ public void Parse_RequiredParameterMissing_ThrowsException()
{
const int expectedValue1 = 4321;
- var args = new[] {"hello", "-j", expectedValue1.ToString()};
+ var args = new[] { "hello", "-j", expectedValue1.ToString() };
var parser = new OptionParser(typeof(TestOptionWithInt));
@@ -140,13 +140,13 @@ public void Parse_RequiredParameterMissing_ThrowsException()
exception.ParameterAttribute
.Should()
- .BeEquivalentTo(new OptionParameterAttribute('i', "integer") {IsRequired = true});
+ .BeEquivalentTo(new OptionParameterAttribute('i', "integer") { IsRequired = true });
}
[Fact]
public void Parse_BoolValues_PropertiesAreSetCorrect()
{
- var args = new[] {"-v", "--bold", "true"};
+ var args = new[] { "-v", "--bold", "true" };
var parser = new OptionParser(typeof(TestOptionWithBool));
@@ -170,7 +170,7 @@ public void Parse_BoolValues_PropertiesAreSetCorrect()
[Fact]
public void Parse_BoolValuesInvalidFormat_PropertyIsSetFalse()
{
- var args = new[] {"-v", "--bold", "1234"};
+ var args = new[] { "-v", "--bold", "1234" };
var parser = new OptionParser(typeof(TestOptionWithBool));
@@ -214,7 +214,7 @@ public void Parse_RequiredValueMissing_ThrowsException()
exception.ValueAttribute
.Should()
- .BeEquivalentTo(new OptionValueAttribute(0) {IsRequired = true});
+ .BeEquivalentTo(new OptionValueAttribute(0) { IsRequired = true });
}
[Fact]
@@ -295,7 +295,7 @@ public void Parse_OptionNull_ThrowsException()
[InlineData("nONe", TestEnum.None)]
public void Parse_EnumValue_PropertyIsSetCorrect(string argValue, TestEnum enumValue)
{
- var args = new[] {"-e", argValue};
+ var args = new[] { "-e", argValue };
var parser = new OptionParser(typeof(TestOptionWithEnum));
@@ -319,7 +319,7 @@ public void Parse_EnumValue_PropertyIsSetCorrect(string argValue, TestEnum enumV
[InlineData("qwertz", "QWERTZ")]
public void Parse_PropertyWithConverter_PropertyIsSetCorrect(string argValue, string propertyValue)
{
- var args = new[] {"-t", argValue};
+ var args = new[] { "-t", argValue };
var parser = new OptionParser(typeof(TestOptionWithConverter));
@@ -337,12 +337,12 @@ public void Parse_PropertyWithConverter_PropertyIsSetCorrect(string argValue, st
}
[Theory]
- [InlineData("1,2,3,4,5", new[] {1, 2, 3, 4, 5})]
- [InlineData("1", new[] {1})]
+ [InlineData("1,2,3,4,5", new[] { 1, 2, 3, 4, 5 })]
+ [InlineData("1", new[] { 1 })]
public void Parse_PropertyIsIEnumerableOfInt_PropertyIsSetCorrect(string argValue,
IEnumerable intValues)
{
- var args = new[] {"-i", argValue};
+ var args = new[] { "-i", argValue };
var parser = new OptionParser(typeof(TestOptionWithIntEnumerable));
@@ -367,7 +367,7 @@ public void Parse_PropertyIsIEnumerableOfInt_PropertyIsSetCorrect(string argValu
public void Parse_PropertyIsEnumWithFlags_EnumFlagsAreSetCorrect(string argValue,
TestEnumWithFlags enumWithFlags)
{
- var args = new[] {"-e", argValue};
+ var args = new[] { "-e", argValue };
var parser = new OptionParser(typeof(TestOptionWithEnumFlags));
@@ -406,7 +406,7 @@ public void Parse_NotAllArgsMatch_ThrowsException(params string[] args)
.Should()
.HaveCount(1)
.And
- .BeEquivalentTo(new[] {new OptionArgument {Kind = OptionArgumentKind.Value, Value = "test"}});
+ .BeEquivalentTo(new[] { new OptionArgument { Kind = OptionArgumentKind.Value, Value = "test" } });
}
[Theory]
@@ -416,7 +416,7 @@ public void Parse_ParameterTypeIsArrayOfString_ArgsAreReturned(Type optionType)
{
var parser = new OptionParser(optionType);
- var args = new[] {"first", "second", "some", "more"};
+ var args = new[] { "first", "second", "some", "more" };
// Act
var option = parser.Parse(args) as string[];
@@ -437,11 +437,97 @@ public void Test(bool expectedValue, params string[] args)
var parser = new OptionParser(typeof(TestOptionWithSingleBool));
// Act
- var option = (TestOptionWithSingleBool) parser.Parse(args);
+ var option = (TestOptionWithSingleBool)parser.Parse(args);
// Assert
option.CreateData
.Should()
.Be(expectedValue);
}
+
+ [Theory]
+ [InlineData("-b")]
+ [InlineData("-b", "true")]
+ public void Parse_NullableBoolValue_BoolValueIsSetToTrue(params string[] args)
+ {
+ // Arrange
+ var parser = new OptionParser(typeof(TestOptionWithNullable));
+
+ // Act
+ var options = (TestOptionWithNullable)parser.Parse(args);
+
+ // Assert
+ options.NullableBoolValue.HasValue
+ .Should().BeTrue();
+
+ options.NullableBoolValue
+ .Should().BeTrue();
+ }
+
+ [Fact]
+ public void Parse_NullableBoolValueNotSet_NullableHasNoValue()
+ {
+ // Arrange
+ var args = Array.Empty();
+ var parser = new OptionParser(typeof(TestOptionWithNullable));
+
+ // Act
+ var options = (TestOptionWithNullable)parser.Parse(args);
+
+ // Assert
+ options.NullableBoolValue.HasValue
+ .Should().BeFalse();
+ }
+
+ [Fact]
+ public void Parse_NullableBoolValueSetToFalse_NullableValueIsFalse()
+ {
+ // Arrange
+ var args = new[] { "-b", "false" };
+ var parser = new OptionParser(typeof(TestOptionWithNullable));
+
+ // Act
+ var options = (TestOptionWithNullable)parser.Parse(args);
+
+ // Assert
+ options.NullableBoolValue.HasValue
+ .Should().BeTrue();
+
+ options.NullableBoolValue
+ .Should().BeFalse();
+ }
+
+ [Theory]
+ [InlineData("--nullable", "1234")]
+ [InlineData("-n", "1234")]
+ public void Parse_NullableIntValue_IntValueIsSetToTrue(params string[] args)
+ {
+ // Arrange
+ var parser = new OptionParser(typeof(TestOptionWithNullable));
+
+ // Act
+ var options = (TestOptionWithNullable)parser.Parse(args);
+
+ // Assert
+ options.NullableIntValue.HasValue
+ .Should().BeTrue();
+
+ options.NullableIntValue
+ .Should().Be(int.Parse(args[1]));
+ }
+
+ [Fact]
+ public void Parse_NullableIntValueNotSet_NullableValueHasNoValue()
+ {
+ // Arrange
+ var args = new[] { "-n" };
+ var parser = new OptionParser(typeof(TestOptionWithNullable));
+
+ // Act
+ var options = (TestOptionWithNullable)parser.Parse(args);
+
+ // Assert
+ options.NullableIntValue.HasValue
+ .Should().BeFalse();
+ }
}
diff --git a/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/TestData/TestOptionWithNullable.cs b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/TestData/TestOptionWithNullable.cs
new file mode 100644
index 00000000..5cfdea2d
--- /dev/null
+++ b/tests/CreativeCoders.SysConsole.Cli.Parsing.UnitTests/TestData/TestOptionWithNullable.cs
@@ -0,0 +1,11 @@
+using JetBrains.Annotations;
+
+namespace CreativeCoders.SysConsole.Cli.Parsing.UnitTests.TestData;
+
+[UsedImplicitly]
+public class TestOptionWithNullable
+{
+ [OptionParameter('n', "nullable")] public int? NullableIntValue { get; set; }
+
+ [OptionParameter('b', "bool")] public bool? NullableBoolValue { get; set; }
+}
diff --git a/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj b/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj
index 278ad2f2..1590ee63 100644
--- a/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj
+++ b/tests/CreativeCoders.SysConsole.CliArguments.UnitTests/CreativeCoders.SysConsole.CliArguments.UnitTests.csproj
@@ -8,7 +8,7 @@
-
+
@@ -19,7 +19,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
diff --git a/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj b/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj
index 2db0d7e9..c98979df 100644
--- a/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj
+++ b/tests/CreativeCoders.SysConsole.UnitTests/CreativeCoders.SysConsole.UnitTests.csproj
@@ -19,7 +19,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+