Skip to content

Commit 080a96d

Browse files
committed
refactor: updated some syntax to use latest c# features
1 parent cb371a8 commit 080a96d

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

MapDataReader/MapperGenerator.cs

+10-11
Original file line numberDiff line numberDiff line change
@@ -169,20 +169,20 @@ internal class TargetTypeTracker : ISyntaxContextReceiver
169169

170170
public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
171171
{
172-
if (context.Node is ClassDeclarationSyntax cdecl)
173-
if (cdecl.IsDecoratedWithAttribute("GenerateDataReaderMapper"))
174-
TypesNeedingGening = TypesNeedingGening.Add(cdecl);
172+
if (context.Node is not ClassDeclarationSyntax classDec) return;
173+
174+
if (classDec.IsDecoratedWithAttribute("GenerateDataReaderMapper"))
175+
TypesNeedingGening = TypesNeedingGening.Add(classDec);
175176
}
176177
}
177178

178179
internal static class Helpers
179180
{
180-
internal static bool IsDecoratedWithAttribute(this TypeDeclarationSyntax cdecl, string attributeName) =>
181-
cdecl.AttributeLists
181+
internal static bool IsDecoratedWithAttribute(this TypeDeclarationSyntax typeDec, string attributeName) =>
182+
typeDec.AttributeLists
182183
.SelectMany(x => x.Attributes)
183184
.Any(x => x.Name.ToString().Contains(attributeName));
184185

185-
186186
internal static string FullName(this ITypeSymbol typeSymbol) => typeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
187187

188188
internal static string StringConcat(this IEnumerable<string> source, string separator) => string.Join(separator, source);
@@ -214,12 +214,11 @@ internal static bool IsNullableEnum(this ITypeSymbol symbol)
214214
//tries to get underlying non-nullable type from nullable type
215215
//and then check if it's Enum
216216
if (symbol.NullableAnnotation == NullableAnnotation.Annotated
217-
&& symbol is INamedTypeSymbol namedType
218-
&& namedType.IsValueType
219-
&& namedType.IsGenericType
220-
&& namedType.ConstructedFrom?.ToDisplayString() == "System.Nullable<T>"
221-
)
217+
&& symbol is INamedTypeSymbol { IsValueType: true, IsGenericType: true } namedType
218+
&& namedType.ConstructedFrom.ToDisplayString() == "System.Nullable<T>")
219+
{
222220
return namedType.TypeArguments[0].TypeKind == TypeKind.Enum;
221+
}
223222

224223
return false;
225224
}

0 commit comments

Comments
 (0)