From 40f5f0111ea0883d41c03d6adbb0a7c399d89798 Mon Sep 17 00:00:00 2001
From: "deepsource-autofix[bot]"
<62050782+deepsource-autofix[bot]@users.noreply.github.com>
Date: Wed, 27 Dec 2023 10:16:33 +0000
Subject: [PATCH] style: format code with dotnet-format
This commit fixes the style issues introduced in 8935ec8 according to the output
from dotnet-format.
Details: None
---
src/Constants.cs | 369 ++++++++++++++++++++++++++---------------------
1 file changed, 201 insertions(+), 168 deletions(-)
diff --git a/src/Constants.cs b/src/Constants.cs
index 1e07548..67f9ac6 100644
--- a/src/Constants.cs
+++ b/src/Constants.cs
@@ -61,202 +61,235 @@ internal static partial class Constants
"""";
private const string GeneratedCodeAttributesList =
- $"[GeneratedCode(\"{ThisAssemblyName}\", \"{RegexDtoGeneratorVersion}\"), CompilerGenerated]";
-
- private const string RegexDtoAttributeDeclaration = $$$""""
+ $"[GeneratedCode(\"{ThisAssemblyName}\", \"{RegexDtoGeneratorVersion}\"), CompilerGenerated]";
+
+private const string RegexDtoAttributeDeclaration = $$$""""
[AttributeUsage(@Class | @Struct, Inherited = false, AllowMultiple = false)]
- {{{GeneratedCodeAttributesList}}}
- internal sealed class RegexDtoAttribute(
- #if NET7_0_OR_GREATER
+ {{{GeneratedCodeAttributesList
+}}}
+ internal sealed class RegexDtoAttribute(
+#if NET7_0_OR_GREATER
[@StringSyntax(StringSyntax.Regex)]
- #endif
- string Regex, System.Type? BaseType = null, RegexOptions RegexOptions = Compiled | CultureInvariant | ExplicitCapture | IgnoreCase | IgnorePatternWhitespace | Singleline) : System.Attribute
+#endif
+ string Regex, System.Type ? BaseType = null, RegexOptions RegexOptions = Compiled | CultureInvariant | ExplicitCapture | IgnoreCase | IgnorePatternWhitespace | Singleline) : System.Attribute
{
- public string Regex { get; } = Regex;
- public System.Type? BaseType { get; } = BaseType;
- public RegexOptions RegexOptions { get; } = RegexOptions;
+ public string Regex { get; } = Regex;
+public System.Type? BaseType { get; } = BaseType;
+public RegexOptions RegexOptions { get; } = RegexOptions;
}
- """";
-
- private const string RegexDtoBaseTypeDeclaration = $$$""""
+ """";
+
+private const string RegexDtoBaseTypeDeclaration = $$$""""
namespace {{ namespace_name }}
- {
- {{{GeneratedCodeAttributesList}}}
- public abstract partial {{ target_data_structure_type }} {{ type_name }}Base {{ if base_type != "" }} : {{ base_type ~}}{{ end }}
- {
- /// The default
- /// (RegexOptions)({{ regex_options | string.replace "," " | " }})
- const RegexOptions RegexOptions = (RegexOptions)({{ regex_options | string.replace "," " | " }});
-
+ {
+ { { { GeneratedCodeAttributesList} } }
+ public abstract partial
+{ { target_data_structure_type } }
+{ { type_name } }
+Base
+{ { if base_type != "" } } : { { base_type ~} }
+{ { end } }
+{
+ /// The default
+ /// (RegexOptions)({{ regex_options | string.replace "," " | " }})
+ const RegexOptions RegexOptions = (RegexOptions)({ { regex_options | string.replace "," " | " } });
+
#if NET7_0_OR_GREATER
[@StringSyntax(StringSyntax.Regex)]
- #endif
- public const string RegexString = @"{{ regex }}";
-
- // #if NET7_0_OR_GREATER
- // [GeneratedRegex(RegexString, RegexOptions)]
- // public static partial Regex Regex();
- // #else
- private static readonly Regex _regex = new (RegexString, RegexOptions);
- /// The that will be used to validate and recognize the DTO
- public static Regex Regex() => _regex;
- // #endif
-
- public {{ if is_class }}virtual{{ end }} string OriginalString { get; init; }
-
- {{ properties_declarations }}
-
- {{ parse_declaration }}
-
- {{ constructor_declaration }}
+#endif
+public const string RegexString = @"{{ regex }}";
+
+// #if NET7_0_OR_GREATER
+// [GeneratedRegex(RegexString, RegexOptions)]
+// public static partial Regex Regex();
+// #else
+private static readonly Regex _regex = new(RegexString, RegexOptions);
+/// The that will be used to validate and recognize the DTO
+public static Regex Regex() => _regex;
+// #endif
+
+public
+{ { if is_class } }
+virtual
+{ { end } }
+string OriginalString { get; init; }
+
+{ { properties_declarations } }
+
+{ { parse_declaration } }
+
+{ { constructor_declaration } }
}
}
- """";
-
- private const string RegexDtoTypeDeclaration = $$$$""""
+ """";
+
+private const string RegexDtoTypeDeclaration = $$$$""""
namespace {{ namespace_name }}
- {
- {{{{GeneratedCodeAttributesList}}}}
- public partial {{ target_data_structure_type }} {{ type_name }} {{ if base_type != "" }} : {{ base_type ~}}{{ end }}
- {
- const RegexOptions RegexOptions = (RegexOptions)({{ regex_options | string.replace "," " | " }});
-
+ {
+ { { { { GeneratedCodeAttributesList} } } }
+ public partial
+{ { target_data_structure_type } }
+{ { type_name } }
+{ { if base_type != "" } } : { { base_type ~} }
+{ { end } }
+{
+ const RegexOptions RegexOptions = (RegexOptions)({ { regex_options | string.replace "," " | " } });
+
#if NET7_0_OR_GREATER
[@StringSyntax(StringSyntax.Regex)]
- #endif
- /// The regex string that will be used to validate and recognize the DTO
- public const string RegexString = @"{{ regex }}";
-
- // #if NET7_0_OR_GREATER
- // [GeneratedRegex(RegexString, RegexOptions)]
- // public static partial Regex Regex();
- // #else
- private static readonly Regex _regex = new (RegexString, RegexOptions);
- /// The that will be used to validate and recognize the DTO
- public static {{ if base_type != "" }}new{{ end }} Regex Regex() => _regex;
- // #endif
-
- public {{ if is_class }}override{{ end }} string OriginalString { get; init; }
-
- {{ properties_declarations }}
-
- {{ parse_declaration }}
-
- {{ constructor_declaration }}
+#endif
+ /// The regex string that will be used to validate and recognize the DTO
+public const string RegexString = @"{{ regex }}";
+
+// #if NET7_0_OR_GREATER
+// [GeneratedRegex(RegexString, RegexOptions)]
+// public static partial Regex Regex();
+// #else
+private static readonly Regex _regex = new(RegexString, RegexOptions);
+/// The that will be used to validate and recognize the DTO
+public static
+{ { if base_type != "" } }
+new {{ end }} Regex Regex() => _regex;
+// #endif
+
+public
+{ { if is_class } }
+override
+{ { end } }
+string OriginalString { get; init; }
+
+{ { properties_declarations } }
+
+{ { parse_declaration } }
+
+{ { constructor_declaration } }
}
}
- """";
-
- private const string RegexDtoParseDeclaration = """
+ """";
+
+private const string RegexDtoParseDeclaration = """
/// Parses the string into an instance of the DTO
/// The to parse
/// The parsed DTO
- public static {{ type_name }} Parse(string s)
- {
- return new {{ type_name }}(s);
+public static
+{ { type_name } }
+Parse(string s)
+ {
+ return new {{ type_name }
+} (s);
}
""";
private const string RegexDtoConstructorDeclaration = """
/// Instantiates a new, empty
- {{ parameterless_constructor_visibility }} {{ type_name }} () { }
-
- /// Instantiates a new and parses the
- {{ parameterized_constructor_visibility }} {{ type_name }} (string s)
- {
- var match = Regex().Match(s);
- if (!match.Success)
- {
- throw new ArgumentException($"The string \"{s}\" does not match the regular expression \"{RegexString}\".", nameof(s));
- }
-
- {{~ for property in properties ~}}
- {{~ if property.is_nullable ~}}
- {{ property.name }} = string.IsNullOrEmpty(match.Groups["{{ property.name }}"]?.Value) ? null : ({{ property.type }}?)System.Convert.ChangeType(match.Groups["{{ property.name }}"]?.Value, typeof({{ property.type }}));
- {{~ else ~}}
- {{ property.name }} = ({{ property.type }})System.Convert.ChangeType(match.Groups["{{ property.name }}"]?.Value, typeof({{ property.type }}));
- {{~ end ~}}
- {{~ end ~}}
-
- OriginalString = s;
- }
- """;
+ { { parameterless_constructor_visibility } }
+{ { type_name } } () { }
+
+/// Instantiates a new and parses the
+{ { parameterized_constructor_visibility } }
+{ { type_name } } (string s)
+ {
+ var match = Regex().Match(s);
+ if (!match.Success)
+ {
+ throw new ArgumentException($"The string \"{s}\" does not match the regular expression \"{RegexString}\".", nameof(s));
+ }
+
+ { { ~ for property in properties ~} }
+ { { ~ if property.is_nullable ~} }
+ { { property.name } } = string.IsNullOrEmpty(match.Groups["{{ property.name }}"]?.Value) ? null : ({ { property.type } }?)System.Convert.ChangeType(match.Groups["{{ property.name }}"]?.Value, typeof({ { property.type } }));
+ { { ~ else ~} }
+ { { property.name } } = ({ { property.type } })System.Convert.ChangeType(match.Groups["{{ property.name }}"]?.Value, typeof({ { property.type } }));
+ { { ~end ~} }
+ { { ~end ~} }
+
+ OriginalString = s;
+}
+""";
private const string RegexDtoPropertyDeclaration = """
- {{~ if is_nullable ~}}
- public {{ overridability }} {{ type }}? {{ name }} { get; set; }
- {{~ else ~}}
- public {{ overridability }} {{ type }} {{ name }} { get; set; }
- {{~end ~}}
- """;
+ { { ~ if is_nullable ~} }
+public
+{ { overridability } }
+{ { type } }?
+{ { name } }
+{ get; set; }
+{ { ~ else ~} }
+public
+{ { overridability } }
+{ { type } }
+{ { name } }
+{ get; set; }
+{ { ~end ~} }
+""";
private const string RegexDtoPropertiesDeclaration = $$$"""
- {{~ for property in properties ~}}
- {{{RegexDtoPropertyDeclaration}}}
- {{~end ~}}
- """;
+ { { ~ for property in properties ~} }
+{ { { RegexDtoPropertyDeclaration} } }
+{ { ~end ~} }
+""";
private static readonly Template RegexDtoDeclarationTemplate = Parse(
RegexDtoTypeDeclaration,
nameof(RegexDtoTypeDeclaration)
- );
-
- private static readonly Template RegexDtoBaseTypeDeclarationTemplate = Parse(
- RegexDtoBaseTypeDeclaration,
- nameof(RegexDtoBaseTypeDeclaration)
- );
-
- private static readonly Template RegexDtoParseDeclarationTemplate = Parse(
- RegexDtoParseDeclaration,
- nameof(RegexDtoParseDeclaration)
- );
-
- private static readonly Template RegexDtoPropertiesDeclarationTemplate = Parse(
- RegexDtoPropertiesDeclaration,
- nameof(RegexDtoPropertiesDeclaration)
- );
-
- private static readonly Template RegexDtoConstructorDeclarationTemplate = Parse(
- RegexDtoConstructorDeclaration,
- nameof(RegexDtoConstructorDeclaration)
- );
-
- private static readonly Template RegexDtoAttributeDeclarationTemplate = Parse(
- RegexDtoAttributeDeclaration,
- nameof(RegexDtoAttributeDeclaration)
- );
- private static readonly Template RegexDtoPropertyDeclarationTemplate = Parse(
- RegexDtoPropertyDeclaration,
- nameof(RegexDtoPropertyDeclaration)
- );
-
- private static Template HeaderTemplate => Parse(Header, nameof(Header));
-
- public static string RenderedRegexDtoAttributeDeclaration =>
- HeaderTemplate.Render(new FilenameAndTimestamp(RegexDtoAttributeFilename))
- + RegexDtoAttributeDeclarationTemplate.Render();
-
- public static string RenderDtoConstructorDeclaration(
- RegexDtoConstructorDeclarationModel model
- ) => RegexDtoConstructorDeclarationTemplate.Render(model);
-
- public static string RenderRegexDtoPropertiesDeclaration(
- RegexDtoPropertiesDeclarationModel model
- ) => RegexDtoPropertiesDeclarationTemplate.Render(model);
-
- public static string RenderRegexDtoParseDeclaration(RegexDtoPropertiesDeclarationModel model) =>
- RegexDtoParseDeclarationTemplate.Render(model);
-
- public static string RenderRegexDtoDeclaration(RegexDtoDeclarationModel model) =>
- RegexDtoDeclarationTemplate.Render(model);
-
- public static string RenderHeader(RegexDtoFileModel model) => HeaderTemplate.Render(model);
-
- public static string RenderRegexDtoBaseTypeDeclaration(
- RegexDtoBaseTypeDeclarationModel model
- ) => RegexDtoBaseTypeDeclarationTemplate.Render(model);
-
- public static string RenderRegexDtoPropertyDeclaration(
- RegexDtoPropertyDeclarationModel model
- ) => RegexDtoPropertyDeclarationTemplate.Render(model);
+ );
+
+private static readonly Template RegexDtoBaseTypeDeclarationTemplate = Parse(
+ RegexDtoBaseTypeDeclaration,
+ nameof(RegexDtoBaseTypeDeclaration)
+);
+
+private static readonly Template RegexDtoParseDeclarationTemplate = Parse(
+ RegexDtoParseDeclaration,
+ nameof(RegexDtoParseDeclaration)
+);
+
+private static readonly Template RegexDtoPropertiesDeclarationTemplate = Parse(
+ RegexDtoPropertiesDeclaration,
+ nameof(RegexDtoPropertiesDeclaration)
+);
+
+private static readonly Template RegexDtoConstructorDeclarationTemplate = Parse(
+ RegexDtoConstructorDeclaration,
+ nameof(RegexDtoConstructorDeclaration)
+);
+
+private static readonly Template RegexDtoAttributeDeclarationTemplate = Parse(
+ RegexDtoAttributeDeclaration,
+ nameof(RegexDtoAttributeDeclaration)
+);
+private static readonly Template RegexDtoPropertyDeclarationTemplate = Parse(
+ RegexDtoPropertyDeclaration,
+ nameof(RegexDtoPropertyDeclaration)
+);
+
+private static Template HeaderTemplate => Parse(Header, nameof(Header));
+
+public static string RenderedRegexDtoAttributeDeclaration =>
+ HeaderTemplate.Render(new FilenameAndTimestamp(RegexDtoAttributeFilename))
+ + RegexDtoAttributeDeclarationTemplate.Render();
+
+public static string RenderDtoConstructorDeclaration(
+ RegexDtoConstructorDeclarationModel model
+) => RegexDtoConstructorDeclarationTemplate.Render(model);
+
+public static string RenderRegexDtoPropertiesDeclaration(
+ RegexDtoPropertiesDeclarationModel model
+) => RegexDtoPropertiesDeclarationTemplate.Render(model);
+
+public static string RenderRegexDtoParseDeclaration(RegexDtoPropertiesDeclarationModel model) =>
+ RegexDtoParseDeclarationTemplate.Render(model);
+
+public static string RenderRegexDtoDeclaration(RegexDtoDeclarationModel model) =>
+ RegexDtoDeclarationTemplate.Render(model);
+
+public static string RenderHeader(RegexDtoFileModel model) => HeaderTemplate.Render(model);
+
+public static string RenderRegexDtoBaseTypeDeclaration(
+ RegexDtoBaseTypeDeclarationModel model
+) => RegexDtoBaseTypeDeclarationTemplate.Render(model);
+
+public static string RenderRegexDtoPropertyDeclaration(
+ RegexDtoPropertyDeclarationModel model
+) => RegexDtoPropertyDeclarationTemplate.Render(model);
}