diff --git a/.editorconfig b/.editorconfig
index 59485ab..ee7278f 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -227,7 +227,7 @@ csharp_preserve_single_line_statements = true
##########################################
# Always have accessibility keyword
-dotnet_style_require_accessibility_modifiers = always:warning
+dotnet_style_require_accessibility_modifiers = for_non_interface_members:warning
# Use file scoped namespaces
csharp_style_namespace_declarations = file_scoped:warning
diff --git a/src/AutoCtor.Shared/AttributeSourceGenerator/Emitter.cs b/src/AutoCtor.Shared/AttributeSourceGenerator/Emitter.cs
index 2d0810f..016a2f5 100644
--- a/src/AutoCtor.Shared/AttributeSourceGenerator/Emitter.cs
+++ b/src/AutoCtor.Shared/AttributeSourceGenerator/Emitter.cs
@@ -31,18 +31,18 @@ public static SourceText GenerateSource()
using (source.StartBlock())
{
source.AppendLine("public AutoConstructAttribute(GuardSetting guard = GuardSetting.Default)");
- source.OpenBlock().CloseBlock();
+ source.StartBlock().Dispose();
}
source.AddCompilerGeneratedAttribute().AddGeneratedCodeAttribute();
source.AppendLine("[global::System.AttributeUsage(global::System.AttributeTargets.Method, AllowMultiple = false, Inherited = false)]");
source.AppendLine("internal sealed class AutoPostConstructAttribute : global::System.Attribute");
- source.OpenBlock().CloseBlock();
+ source.StartBlock().Dispose();
source.AddCompilerGeneratedAttribute().AddGeneratedCodeAttribute();
source.AppendLine("[global::System.AttributeUsage(global::System.AttributeTargets.Field | global::System.AttributeTargets.Property, AllowMultiple = false, Inherited = false)]");
source.AppendLine("internal sealed class AutoConstructIgnoreAttribute : global::System.Attribute");
- source.OpenBlock().CloseBlock();
+ source.StartBlock().Dispose();
}
source.AppendLine("#endif");
diff --git a/src/AutoCtor.Shared/AutoConstructSourceGenerator/Emitter.cs b/src/AutoCtor.Shared/AutoConstructSourceGenerator/Emitter.cs
index fd7872c..d1a1d25 100644
--- a/src/AutoCtor.Shared/AutoConstructSourceGenerator/Emitter.cs
+++ b/src/AutoCtor.Shared/AutoConstructSourceGenerator/Emitter.cs
@@ -114,8 +114,8 @@ private static (SourceText?, ParameterList?) GenerateSource(
.AddDebuggerNonUserCodeAttribute();
source.AppendIndent()
- .Append($"public {type.Name}({parameters})")
- .Append(parameters.HasBaseParameters, $" : base({parameters:B})")
+ .Append($"public {type.Name}({parameters.ParameterDeclarations:commaindent})")
+ .Append(parameters.HasBaseParameters, $" : base({parameters.BaseParameters:commaindent})")
.AppendLine();
using (source.StartBlock())
@@ -138,7 +138,7 @@ private static (SourceText?, ParameterList?) GenerateSource(
}
if (postCtorMethod.HasValue)
{
- source.AppendLine($"{postCtorMethod.Value.Name}({parameters:P});");
+ source.AppendLine($"{postCtorMethod.Value.Name}({parameters.Parameters:commaindent});");
}
}
}
diff --git a/src/AutoCtor.Shared/AutoCtor.Shared.projitems b/src/AutoCtor.Shared/AutoCtor.Shared.projitems
index 458deb2..85ea515 100644
--- a/src/AutoCtor.Shared/AutoCtor.Shared.projitems
+++ b/src/AutoCtor.Shared/AutoCtor.Shared.projitems
@@ -13,13 +13,18 @@
+
+
+
+
-
+
+
@@ -30,4 +35,4 @@
-
+
\ No newline at end of file
diff --git a/src/AutoCtor.Shared/Helpers/CodeBuilder.Block.cs b/src/AutoCtor.Shared/Helpers/CodeBuilder.Block.cs
new file mode 100644
index 0000000..2d52efc
--- /dev/null
+++ b/src/AutoCtor.Shared/Helpers/CodeBuilder.Block.cs
@@ -0,0 +1,27 @@
+internal partial class CodeBuilder
+{
+ public IDisposable StartBlock() => StartIndent("{", "}");
+ public IDisposable StartBlock(string line)
+ {
+ AppendLine(line);
+ return StartIndent("{", "}");
+ }
+
+ public IDisposable StartIndent(string? startLine = null, string? endLine = null)
+ {
+ if (!string.IsNullOrEmpty(startLine))
+ AppendLine(startLine!);
+ IncreaseIndent();
+ return new DetentDisposable(this, endLine);
+ }
+
+ private readonly struct DetentDisposable(CodeBuilder codeBuilder, string? endLine) : IDisposable
+ {
+ public void Dispose()
+ {
+ codeBuilder.DecreaseIndent();
+ if (!string.IsNullOrEmpty(endLine))
+ codeBuilder.AppendLine(endLine!);
+ }
+ }
+}
diff --git a/src/AutoCtor.Shared/Helpers/CodeBuilder.InterpolatedStringHandler.cs b/src/AutoCtor.Shared/Helpers/CodeBuilder.InterpolatedStringHandler.cs
new file mode 100644
index 0000000..bcd43bd
--- /dev/null
+++ b/src/AutoCtor.Shared/Helpers/CodeBuilder.InterpolatedStringHandler.cs
@@ -0,0 +1,127 @@
+using System.Runtime.CompilerServices;
+
+#pragma warning disable CS9113 // Parameter is unread.
+#pragma warning disable IDE0060 // Remove unused parameter
+
+internal partial class CodeBuilder
+{
+ public CodeBuilder Append(
+ [InterpolatedStringHandlerArgument("")]
+ ref CodeBuilderInterpolatedStringHandler builder) => this;
+
+ public CodeBuilder Append(bool enabled,
+ [InterpolatedStringHandlerArgument("", nameof(enabled))]
+ ref ConditionalCodeBuilderInterpolatedStringHandler builder) => this;
+
+ public CodeBuilder AppendLineRaw(
+ [InterpolatedStringHandlerArgument("")]
+ ref CodeBuilderInterpolatedStringHandler builder) => AppendLine();
+
+ public CodeBuilder AppendLineRaw(bool enabled,
+ [InterpolatedStringHandlerArgument("", nameof(enabled))]
+ ref ConditionalCodeBuilderInterpolatedStringHandler builder) => enabled ? AppendLine() : this;
+
+ public CodeBuilder AppendLine(
+ [InterpolatedStringHandlerArgument("")]
+ IndentedCodeBuilderInterpolatedStringHandler builder) => AppendLine();
+
+ public CodeBuilder AppendLine(bool enabled,
+ [InterpolatedStringHandlerArgument("", nameof(enabled))]
+ ConditionalIndentedCodeBuilderInterpolatedStringHandler builder) => enabled ? AppendLine() : this;
+
+ private void AppendFormatted(IEnumerable items, string? format)
+ {
+ if (format == "comma")
+ AppendCommaSeparated(items);
+
+ if (format == "commaindent")
+ AppendCommaIndented(items);
+ }
+
+ private void AppendCommaSeparated(IEnumerable items)
+ {
+ var comma = false;
+ foreach (var item in items)
+ {
+ if (comma)
+ Append(", ");
+ comma = true;
+ Append(item);
+ }
+ }
+
+ private void AppendCommaIndented(IEnumerable items)
+ {
+ var count = items.Count();
+
+ if (count < 3)
+ {
+ AppendCommaSeparated(items);
+ return;
+ }
+
+ AppendLine();
+ IncreaseIndent();
+ var comma = false;
+ foreach (var item in items)
+ {
+ if (comma)
+ Append(",").AppendLine();
+ comma = true;
+ AppendIndent().Append(item);
+ }
+ AppendLine();
+ DecreaseIndent();
+ AppendIndent();
+ }
+
+ [InterpolatedStringHandler]
+ internal readonly struct CodeBuilderInterpolatedStringHandler(
+ int literalLength, int formattedCount, CodeBuilder codeBuilder)
+ {
+ public readonly void AppendLiteral(string s) => codeBuilder.Append(s);
+ public readonly void AppendFormatted(string s) => codeBuilder.Append(s);
+ public readonly void AppendFormatted(IEnumerable items, string? format)
+ => codeBuilder.AppendFormatted(items, format);
+ }
+
+ [InterpolatedStringHandler]
+ internal readonly struct ConditionalCodeBuilderInterpolatedStringHandler(
+ int literalLength, int formattedCount, CodeBuilder codeBuilder, bool enabled)
+ {
+ public readonly bool AppendLiteral(string s) { if (enabled) codeBuilder.Append(s); return enabled; }
+ public readonly bool AppendFormatted(string s) { if (enabled) codeBuilder.Append(s); return enabled; }
+ public readonly bool AppendFormatted(IEnumerable items, string? format)
+ { if (enabled) codeBuilder.AppendFormatted(items, format); return enabled; }
+ }
+
+ [InterpolatedStringHandler]
+ internal class IndentedCodeBuilderInterpolatedStringHandler(
+ int literalLength, int formattedCount, CodeBuilder codeBuilder)
+ {
+ private bool _hasIndented;
+
+ private void EnsureIndent()
+ {
+ if (_hasIndented) return;
+ codeBuilder.AppendIndent();
+ _hasIndented = true;
+ }
+
+ public void AppendLiteral(string s) { EnsureIndent(); codeBuilder.Append(s); }
+ public void AppendFormatted(string s) { EnsureIndent(); codeBuilder.Append(s); }
+ public void AppendFormatted(IEnumerable items, string? format)
+ { EnsureIndent(); codeBuilder.AppendFormatted(items, format); }
+ }
+
+ [InterpolatedStringHandler]
+ internal class ConditionalIndentedCodeBuilderInterpolatedStringHandler(
+ int literalLength, int formattedCount, CodeBuilder codeBuilder, bool enabled)
+ : IndentedCodeBuilderInterpolatedStringHandler(literalLength, formattedCount, codeBuilder)
+ {
+ public new bool AppendLiteral(string s) { if (enabled) base.AppendLiteral(s); return enabled; }
+ public new bool AppendFormatted(string s) { if (enabled) base.AppendFormatted(s); return enabled; }
+ public new bool AppendFormatted(IEnumerable items, string? format)
+ { if (enabled) base.AppendFormatted(items, format); return enabled; }
+ }
+}
diff --git a/src/AutoCtor.Shared/Helpers/CodeBuilder.PartialType.cs b/src/AutoCtor.Shared/Helpers/CodeBuilder.PartialType.cs
new file mode 100644
index 0000000..148addf
--- /dev/null
+++ b/src/AutoCtor.Shared/Helpers/CodeBuilder.PartialType.cs
@@ -0,0 +1,33 @@
+internal partial class CodeBuilder
+{
+ public IDisposable StartPartialType(IPartialTypeModel typeModel)
+ {
+ if (!string.IsNullOrEmpty(typeModel.Namespace))
+ {
+ AppendLine($"namespace {typeModel.Namespace!}");
+ AppendLine("{");
+ IncreaseIndent();
+ }
+
+ for (var i = 0; i < typeModel.TypeDeclarations.Count; i++)
+ {
+ AppendLine(typeModel.TypeDeclarations[i]);
+ AppendLine("{");
+ IncreaseIndent();
+ }
+
+ return new CloseBlockDisposable(this, typeModel.TypeDeclarations.Count + (typeModel.Namespace != null ? 1 : 0));
+ }
+
+ private readonly struct CloseBlockDisposable(CodeBuilder codeBuilder, int count) : IDisposable
+ {
+ public void Dispose()
+ {
+ for (var i = 0; i < count; i++)
+ {
+ codeBuilder.DecreaseIndent();
+ codeBuilder.AppendLine("}");
+ }
+ }
+ }
+}
diff --git a/src/AutoCtor.Shared/Helpers/CodeBuilder.Templates.cs b/src/AutoCtor.Shared/Helpers/CodeBuilder.Templates.cs
new file mode 100644
index 0000000..c8b8f28
--- /dev/null
+++ b/src/AutoCtor.Shared/Helpers/CodeBuilder.Templates.cs
@@ -0,0 +1,40 @@
+using System.Reflection;
+
+internal partial class CodeBuilder
+{
+ private static readonly string s_assemblyName;
+ private static readonly string s_version;
+ private static readonly string? s_packageProjectUrl;
+ private static readonly string? s_gitSha;
+
+ static CodeBuilder()
+ {
+ var assembly = Assembly.GetAssembly(typeof(CodeBuilder));
+ s_assemblyName = assembly?.GetCustomAttribute()?.Title ?? "Untitled";
+ s_version = assembly?.GetCustomAttribute()?.Version ?? "0.0.0.0";
+ var metadata = assembly?.GetCustomAttributes()?.ToDictionary(m => m.Key, m => m.Value);
+ if (metadata != null)
+ {
+ metadata.TryGetValue("PackageProjectUrl", out s_packageProjectUrl);
+ metadata.TryGetValue("GitSha", out s_gitSha);
+ }
+ }
+
+ public CodeBuilder AddCompilerGeneratedAttribute()
+ => AppendLine("[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]");
+
+ public CodeBuilder AddDebuggerNonUserCodeAttribute()
+ => AppendLine("[global::System.Diagnostics.DebuggerNonUserCodeAttribute]");
+
+ public CodeBuilder AddGeneratedCodeAttribute()
+ => AppendLine($"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{s_assemblyName}\", \"{s_version}\")]");
+
+ public CodeBuilder AppendHeader() =>
+ AppendLine($"//------------------------------------------------------------------------------")
+ .AppendLine($"// ")
+ .AppendLine(!string.IsNullOrEmpty(s_packageProjectUrl), $"// This code was generated by {s_packageProjectUrl!}")
+ .AppendLine($"// Version: {s_version}")
+ .AppendLine(!string.IsNullOrEmpty(s_gitSha), $"// SHA: {s_gitSha!}")
+ .AppendLine($"// ")
+ .AppendLine($"//------------------------------------------------------------------------------");
+}
diff --git a/src/AutoCtor.Shared/Helpers/CodeBuilder.cs b/src/AutoCtor.Shared/Helpers/CodeBuilder.cs
index 4d4ab95..d4e0132 100644
--- a/src/AutoCtor.Shared/Helpers/CodeBuilder.cs
+++ b/src/AutoCtor.Shared/Helpers/CodeBuilder.cs
@@ -1,139 +1,26 @@
-using System.Reflection;
-using System.Text;
+using System.Text;
using Microsoft.CodeAnalysis.Text;
-internal interface IPartialTypeModel
+internal partial class CodeBuilder
{
- string? Namespace { get; }
- IReadOnlyList TypeDeclarations { get; }
-}
-
-internal class CodeBuilder
-{
- private static readonly string s_assemblyName;
- private static readonly string s_version;
- private static readonly string? s_packageProjectUrl;
- private static readonly string? s_gitSha;
-
- static CodeBuilder()
- {
- var assembly = Assembly.GetAssembly(typeof(CodeBuilder));
- s_assemblyName = assembly?.GetCustomAttribute()?.Title ?? "Untitled";
- s_version = assembly?.GetCustomAttribute()?.Version ?? "0.0.0.0";
- var metadata = assembly?.GetCustomAttributes()?.ToDictionary(m => m.Key, m => m.Value);
- if (metadata != null)
- {
- metadata.TryGetValue("PackageProjectUrl", out s_packageProjectUrl);
- metadata.TryGetValue("GitSha", out s_gitSha);
- }
- }
-
private readonly StringBuilder _stringBuilder = new();
private int _indent = 0;
- public CodeBuilder Append(string text)
- {
- _stringBuilder.Append(text);
- return this;
- }
-
- public CodeBuilder Append(bool enabled, string text)
- {
- if (enabled)
- _stringBuilder.Append(text);
- return this;
- }
-
- public CodeBuilder AppendIndent()
- {
- _stringBuilder.Append(Indent);
- return this;
- }
-
- public CodeBuilder AppendLine()
- {
- _stringBuilder.AppendLine();
- return this;
- }
-
- public CodeBuilder AppendLine(string line)
- {
- _stringBuilder.AppendLine(Indent + line);
- return this;
- }
-
- public void IncreaseIndent() { _indent++; }
- public void DecreaseIndent()
- {
- if (_indent > 0)
- {
- _indent--;
- }
- }
-
- public CodeBuilder OpenBlock()
- {
- AppendLine("{");
- IncreaseIndent();
- return this;
- }
- public CodeBuilder CloseBlock()
- {
- DecreaseIndent();
- AppendLine("}");
- return this;
- }
-
public char IndentChar { get; set; } = '\t';
public string Indent => new(IndentChar, _indent);
- public CodeBuilder AddCompilerGeneratedAttribute() => AppendLine(
- "[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]");
-
- public CodeBuilder AddDebuggerNonUserCodeAttribute() => AppendLine(
- "[global::System.Diagnostics.DebuggerNonUserCodeAttribute]");
-
- public CodeBuilder AddGeneratedCodeAttribute() => AppendLine($"[global::System.CodeDom.Compiler.GeneratedCodeAttribute(\"{s_assemblyName}\", \"{s_version}\")]");
-
- public CodeBuilder AppendHeader() =>
- AppendLine($"//------------------------------------------------------------------------------")
- .AppendLine($"// ")
- .AppendLine($"// This code was generated by {s_packageProjectUrl}")
- .AppendLine($"// Version: {s_version}")
- .AppendLine($"// SHA: {s_gitSha}")
- .AppendLine($"// ")
- .AppendLine($"//------------------------------------------------------------------------------");
+ public CodeBuilder IncreaseIndent() { _indent++; return this; }
+ public CodeBuilder DecreaseIndent() { if (_indent > 0) _indent--; return this; }
- public IDisposable StartPartialType(IPartialTypeModel typeModel)
- {
- if (!string.IsNullOrEmpty(typeModel.Namespace))
- {
- AppendLine($"namespace {typeModel.Namespace}");
- OpenBlock();
- }
-
- for (var i = 0; i < typeModel.TypeDeclarations.Count; i++)
- {
- AppendLine(typeModel.TypeDeclarations[i]);
- OpenBlock();
- }
-
- return new CloseBlockDisposable(this, typeModel.TypeDeclarations.Count + (typeModel.Namespace != null ? 1 : 0));
- }
-
- public IDisposable StartBlock(string? line = null)
- {
- if (!string.IsNullOrEmpty(line))
- AppendLine(line!);
- OpenBlock();
- return new CloseBlockDisposable(this, 1);
- }
+ public CodeBuilder Append(string text) { _stringBuilder.Append(text); return this; }
+ public CodeBuilder Append(bool enabled, string text) { if (enabled) _stringBuilder.Append(text); return this; }
+ public CodeBuilder AppendLine() { _stringBuilder.AppendLine(); return this; }
+ public CodeBuilder AppendLine(string line) { _stringBuilder.AppendLine(Indent + line); return this; }
+ public CodeBuilder AppendLine(bool enabled, string line) { if (enabled) _stringBuilder.AppendLine(Indent + line); return this; }
+ public CodeBuilder AppendLineRaw(string line) { _stringBuilder.AppendLine(line); return this; }
+ public CodeBuilder AppendLineRaw(bool enabled, string line) { if (enabled) _stringBuilder.AppendLine(line); return this; }
+ public CodeBuilder AppendIndent() { _stringBuilder.Append(Indent); return this; }
public static implicit operator SourceText(CodeBuilder codeBuilder)
=> SourceText.From(codeBuilder._stringBuilder.ToString(), Encoding.UTF8);
-
- private readonly struct CloseBlockDisposable(CodeBuilder codeBuilder, int count) : IDisposable
- {
- public void Dispose() { for (var i = 0; i < count; i++) codeBuilder.CloseBlock(); }
- }
}
diff --git a/src/AutoCtor.Shared/Helpers/GeneratorUtilities.cs b/src/AutoCtor.Shared/Helpers/GeneratorUtilities.cs
index c45c635..3d9484f 100644
--- a/src/AutoCtor.Shared/Helpers/GeneratorUtilities.cs
+++ b/src/AutoCtor.Shared/Helpers/GeneratorUtilities.cs
@@ -25,9 +25,6 @@ public static string ToParameterPrefix(this RefKind kind)
};
}
- public static string AsCommaSeparated(this IEnumerable items) =>
- string.Join(", ", items);
-
public static string EscapeKeywordIdentifier(this string identifier) =>
SyntaxFacts.IsKeywordKind(SyntaxFacts.GetKeywordKind(identifier)) ? "@" + identifier : identifier;
diff --git a/src/AutoCtor.Shared/Helpers/IsExternalInit.cs b/src/AutoCtor.Shared/Helpers/IsExternalInit.cs
deleted file mode 100644
index 274e9de..0000000
--- a/src/AutoCtor.Shared/Helpers/IsExternalInit.cs
+++ /dev/null
@@ -1,3 +0,0 @@
-namespace System.Runtime.CompilerServices;
-
-internal static class IsExternalInit;
diff --git a/src/AutoCtor.Shared/Helpers/Polyfill.cs b/src/AutoCtor.Shared/Helpers/Polyfill.cs
new file mode 100644
index 0000000..d052128
--- /dev/null
+++ b/src/AutoCtor.Shared/Helpers/Polyfill.cs
@@ -0,0 +1,36 @@
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices;
+
+// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/IsExternalInit.cs
+[EditorBrowsable(EditorBrowsableState.Never)]
+internal static class IsExternalInit { }
+
+// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerAttribute.cs
+/// Indicates the attributed type is to be used as an interpolated string handler.
+[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
+public sealed class InterpolatedStringHandlerAttribute : Attribute
+{
+ /// Initializes the .
+ public InterpolatedStringHandlerAttribute() { }
+}
+
+// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/InterpolatedStringHandlerArgumentAttribute.cs
+/// Indicates which arguments to a method involving an interpolated string handler should be passed to that handler.
+[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
+public sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
+{
+ /// Initializes a new instance of the class.
+ /// The name of the argument that should be passed to the handler.
+ /// The empty string may be used as the name of the receiver in an instance method.
+ public InterpolatedStringHandlerArgumentAttribute(string argument) => Arguments = [argument];
+
+ /// Initializes a new instance of the class.
+ /// The names of the arguments that should be passed to the handler.
+ /// The empty string may be used as the name of the receiver in an instance method.
+ public InterpolatedStringHandlerArgumentAttribute(params string[] arguments) => Arguments = arguments;
+
+ /// Gets the names of the arguments that should be passed to the handler.
+ /// The empty string may be used as the name of the receiver in an instance method.
+ public string[] Arguments { get; }
+}
diff --git a/src/AutoCtor.Shared/Models/IPartialTypeModel.cs b/src/AutoCtor.Shared/Models/IPartialTypeModel.cs
new file mode 100644
index 0000000..8e14f9a
--- /dev/null
+++ b/src/AutoCtor.Shared/Models/IPartialTypeModel.cs
@@ -0,0 +1,5 @@
+internal interface IPartialTypeModel
+{
+ string? Namespace { get; }
+ IReadOnlyList TypeDeclarations { get; }
+}
diff --git a/src/AutoCtor.Shared/Models/ParameterList.cs b/src/AutoCtor.Shared/Models/ParameterList.cs
index 8f45873..6499ffd 100644
--- a/src/AutoCtor.Shared/Models/ParameterList.cs
+++ b/src/AutoCtor.Shared/Models/ParameterList.cs
@@ -1,8 +1,7 @@
using System.Collections;
-using System.Globalization;
internal class ParameterList(IEnumerable fields, IEnumerable properties)
- : IEnumerable, IFormattable
+ : IEnumerable
{
private readonly Dictionary _memberToParameterMap
= fields.Concat(properties)
@@ -12,6 +11,11 @@ private readonly Dictionary _memberToParameterMap
private readonly List _postCtorParameters = [];
public bool HasBaseParameters => _parameters?.Any() == true;
+ public IEnumerable ParameterDeclarations => _uniqueNames.Select(u => $"{u.Key.Type} {u.Value}");
+ public IEnumerable Parameters => _postCtorParameters.Select(p => _uniqueNames[p]);
+ public IEnumerable BaseParameters => _parameters.Select(p => _uniqueNames[p]);
+
+ public string ParameterName(MemberModel f) => _uniqueNames[_memberToParameterMap[f]];
public void AddParameters(IEnumerable parameters)
=> _parameters.AddRange(parameters);
@@ -38,25 +42,9 @@ public void MakeUniqueNames()
}
}
- public string ParameterName(MemberModel f) => _uniqueNames[_memberToParameterMap[f]];
-
public IEnumerator GetEnumerator() => _parameters
.Concat(_memberToParameterMap.Values)
.Concat(_postCtorParameters)
.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
-
- public override string ToString() => ToString("G", CultureInfo.InvariantCulture);
- public string ToString(string format) => ToString(format, CultureInfo.InvariantCulture);
- public string ToString(string format, IFormatProvider provider)
- {
- if (string.IsNullOrEmpty(format)) format = "G";
- return format.ToUpperInvariant() switch
- {
- "G" => _uniqueNames.Select(u => $"{u.Key.Type} {u.Value}").AsCommaSeparated(),
- "B" => _parameters.Select(p => _uniqueNames[p]).AsCommaSeparated(),
- "P" => _postCtorParameters.Select(p => _uniqueNames[p]).AsCommaSeparated(),
- _ => throw new FormatException($"The {format} format string is not supported"),
- };
- }
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/BaseTest.ExamplesGeneratedCode#TheClass.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/BaseTest.ExamplesGeneratedCode#TheClass.g.verified.cs
index 430033b..6b7e878 100644
--- a/src/AutoCtor.Tests/Examples/Verified/BaseTest.ExamplesGeneratedCode#TheClass.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/BaseTest.ExamplesGeneratedCode#TheClass.g.verified.cs
@@ -9,7 +9,11 @@ partial class TheClass
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public TheClass(int number, string text, bool flag) : base(number, text)
+ public TheClass(
+ int number,
+ string text,
+ bool flag
+ ) : base(number, text)
{
this._flag = flag;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/ConflicingNames.ExamplesGeneratedCode#CClass.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/ConflicingNames.ExamplesGeneratedCode#CClass.g.verified.cs
index 47a0f0d..4c0ef46 100644
--- a/src/AutoCtor.Tests/Examples/Verified/ConflicingNames.ExamplesGeneratedCode#CClass.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/ConflicingNames.ExamplesGeneratedCode#CClass.g.verified.cs
@@ -9,7 +9,11 @@ partial class CClass
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public CClass(global::IServiceA service, global::IServiceB service0, global::IServiceC service1) : base(service, service0)
+ public CClass(
+ global::IServiceA service,
+ global::IServiceB service0,
+ global::IServiceC service1
+ ) : base(service, service0)
{
this._service = service1;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/FriendlyParameterNamesTest.ExamplesGeneratedCode#FriendlyParameterNamesTest.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/FriendlyParameterNamesTest.ExamplesGeneratedCode#FriendlyParameterNamesTest.g.verified.cs
index 7fe459f..f597794 100644
--- a/src/AutoCtor.Tests/Examples/Verified/FriendlyParameterNamesTest.ExamplesGeneratedCode#FriendlyParameterNamesTest.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/FriendlyParameterNamesTest.ExamplesGeneratedCode#FriendlyParameterNamesTest.g.verified.cs
@@ -9,7 +9,11 @@ partial class FriendlyParameterNamesTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public FriendlyParameterNamesTest(int underscorePrefix, int camelCase, int PascalCase)
+ public FriendlyParameterNamesTest(
+ int underscorePrefix,
+ int camelCase,
+ int PascalCase
+ )
{
this._underscorePrefix = underscorePrefix;
this.camelCase = camelCase;
diff --git a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#A.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#A.g.verified.cs
index c361ac4..7d6c7f3 100644
--- a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#A.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#A.g.verified.cs
@@ -9,7 +9,18 @@ partial class A
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public A(global::IServiceE serviceE, global::IServiceD serviceD, global::IServiceC serviceC, global::IServiceB serviceB, global::IServiceA serviceA) : base(serviceE, serviceD, serviceC, serviceB)
+ public A(
+ global::IServiceE serviceE,
+ global::IServiceD serviceD,
+ global::IServiceC serviceC,
+ global::IServiceB serviceB,
+ global::IServiceA serviceA
+ ) : base(
+ serviceE,
+ serviceD,
+ serviceC,
+ serviceB
+ )
{
this._serviceA = serviceA;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#B.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#B.g.verified.cs
index 96c94d8..f7d66a2 100644
--- a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#B.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#B.g.verified.cs
@@ -9,7 +9,16 @@ partial class B
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public B(global::IServiceE serviceE, global::IServiceD serviceD, global::IServiceC serviceC, global::IServiceB serviceB) : base(serviceE, serviceD, serviceC)
+ public B(
+ global::IServiceE serviceE,
+ global::IServiceD serviceD,
+ global::IServiceC serviceC,
+ global::IServiceB serviceB
+ ) : base(
+ serviceE,
+ serviceD,
+ serviceC
+ )
{
this._serviceB = serviceB;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#C.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#C.g.verified.cs
index 07813fc..ea85976 100644
--- a/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#C.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/InheritanceTest.ExamplesGeneratedCode#C.g.verified.cs
@@ -9,7 +9,11 @@ partial class C
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public C(global::IServiceE serviceE, global::IServiceD serviceD, global::IServiceC serviceC) : base(serviceE, serviceD)
+ public C(
+ global::IServiceE serviceE,
+ global::IServiceD serviceD,
+ global::IServiceC serviceC
+ ) : base(serviceE, serviceD)
{
this._serviceC = serviceC;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/KeywordsTest.ExamplesGeneratedCode#KeywordsTest.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/KeywordsTest.ExamplesGeneratedCode#KeywordsTest.g.verified.cs
index f8d8037..413ffba 100644
--- a/src/AutoCtor.Tests/Examples/Verified/KeywordsTest.ExamplesGeneratedCode#KeywordsTest.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/KeywordsTest.ExamplesGeneratedCode#KeywordsTest.g.verified.cs
@@ -9,7 +9,12 @@ partial class KeywordsTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public KeywordsTest(int @base, int @int, int @class, int @private)
+ public KeywordsTest(
+ int @base,
+ int @int,
+ int @class,
+ int @private
+ )
{
this.@base = @base;
this.@int = @int;
diff --git a/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example1.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example1.g.verified.cs
index 3a0e609..282557f 100644
--- a/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example1.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example1.g.verified.cs
@@ -9,7 +9,11 @@ partial class Example1
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public Example1(global::IServiceA a, global::IServiceB b, global::IServiceC c) : base(a, b)
+ public Example1(
+ global::IServiceA a,
+ global::IServiceB b,
+ global::IServiceC c
+ ) : base(a, b)
{
this.c = c;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example2.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example2.g.verified.cs
index a4e6789..359b568 100644
--- a/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example2.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/MultipleGenericInheritance.ExamplesGeneratedCode#Example2.g.verified.cs
@@ -9,7 +9,11 @@ partial class Example2
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public Example2(global::IServiceD a, global::IServiceE b, global::IServiceF f) : base(a, b)
+ public Example2(
+ global::IServiceD a,
+ global::IServiceE b,
+ global::IServiceF f
+ ) : base(a, b)
{
this.f = f;
}
diff --git a/src/AutoCtor.Tests/Examples/Verified/UniqueNameTest.ExamplesGeneratedCode#UniqueNameTest.g.verified.cs b/src/AutoCtor.Tests/Examples/Verified/UniqueNameTest.ExamplesGeneratedCode#UniqueNameTest.g.verified.cs
index 0140750..d15b04a 100644
--- a/src/AutoCtor.Tests/Examples/Verified/UniqueNameTest.ExamplesGeneratedCode#UniqueNameTest.g.verified.cs
+++ b/src/AutoCtor.Tests/Examples/Verified/UniqueNameTest.ExamplesGeneratedCode#UniqueNameTest.g.verified.cs
@@ -9,7 +9,11 @@ partial class UniqueNameTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public UniqueNameTest(global::IServiceC serviceC, global::IServiceA serviceA, global::IServiceB serviceB) : base(serviceC)
+ public UniqueNameTest(
+ global::IServiceC serviceC,
+ global::IServiceA serviceA,
+ global::IServiceB serviceB
+ ) : base(serviceC)
{
this._serviceA = serviceA;
Initialize(serviceB);
diff --git a/src/AutoCtor.Tests/LangExamples/Verified_3_11/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs b/src/AutoCtor.Tests/LangExamples/Verified_3_11/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
index 37b138c..3315418 100644
--- a/src/AutoCtor.Tests/LangExamples/Verified_3_11/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
+++ b/src/AutoCtor.Tests/LangExamples/Verified_3_11/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
@@ -9,7 +9,11 @@ partial class PropertiesTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public PropertiesTest(string getProperty, string protectedProperty, string initProperty)
+ public PropertiesTest(
+ string getProperty,
+ string protectedProperty,
+ string initProperty
+ )
{
this.GetProperty = getProperty;
this.ProtectedProperty = protectedProperty;
diff --git a/src/AutoCtor.Tests/LangExamples/Verified_4_0/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs b/src/AutoCtor.Tests/LangExamples/Verified_4_0/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
index 37b138c..3315418 100644
--- a/src/AutoCtor.Tests/LangExamples/Verified_4_0/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
+++ b/src/AutoCtor.Tests/LangExamples/Verified_4_0/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
@@ -9,7 +9,11 @@ partial class PropertiesTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public PropertiesTest(string getProperty, string protectedProperty, string initProperty)
+ public PropertiesTest(
+ string getProperty,
+ string protectedProperty,
+ string initProperty
+ )
{
this.GetProperty = getProperty;
this.ProtectedProperty = protectedProperty;
diff --git a/src/AutoCtor.Tests/LangExamples/Verified_4_4/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs b/src/AutoCtor.Tests/LangExamples/Verified_4_4/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
index 43d5390..5ff8d60 100644
--- a/src/AutoCtor.Tests/LangExamples/Verified_4_4/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
+++ b/src/AutoCtor.Tests/LangExamples/Verified_4_4/PropertiesTest.ExamplesGeneratedCode#PropertiesTest.g.verified.cs
@@ -9,7 +9,12 @@ partial class PropertiesTest
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
- public PropertiesTest(string getProperty, string protectedProperty, string initProperty, string requiredProperty)
+ public PropertiesTest(
+ string getProperty,
+ string protectedProperty,
+ string initProperty,
+ string requiredProperty
+ )
{
this.GetProperty = getProperty;
this.ProtectedProperty = protectedProperty;