diff --git a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs index 69347f1..76e67d0 100644 --- a/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs +++ b/CliFx.Analyzers.Tests/Utils/AnalyzerAssertions.cs @@ -73,9 +73,10 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions e.ToString())) + $""" + Failed to compile code. + {string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))} + """ ); } diff --git a/CliFx.Tests/Utils/DynamicCommandBuilder.cs b/CliFx.Tests/Utils/DynamicCommandBuilder.cs index 405656c..a67cfbc 100644 --- a/CliFx.Tests/Utils/DynamicCommandBuilder.cs +++ b/CliFx.Tests/Utils/DynamicCommandBuilder.cs @@ -77,9 +77,10 @@ internal static class DynamicCommandBuilder if (compilationErrors.Any()) { throw new InvalidOperationException( - "Failed to compile code." + - Environment.NewLine + - string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString())) + $""" + Failed to compile code. + {string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))} + """ ); } @@ -95,9 +96,10 @@ internal static class DynamicCommandBuilder if (emitErrors.Any()) { throw new InvalidOperationException( - "Failed to emit code." + - Environment.NewLine + - string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString())) + $""" + Failed to emit code. + {string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString()))} + """ ); } diff --git a/CliFx/CommandBinder.cs b/CliFx/CommandBinder.cs index 018a3d8..6b1a614 100644 --- a/CliFx/CommandBinder.cs +++ b/CliFx/CommandBinder.cs @@ -99,11 +99,11 @@ internal class CommandBinder } throw CliFxException.InternalError( - $"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." + - Environment.NewLine + - $"There is no known way to convert a string value into an instance of type `{targetType.FullName}`." + - Environment.NewLine + - "To fix this, either change the property to use a supported type or configure a custom converter." + $""" + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type. + There is no known way to convert a string value into an instance of type `{targetType.FullName}` + To fix this, either change the property to use a supported type or configure a custom converter. + """ ); } @@ -133,11 +133,11 @@ internal class CommandBinder } throw CliFxException.InternalError( - $"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." + - Environment.NewLine + - $"There is no known way to convert an array of `{targetElementType.FullName}` into an instance of type `{targetEnumerableType.FullName}`." + - Environment.NewLine + - "To fix this, change the property to use a type which can be assigned from an array or a type that has a constructor which accepts an array." + $""" + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type. + There is no known way to convert an array of `{targetElementType.FullName}` into an instance of type `{targetEnumerableType.FullName}`. + To fix this, change the property to use a type which can be assigned from an array or a type that has a constructor which accepts an array. + """ ); } @@ -169,20 +169,21 @@ internal class CommandBinder : ex.Message; throw CliFxException.UserError( - $"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s):" + - Environment.NewLine + - rawValues.Select(v => '<' + v + '>').JoinToString(" ") + - Environment.NewLine + - $"Error: {errorMessage}", + $""" + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s): + {rawValues.Select(v => '<' + v + '>').JoinToString(" ")} + Error: {errorMessage} + """, ex ); } // Mismatch (scalar but too many values) throw CliFxException.UserError( - $"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple:" + - Environment.NewLine + - rawValues.Select(v => '<' + v + '>').JoinToString(" ") + $""" + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple: + {rawValues.Select(v => '<' + v + '>').JoinToString(" ")} + """ ); } @@ -202,11 +203,11 @@ internal class CommandBinder if (errors.Any()) { throw CliFxException.UserError( - $"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value." + - Environment.NewLine + - "Error(s):" + - Environment.NewLine + - errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine) + $""" + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value. + Error(s): + {errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine)} + """ ); } } @@ -264,22 +265,20 @@ internal class CommandBinder if (remainingParameterInputs.Any()) { throw CliFxException.UserError( - "Unexpected parameter(s):" + - Environment.NewLine + - remainingParameterInputs - .Select(p => p.GetFormattedIdentifier()) - .JoinToString(" ") + $""" + Unexpected parameter(s): + {remainingParameterInputs.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")} + """ ); } if (remainingRequiredParameterSchemas.Any()) { throw CliFxException.UserError( - "Missing required parameter(s):" + - Environment.NewLine + - remainingRequiredParameterSchemas - .Select(p => p.GetFormattedIdentifier()) - .JoinToString(" ") + $""" + Missing required parameter(s): + {remainingRequiredParameterSchemas.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")} + """ ); } } @@ -337,22 +336,20 @@ internal class CommandBinder if (remainingOptionInputs.Any()) { throw CliFxException.UserError( - "Unrecognized option(s):" + - Environment.NewLine + - remainingOptionInputs - .Select(o => o.GetFormattedIdentifier()) - .JoinToString(", ") + $""" + Unrecognized option(s): + {remainingOptionInputs.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")} + """ ); } if (remainingRequiredOptionSchemas.Any()) { throw CliFxException.UserError( - "Missing required option(s):" + - Environment.NewLine + - remainingRequiredOptionSchemas - .Select(o => o.GetFormattedIdentifier()) - .JoinToString(", ") + $""" + Missing required option(s): + {remainingRequiredOptionSchemas.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")} + """ ); } } diff --git a/CliFx/Infrastructure/DefaultTypeActivator.cs b/CliFx/Infrastructure/DefaultTypeActivator.cs index cd31e3f..9a27b77 100644 --- a/CliFx/Infrastructure/DefaultTypeActivator.cs +++ b/CliFx/Infrastructure/DefaultTypeActivator.cs @@ -20,11 +20,11 @@ public class DefaultTypeActivator : ITypeActivator catch (MemberAccessException ex) { throw CliFxException.InternalError( - $"Failed to create an instance of type `{type.FullName}`, could not access the constructor." + - Environment.NewLine + - "Default type activator is only capable of instantiating a type if it has a public parameterless constructor." + - Environment.NewLine + - "To fix this, either add a parameterless constructor to the type or configure a custom activator for the application.", + $""" + Failed to create an instance of type `{type.FullName}`, could not access the constructor. + Default type activator is only capable of instantiating a type if it has a public parameterless constructor. + To fix this, either add a parameterless constructor to the type or configure a custom activator for the application. + """, ex ); } diff --git a/CliFx/Infrastructure/DelegateTypeActivator.cs b/CliFx/Infrastructure/DelegateTypeActivator.cs index 64212f2..5fd8011 100644 --- a/CliFx/Infrastructure/DelegateTypeActivator.cs +++ b/CliFx/Infrastructure/DelegateTypeActivator.cs @@ -24,11 +24,11 @@ public class DelegateTypeActivator : ITypeActivator if (instance is null) { throw CliFxException.InternalError( - $"Failed to create an instance of type `{type.FullName}`, received instead." + - Environment.NewLine + - "To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return ." + - Environment.NewLine + - "If you are relying on a dependency container, this error may indicate that the specified type has not been registered." + $""" + Failed to create an instance of type `{type.FullName}`, received instead. + To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return . + If you are relying on a dependency container, this error may indicate that the specified type has not been registered. + """ ); } diff --git a/CliFx/Schema/CommandSchema.cs b/CliFx/Schema/CommandSchema.cs index 97c87a3..33e0624 100644 --- a/CliFx/Schema/CommandSchema.cs +++ b/CliFx/Schema/CommandSchema.cs @@ -129,15 +129,13 @@ internal partial class CommandSchema if (schema is null) { throw CliFxException.InternalError( - $"Type `{type.FullName}` is not a valid command type." + - Environment.NewLine + - "In order to be a valid command type, it must:" + - Environment.NewLine + - $"- Implement `{typeof(ICommand).FullName}`" + - Environment.NewLine + - $"- Be annotated with `{typeof(CommandAttribute).FullName}`" + - Environment.NewLine + - "- Not be an abstract class" + $""" + Type `{type.FullName}` is not a valid command type. + In order to be a valid command type, it must: + - Implement `{typeof(ICommand).FullName}` + - Be annotated with `{typeof(CommandAttribute).FullName}` + - Not be an abstract class + """ ); } diff --git a/CliFx/Utils/StackFrame.cs b/CliFx/Utils/StackFrame.cs index e9ce448..18a193a 100644 --- a/CliFx/Utils/StackFrame.cs +++ b/CliFx/Utils/StackFrame.cs @@ -96,9 +96,10 @@ internal partial class StackFrame // If parsing fails, we include the original stacktrace in the // exception so that it's shown to the user. throw new FormatException( - "Could not parse stacktrace:" + - Environment.NewLine + - stackTrace + $""" + Could not parse stacktrace: + {stackTrace} + """ ); }