Skip to content

Commit 78c3d88

Browse files
committed
Rename method
1 parent 7e614ab commit 78c3d88

9 files changed

+64
-64
lines changed

src/DynamoDBGenerator.SourceGenerator/DynamoDBDMarshallerEntry.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ private static IEnumerable<string> CreateFileContent(ISymbol type, Compilation c
6464

6565
var (options, args) = CreateArguments(type, compilation);
6666
var classContent =
67-
$"public sealed partial class {type.Name}".CreateBlock(DynamoDbMarshaller.CreateRepository(args, options));
67+
$"public sealed partial class {type.Name}".CreateScope(DynamoDbMarshaller.CreateRepository(args, options));
6868
var content = type.ContainingNamespace.IsGlobalNamespace
6969
? classContent
70-
: $"namespace {type.ContainingNamespace.ToDisplayString()}".CreateBlock(classContent);
70+
: $"namespace {type.ContainingNamespace.ToDisplayString()}".CreateScope(classContent);
7171

7272
foreach (var s in content)
7373
yield return s;

src/DynamoDBGenerator.SourceGenerator/DynamoDbMarshaller.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
2222
var argumentTypeName = argument.AnnotatedArgumentType;
2323

2424
var constructor = $"public {argument.ImplementationName}({MarshallerOptions.Name} {MarshallerOptions.ParamReference})"
25-
.CreateBlock($"{MarshallerOptions.FieldReference} = {MarshallerOptions.ParamReference};", $"{KeyMarshaller.PrimaryKeyMarshallerReference} = {KeyMarshaller.AssignmentRoot(argument.EntityTypeSymbol)};");
25+
.CreateScope($"{MarshallerOptions.FieldReference} = {MarshallerOptions.ParamReference};", $"{KeyMarshaller.PrimaryKeyMarshallerReference} = {KeyMarshaller.AssignmentRoot(argument.EntityTypeSymbol)};");
2626
var interfaceImplementation = constructor
2727
.Concat(Marshaller.RootSignature(argument.EntityTypeSymbol, entityTypeName))
2828
.Concat(Unmarshaller.RootSignature(argument.EntityTypeSymbol, entityTypeName))
@@ -33,7 +33,7 @@ private static IEnumerable<string> CreateImplementations(IEnumerable<DynamoDBMar
3333
.Prepend(MarshallerOptions.FieldDeclaration);
3434

3535
var classImplementation = $"private sealed class {argument.ImplementationName}: {Interface}<{entityTypeName}, {argumentTypeName}, {nameTrackerTypeName}, {valueTrackerTypeName}>"
36-
.CreateBlock(interfaceImplementation);
36+
.CreateScope(interfaceImplementation);
3737

3838
yield return options.TryInstantiate() switch
3939
{

src/DynamoDBGenerator.SourceGenerator/Extensions/StringExtensions.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private static string Indent(int level)
2121

2222
return indent;
2323
}
24-
public static IEnumerable<string> CreateBlock(this string header, IEnumerable<string> content, int indentLevel)
24+
public static IEnumerable<string> CreateScope(this string header, IEnumerable<string> content, int indentLevel)
2525
{
2626
var indent = Indent(indentLevel);
2727

@@ -33,7 +33,7 @@ public static IEnumerable<string> CreateBlock(this string header, IEnumerable<st
3333

3434
yield return string.Intern($"{indent}}}");
3535
}
36-
public static IEnumerable<string> CreateBlock(this string header, IEnumerable<string> content)
36+
public static IEnumerable<string> CreateScope(this string header, IEnumerable<string> content)
3737
{
3838
yield return header;
3939
yield return "{";
@@ -44,7 +44,7 @@ public static IEnumerable<string> CreateBlock(this string header, IEnumerable<st
4444
yield return "}";
4545
}
4646

47-
public static IEnumerable<string> CreateBlock(this string header, string content)
47+
public static IEnumerable<string> CreateScope(this string header, string content)
4848
{
4949
yield return header;
5050
yield return "{";
@@ -54,7 +54,7 @@ public static IEnumerable<string> CreateBlock(this string header, string content
5454
yield return "}";
5555
}
5656

57-
public static IEnumerable<string> CreateBlock(this string header, string content, string second)
57+
public static IEnumerable<string> CreateScope(this string header, string content, string second)
5858
{
5959
yield return header;
6060
yield return "{";

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionName.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static IEnumerable<string> CreateCode(
3535
})
3636
.Append($@"{self} = new(() => {ConstructorAttributeName} ?? throw new NotImplementedException(""Root element AttributeExpressionName reference.""));");
3737
38-
foreach (var fieldAssignment in $"public {structName}(string? {ConstructorAttributeName})".CreateBlock(constructorFieldAssignments))
38+
foreach (var fieldAssignment in $"public {structName}(string? {ConstructorAttributeName})".CreateScope(constructorFieldAssignments))
3939
yield return fieldAssignment;
4040
4141
foreach (var fieldDeclaration in dataMembers)
@@ -61,7 +61,7 @@ private static IEnumerable<string> CreateCode(
6161
)
6262
.Append($@"if ({self}.IsValueCreated) yield return new ({self}.Value, ""{typeSymbol.Name}"");");
6363

64-
foreach (var s in $"IEnumerable<KeyValuePair<string, string>> {AttributeExpressionNameTrackerInterface}.{AttributeExpressionNameTrackerInterfaceAccessedNames}()".CreateBlock(yields))
64+
foreach (var s in $"IEnumerable<KeyValuePair<string, string>> {AttributeExpressionNameTrackerInterface}.{AttributeExpressionNameTrackerInterfaceAccessedNames}()".CreateScope(yields))
6565
yield return s;
6666

6767
yield return $"public override string ToString() => {self}.Value;";
@@ -80,7 +80,7 @@ private static Conversion CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol,
8080

8181
var structName = TypeName(typeSymbol);
8282

83-
var @class = $"public readonly struct {structName} : {AttributeExpressionNameTrackerInterface}".CreateBlock(CreateCode(typeSymbol, dataMembers, structName));
83+
var @class = $"public readonly struct {structName} : {AttributeExpressionNameTrackerInterface}".CreateScope(CreateCode(typeSymbol, dataMembers, structName));
8484
return new Conversion(@class, dataMembers.Where(x => x.IsUnknown).Select(x => x.DDB.DataMember.Type));
8585

8686
}

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MarshallerOptions options
2424
: $"{x.ValueRef} = new ({ValueProvider});")
2525
.Append($"{self} = new({ValueProvider});")
2626
.Append($"{MarshallerOptions.FieldReference} = {MarshallerOptions.ParamReference};");
27-
foreach (var fieldAssignment in $"public {structName}(Func<string> {ValueProvider}, {MarshallerOptions.Name} options)".CreateBlock(constructorFieldAssignments))
27+
foreach (var fieldAssignment in $"public {structName}(Func<string> {ValueProvider}, {MarshallerOptions.Name} options)".CreateScope(constructorFieldAssignments))
2828
yield return fieldAssignment;
2929

3030
yield return MarshallerOptions.FieldDeclaration;
@@ -48,11 +48,11 @@ MarshallerOptions options
4848
var enumerable = Enumerable.Empty<string>();
4949
if (typeSymbol.IsNullable())
5050
{
51-
enumerable = $"if ({param} is null)".CreateBlock($"yield return new ({self}.Value, {AttributeValueUtilityFactory.Null});", "yield break;");
51+
enumerable = $"if ({param} is null)".CreateScope($"yield return new ({self}.Value, {AttributeValueUtilityFactory.Null});", "yield break;");
5252
}
5353
else if (typeSymbol.IsReferenceType)
5454
{
55-
enumerable = $"if ({param} is null)".CreateBlock($"throw {ExceptionHelper.NullExceptionMethod}(\"{structName}\");");
55+
enumerable = $"if ({param} is null)".CreateScope($"throw {ExceptionHelper.NullExceptionMethod}(\"{structName}\");");
5656
}
5757

5858
var yields = enumerable.Concat(
@@ -70,7 +70,7 @@ MarshallerOptions options
7070

7171
foreach (var yield in
7272
$"IEnumerable<KeyValuePair<string, AttributeValue>> {interfaceName}.{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerAccessedValues}({typeSymbol.Representation().annotated} entity)"
73-
.CreateBlock(yields))
73+
.CreateScope(yields))
7474
yield return yield;
7575

7676
yield return $"public override string ToString() => {self}.Value;";
@@ -101,7 +101,7 @@ private static Conversion CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol,
101101
var structName = TypeName(typeSymbol);
102102
var interfaceName = $"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{typeSymbol.Representation().annotated}>";
103103

104-
var @struct = $"public readonly struct {structName} : {interfaceName}".CreateBlock(CreateCode(typeSymbol, dataMembers, structName, interfaceName, options));
104+
var @struct = $"public readonly struct {structName} : {interfaceName}".CreateScope(CreateCode(typeSymbol, dataMembers, structName, interfaceName, options));
105105

106106
return new Conversion(@struct, dataMembers.Where(x => x.IsUnknown).Select(x => x.DDB.DataMember.Type));
107107

@@ -110,7 +110,7 @@ private static Conversion CreateStruct(ITypeSymbol typeSymbol, Func<ITypeSymbol,
110110
internal static (IEnumerable<string> method, string typeName) RootSignature(ITypeSymbol typeSymbol)
111111
{
112112
var typeName = TypeName(typeSymbol);
113-
return ($"public {typeName} {Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerMethodName}()".CreateBlock(
113+
return ($"public {typeName} {Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerMethodName}()".CreateScope(
114114
"var incrementer = new DynamoExpressionValueIncrementer();",
115115
$"return new {typeName}(incrementer.GetNext, {MarshallerOptions.FieldReference});"
116116
), typeName);

src/DynamoDBGenerator.SourceGenerator/Generations/KeyMarshaller.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ private static IEnumerable<string> CreateAssignment(string validateReference, st
1919
var expression = $"{keyReference} is {expectedType} {{ }} {reference}";
2020

2121
var innerContent = $"if ({expression}) "
22-
.CreateBlock($@"{DictionaryName}.Add(""{dataMember.AttributeName}"", {Marshaller.InvokeMarshallerMethod(dataMember.DataMember.Type, reference, $"nameof({keyReference})", options)});")
23-
.Concat($"else if ({keyReference} is null) ".CreateBlock($@"throw {ExceptionHelper.KeysArgumentNullExceptionMethod}(""{dataMember.DataMember.Name}"", ""{keyReference}"");"))
24-
.Concat("else".CreateBlock($@"throw {ExceptionHelper.KeysInvalidConversionExceptionMethod}(""{dataMember.DataMember.Name}"", ""{keyReference}"", {keyReference}, ""{expectedType}"");"));
22+
.CreateScope($@"{DictionaryName}.Add(""{dataMember.AttributeName}"", {Marshaller.InvokeMarshallerMethod(dataMember.DataMember.Type, reference, $"nameof({keyReference})", options)});")
23+
.Concat($"else if ({keyReference} is null) ".CreateScope($@"throw {ExceptionHelper.KeysArgumentNullExceptionMethod}(""{dataMember.DataMember.Name}"", ""{keyReference}"");"))
24+
.Concat("else".CreateScope($@"throw {ExceptionHelper.KeysInvalidConversionExceptionMethod}(""{dataMember.DataMember.Name}"", ""{keyReference}"", {keyReference}, ""{expectedType}"");"));
2525

26-
return $"if({validateReference})".CreateBlock(innerContent);
26+
return $"if({validateReference})".CreateScope(innerContent);
2727

2828
}
2929
private static IEnumerable<string> CreateBody(ITypeSymbol typeSymbol, Func<ITypeSymbol, IReadOnlyList<DynamoDbDataMember>> fn, MarshallerOptions options)
@@ -39,17 +39,17 @@ private static IEnumerable<string> CreateBody(ITypeSymbol typeSymbol, Func<IType
3939
yield return $"var {DictionaryName} = new Dictionary<string, AttributeValue>(2);";
4040

4141
var switchBody = GetAssignments(keyStructure.Value, options)
42-
.SelectMany(x => $"case {(x.IndexName is null ? "null" : @$"""{x.IndexName}""")}:".CreateBlock(x.assignments).Append("break;"))
42+
.SelectMany(x => $"case {(x.IndexName is null ? "null" : @$"""{x.IndexName}""")}:".CreateScope(x.assignments).Append("break;"))
4343
.Append($"default: throw {ExceptionHelper.MissMatchedIndexNameExceptionMethod}(nameof(index), index);");
4444

45-
foreach (var s in "switch (index)".CreateBlock(switchBody))
45+
foreach (var s in "switch (index)".CreateScope(switchBody))
4646
yield return s;
4747

4848
var validateSwitch = $"if ({EnforcePkReference} && {EnforceRkReference} && {DictionaryName}.Count == 2)"
49-
.CreateBlock($"return {DictionaryName};")
50-
.Concat($"if ({EnforcePkReference} && {EnforceRkReference} is false && {DictionaryName}.Count == 1)".CreateBlock($"return {DictionaryName};"))
51-
.Concat($"if ({EnforcePkReference} is false && {EnforceRkReference} && {DictionaryName}.Count == 1)".CreateBlock($"return {DictionaryName};"))
52-
.Concat($"if ({EnforcePkReference} && {EnforceRkReference} && {DictionaryName}.Count == 1)".CreateBlock($"throw {ExceptionHelper.KeysMissingDynamoDBAttributeExceptionMethod}({PkReference}, {RkReference});"))
49+
.CreateScope($"return {DictionaryName};")
50+
.Concat($"if ({EnforcePkReference} && {EnforceRkReference} is false && {DictionaryName}.Count == 1)".CreateScope($"return {DictionaryName};"))
51+
.Concat($"if ({EnforcePkReference} is false && {EnforceRkReference} && {DictionaryName}.Count == 1)".CreateScope($"return {DictionaryName};"))
52+
.Concat($"if ({EnforcePkReference} && {EnforceRkReference} && {DictionaryName}.Count == 1)".CreateScope($"throw {ExceptionHelper.KeysMissingDynamoDBAttributeExceptionMethod}({PkReference}, {RkReference});"))
5353
.Append($"throw {ExceptionHelper.ShouldNeverHappenExceptionMethod}();");
5454

5555
foreach (var s in validateSwitch)
@@ -93,11 +93,11 @@ private static IEnumerable<string> MissingAssigment(string validateReference, st
9393
{
9494

9595
var expression = $"{validateReference} && {keyReference} is not null";
96-
return $"if ({expression})".CreateBlock($"throw {ExceptionHelper.KeysValueWithNoCorrespondenceMethod}(\"{keyReference}\", {keyReference});");
96+
return $"if ({expression})".CreateScope($"throw {ExceptionHelper.KeysValueWithNoCorrespondenceMethod}(\"{keyReference}\", {keyReference});");
9797
}
9898
internal static IEnumerable<string> IndexKeyMarshallerRootSignature(ITypeSymbol typeSymbol)
9999
{
100-
return $"public {Constants.DynamoDBGenerator.Marshaller.IndexKeyMarshallerInterface} IndexKeyMarshaller(string index)".CreateBlock(
100+
return $"public {Constants.DynamoDBGenerator.Marshaller.IndexKeyMarshallerInterface} IndexKeyMarshaller(string index)".CreateScope(
101101
"ArgumentNullException.ThrowIfNull(index);",
102102
$"return new {IndexKeyMarshallerImplementationTypeName}((pk, rk, ipk, irk, dm) => {MethodName(typeSymbol)}({MarshallerOptions.FieldReference}, pk, rk, ipk, irk, dm), index);"
103103
);
@@ -114,7 +114,7 @@ private static Conversion StaticAttributeValueDictionaryKeys(ITypeSymbol typeSym
114114
{
115115

116116
var code = $"private static Dictionary<string, AttributeValue> {MethodName(typeSymbol)}({MarshallerOptions.Name} {MarshallerOptions.ParamReference}, object? {PkReference}, object? {RkReference}, bool {EnforcePkReference}, bool {EnforceRkReference}, string? index = null)"
117-
.CreateBlock(CreateBody(typeSymbol, fn, options));
117+
.CreateScope(CreateBody(typeSymbol, fn, options));
118118

119119
return new Conversion(code);
120120

0 commit comments

Comments
 (0)