Skip to content

Commit f3bae89

Browse files
committed
Fix
1 parent 4d1497d commit f3bae89

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/DynamoDBGenerator.SourceGenerator/Generations/AttributeExpressionValue.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ MarshallerOptions options
6363

6464
var yields = (typeIdentifier switch
6565
{
66-
{IsNullable:true} => $"if ({param} is null)".CreateScope(
66+
{ IsNullable: true } => $"if ({param} is null)".CreateScope(
6767
$"yield return new ({self}.Value, {AttributeValueUtilityFactory.Null});", "yield break;"),
6868
{ TypeSymbol.IsReferenceType: true } => $"if ({param} is null)".CreateScope(
6969
$"throw {ExceptionHelper.NullExceptionMethod}(\"{structName}\");"),
@@ -129,30 +129,29 @@ internal static IEnumerable<string> CreateClasses(DynamoDBMarshallerArguments[]
129129
private static CodeFactory CreateStruct(TypeIdentifier typeIdentifier, Func<ITypeSymbol, DynamoDbDataMember[]> fn,
130130
MarshallerOptions options)
131131
{
132-
var dataMembers =
133-
options.IsConvertable(typeIdentifier.TypeSymbol)
134-
? Array
135-
.Empty<(bool IsUnknown, DynamoDbDataMember DDB, string AttributeReference, string
136-
AttributeInterfaceName)>()
137-
: fn(typeIdentifier.TypeSymbol)
138-
.Select(x => (
139-
IsUnknown: options.IsUnknown(x.DataMember.TypeIdentifier),
140-
DDB: x,
141-
AttributeReference: TypeName(x.DataMember.TypeIdentifier.TypeSymbol),
142-
AttributeInterfaceName:
143-
$"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{x.DataMember.TypeIdentifier.AnnotatedString}>"
144-
))
145-
.ToArray();
132+
var dataMembers = options.IsConvertable(typeIdentifier)
133+
? Array.Empty<(bool IsUnknown, DynamoDbDataMember DDB, string AttributeReference, string AttributeInterfaceName)>()
134+
: fn(typeIdentifier.TypeSymbol)
135+
.Select(x => (
136+
IsUnknown: options.IsUnknown(x.DataMember.TypeIdentifier),
137+
DDB: x,
138+
AttributeReference: TypeName(x.DataMember.TypeIdentifier.TypeSymbol),
139+
AttributeInterfaceName:
140+
$"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{x.DataMember.TypeIdentifier.AnnotatedString}>"
141+
))
142+
.ToArray();
146143

147144
var structName = TypeName(typeIdentifier.TypeSymbol);
148145
var interfaceName =
149146
$"{Constants.DynamoDBGenerator.Marshaller.AttributeExpressionValueTrackerInterface}<{typeIdentifier.AnnotatedString}>";
150147

151148
var @struct =
152-
$"public readonly struct {structName} : {interfaceName}".CreateScope(TypeContents(typeIdentifier, dataMembers,
149+
$"public readonly struct {structName} : {interfaceName}".CreateScope(TypeContents(typeIdentifier,
150+
dataMembers,
153151
structName, interfaceName, options));
154152

155-
return new CodeFactory(@struct, dataMembers.Where(x => x.IsUnknown).Select(x => x.DDB.DataMember.TypeIdentifier));
153+
return new CodeFactory(@struct,
154+
dataMembers.Where(x => x.IsUnknown).Select(x => x.DDB.DataMember.TypeIdentifier));
156155
}
157156

158157
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/DynamoDBGenerator.SourceGenerator/Types/MarshallerOptions.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ public readonly struct MarshallerOptions
1717
public string FullName { get; }
1818
public string FieldDeclaration { get; }
1919

20-
public bool IsUnknown(TypeIdentifier typeSymbol) =>
21-
typeSymbol is UnknownType && IsConvertable(typeSymbol.TypeSymbol) is false;
22-
20+
public bool IsUnknown(TypeIdentifier typeIdentifier) => typeIdentifier is UnknownType && IsConvertable(typeIdentifier) is false;
21+
public bool IsConvertable(TypeIdentifier typeIdentifier) => typeIdentifier.TypeSymbol.TypeKind is TypeKind.Enum || Converters.ContainsKey(typeIdentifier.TypeSymbol);
2322

2423
private MarshallerOptions(
2524
INamedTypeSymbol originalType,
@@ -90,10 +89,6 @@ or ConversionStrategy.UpperCase
9089
return null;
9190
}
9291

93-
public bool IsConvertable(ITypeSymbol typeSymbol)
94-
{
95-
return typeSymbol.TypeKind is TypeKind.Enum || Converters.ContainsKey(typeSymbol);
96-
}
9792

9893
private Dictionary<ISymbol?, KeyValuePair<string, ITypeSymbol>> Converters { get; }
9994

0 commit comments

Comments
 (0)