More raw string literals

This commit is contained in:
Oleksii Holub
2022-12-08 03:33:10 +02:00
parent 15150cb3ed
commit bd29ad31cc
7 changed files with 73 additions and 74 deletions

View File

@@ -73,9 +73,10 @@ internal class AnalyzerAssertions : ReferenceTypeAssertions<DiagnosticAnalyzer,
if (compilationErrors.Any()) if (compilationErrors.Any())
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"Failed to compile code." + $"""
Environment.NewLine + Failed to compile code.
string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString())) {string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))}
"""
); );
} }

View File

@@ -77,9 +77,10 @@ internal static class DynamicCommandBuilder
if (compilationErrors.Any()) if (compilationErrors.Any())
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"Failed to compile code." + $"""
Environment.NewLine + Failed to compile code.
string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString())) {string.Join(Environment.NewLine, compilationErrors.Select(e => e.ToString()))}
"""
); );
} }
@@ -95,9 +96,10 @@ internal static class DynamicCommandBuilder
if (emitErrors.Any()) if (emitErrors.Any())
{ {
throw new InvalidOperationException( throw new InvalidOperationException(
"Failed to emit code." + $"""
Environment.NewLine + Failed to emit code.
string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString())) {string.Join(Environment.NewLine, emitErrors.Select(e => e.ToString()))}
"""
); );
} }

View File

@@ -99,11 +99,11 @@ internal class CommandBinder
} }
throw CliFxException.InternalError( throw CliFxException.InternalError(
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." + $"""
Environment.NewLine + {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}`." + 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.
"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( throw CliFxException.InternalError(
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has an unsupported underlying property type." + $"""
Environment.NewLine + {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}`." + 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.
"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; : ex.Message;
throw CliFxException.UserError( throw CliFxException.UserError(
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s):" + $"""
Environment.NewLine + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} cannot be set from the provided argument(s):
rawValues.Select(v => '<' + v + '>').JoinToString(" ") + {rawValues.Select(v => '<' + v + '>').JoinToString(" ")}
Environment.NewLine + Error: {errorMessage}
$"Error: {errorMessage}", """,
ex ex
); );
} }
// Mismatch (scalar but too many values) // Mismatch (scalar but too many values)
throw CliFxException.UserError( throw CliFxException.UserError(
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple:" + $"""
Environment.NewLine + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} expects a single argument, but provided with multiple:
rawValues.Select(v => '<' + v + '>').JoinToString(" ") {rawValues.Select(v => '<' + v + '>').JoinToString(" ")}
"""
); );
} }
@@ -202,11 +203,11 @@ internal class CommandBinder
if (errors.Any()) if (errors.Any())
{ {
throw CliFxException.UserError( throw CliFxException.UserError(
$"{memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value." + $"""
Environment.NewLine + {memberSchema.GetKind()} {memberSchema.GetFormattedIdentifier()} has been provided with an invalid value.
"Error(s):" + Error(s):
Environment.NewLine + {errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine)}
errors.Select(e => "- " + e.Message).JoinToString(Environment.NewLine) """
); );
} }
} }
@@ -264,22 +265,20 @@ internal class CommandBinder
if (remainingParameterInputs.Any()) if (remainingParameterInputs.Any())
{ {
throw CliFxException.UserError( throw CliFxException.UserError(
"Unexpected parameter(s):" + $"""
Environment.NewLine + Unexpected parameter(s):
remainingParameterInputs {remainingParameterInputs.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")}
.Select(p => p.GetFormattedIdentifier()) """
.JoinToString(" ")
); );
} }
if (remainingRequiredParameterSchemas.Any()) if (remainingRequiredParameterSchemas.Any())
{ {
throw CliFxException.UserError( throw CliFxException.UserError(
"Missing required parameter(s):" + $"""
Environment.NewLine + Missing required parameter(s):
remainingRequiredParameterSchemas {remainingRequiredParameterSchemas.Select(p => p.GetFormattedIdentifier()).JoinToString(" ")}
.Select(p => p.GetFormattedIdentifier()) """
.JoinToString(" ")
); );
} }
} }
@@ -337,22 +336,20 @@ internal class CommandBinder
if (remainingOptionInputs.Any()) if (remainingOptionInputs.Any())
{ {
throw CliFxException.UserError( throw CliFxException.UserError(
"Unrecognized option(s):" + $"""
Environment.NewLine + Unrecognized option(s):
remainingOptionInputs {remainingOptionInputs.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")}
.Select(o => o.GetFormattedIdentifier()) """
.JoinToString(", ")
); );
} }
if (remainingRequiredOptionSchemas.Any()) if (remainingRequiredOptionSchemas.Any())
{ {
throw CliFxException.UserError( throw CliFxException.UserError(
"Missing required option(s):" + $"""
Environment.NewLine + Missing required option(s):
remainingRequiredOptionSchemas {remainingRequiredOptionSchemas.Select(o => o.GetFormattedIdentifier()).JoinToString(", ")}
.Select(o => o.GetFormattedIdentifier()) """
.JoinToString(", ")
); );
} }
} }

View File

@@ -20,11 +20,11 @@ public class DefaultTypeActivator : ITypeActivator
catch (MemberAccessException ex) catch (MemberAccessException ex)
{ {
throw CliFxException.InternalError( throw CliFxException.InternalError(
$"Failed to create an instance of type `{type.FullName}`, could not access the constructor." + $"""
Environment.NewLine + 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." + 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.
"To fix this, either add a parameterless constructor to the type or configure a custom activator for the application.", """,
ex ex
); );
} }

View File

@@ -24,11 +24,11 @@ public class DelegateTypeActivator : ITypeActivator
if (instance is null) if (instance is null)
{ {
throw CliFxException.InternalError( throw CliFxException.InternalError(
$"Failed to create an instance of type `{type.FullName}`, received <null> instead." + $"""
Environment.NewLine + Failed to create an instance of type `{type.FullName}`, received <null> instead.
"To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return <null>." + To fix this, ensure that the provided type activator is configured correctly, as it's not expected to return <null>.
Environment.NewLine + If you are relying on a dependency container, this error may indicate that the specified type has not been registered.
"If you are relying on a dependency container, this error may indicate that the specified type has not been registered." """
); );
} }

View File

@@ -129,15 +129,13 @@ internal partial class CommandSchema
if (schema is null) if (schema is null)
{ {
throw CliFxException.InternalError( throw CliFxException.InternalError(
$"Type `{type.FullName}` is not a valid command type." + $"""
Environment.NewLine + Type `{type.FullName}` is not a valid command type.
"In order to be a valid command type, it must:" + In order to be a valid command type, it must:
Environment.NewLine + - Implement `{typeof(ICommand).FullName}`
$"- Implement `{typeof(ICommand).FullName}`" + - Be annotated with `{typeof(CommandAttribute).FullName}`
Environment.NewLine + - Not be an abstract class
$"- Be annotated with `{typeof(CommandAttribute).FullName}`" + """
Environment.NewLine +
"- Not be an abstract class"
); );
} }

View File

@@ -96,9 +96,10 @@ internal partial class StackFrame
// If parsing fails, we include the original stacktrace in the // If parsing fails, we include the original stacktrace in the
// exception so that it's shown to the user. // exception so that it's shown to the user.
throw new FormatException( throw new FormatException(
"Could not parse stacktrace:" + $"""
Environment.NewLine + Could not parse stacktrace:
stackTrace {stackTrace}
"""
); );
} }