Skip to content

Commit f7e9268

Browse files
committed
Remove IsNullableMethod
1 parent b852b4f commit f7e9268

4 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/DynamoDBGenerator.SourceGenerator/Extensions/TypeExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ public static Func<ITypeSymbol, T> CacheFactory<T>(IEqualityComparer<ISymbol> co
5252
private static readonly Dictionary<ITypeSymbol, TypeIdentifier> TypeIdentifierDictionary =
5353
new(SymbolEqualityComparer.IncludeNullability);
5454

55-
public static bool IsNullable(this ITypeSymbol typeSymbol) => typeSymbol switch
56-
{
57-
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.None or NullableAnnotation.Annotated } => true,
58-
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.NotAnnotated } => false,
59-
{ IsValueType: true, OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } => true,
60-
{ IsValueType: true } => false,
61-
_ => throw new ArgumentOutOfRangeException(
62-
$"Could not determine nullablity of type '{typeSymbol.ToDisplayString()}'.")
63-
};
64-
6555
public static TypeIdentifier TypeIdentifier(this ITypeSymbol type)
6656
{
6757
if (TypeIdentifierDictionary.TryGetValue(type, out var typeIdentifier))

src/DynamoDBGenerator.SourceGenerator/Generations/Marshalling/Marshaller.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ private static CodeFactory CreateDictionaryMethod(TypeIdentifier typeIdentifier,
2525

2626
var marshallerInvocation = InvokeMarshallerMethod(x.DataMember.TypeIdentifier, accessPattern, $"\"{x.DataMember.Name}\"", options);
2727

28-
var assignment = x.DataMember.IsNullable
28+
var assignment = x.DataMember.TypeIdentifier.IsNullable
2929
? $"if ({x.DataMember.NameAsCamelCase} is not null)"
3030
.CreateScope($"{DictionaryReference}[\"{x.AttributeName}\"] = {x.DataMember.NameAsCamelCase};")
3131
.Prepend($"var {x.DataMember.NameAsCamelCase} = {marshallerInvocation};")
3232
: new[] { $"{DictionaryReference}[\"{x.AttributeName}\"] = {marshallerInvocation};" };
3333

3434
return (
3535
dictionaryAssignment: assignment,
36-
capacityTernary: x.DataMember.IsNullable ? x.DataMember.TypeIdentifier.TypeSymbol.NotNullTernaryExpression(in accessPattern, "1", "0") : "1",
36+
capacityTernary: x.DataMember.TypeIdentifier.IsNullable ? x.DataMember.TypeIdentifier.TypeSymbol.NotNullTernaryExpression(in accessPattern, "1", "0") : "1",
3737
x.DataMember
3838
);
3939
})

src/DynamoDBGenerator.SourceGenerator/Types/DataMember.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ private DataMember(in ISymbol symbol, in string fieldName, in ITypeSymbol type,
1313
Name = fieldName;
1414
BaseSymbol = symbol;
1515
IsAssignable = isAssignable;
16-
IsNullable = type.IsNullable();
1716
NameAsPrivateField = fieldName.ToPrivateFieldFromPascal();
1817
NameAsCamelCase = fieldName.ToCamelCaseFromPascal();
1918
OriginalRepresentation = type.Representation().original;
@@ -48,13 +47,9 @@ public static DataMember FromProperty(in IPropertySymbol property)
4847
/// </summary>
4948
public string Name { get; }
5049

51-
5250
public TypeIdentifier TypeIdentifier { get; }
5351
public string OriginalRepresentation { get; }
5452
public string NameAsPrivateField { get; }
5553
public string NameAsCamelCase { get; }
56-
57-
public bool IsNullable { get; }
58-
5954
public bool IsAssignable { get; }
6055
}

src/DynamoDBGenerator.SourceGenerator/Types/TypeIdentifier.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ public abstract record TypeIdentifier
77
{
88
protected TypeIdentifier(ITypeSymbol typeSymbol)
99
{
10-
IsNullable = typeSymbol.IsNullable();
10+
IsNullable = typeSymbol switch
11+
{
12+
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.None or NullableAnnotation.Annotated } => true,
13+
{ IsReferenceType: true, NullableAnnotation: NullableAnnotation.NotAnnotated } => false,
14+
{ IsValueType: true, OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } => true,
15+
{ IsValueType: true } => false,
16+
_ => throw new ArgumentOutOfRangeException(
17+
$"Could not determine nullablity of type '{typeSymbol.ToDisplayString()}'.")
18+
};
19+
1120
TypeSymbol = typeSymbol;
1221
var (annotated, original) = typeSymbol.Representation();
1322
OriginalRepresenation = original;

0 commit comments

Comments
 (0)