Fix NotYamlSerializable analyzer ignoring nullable structs (#5934)

Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
This commit is contained in:
Tayrtahn
2025-08-02 13:25:48 -04:00
committed by GitHub
parent e316649fd1
commit 63e383bb17
3 changed files with 50 additions and 4 deletions

View File

@@ -54,4 +54,19 @@ public static class TypeSymbolHelper
current = current.BaseType;
}
}
/// <summary>
/// If <paramref name="type"/> is a Nullable{T}, returns the <see cref="ITypeSymbol"/> of the underlying type.
/// Otherwise, returns <paramref name="type"/>.
/// </summary>
// Modified from https://www.meziantou.net/working-with-types-in-a-roslyn-analyzer.htm
public static ITypeSymbol GetNullableUnderlyingTypeOrSelf(ITypeSymbol type)
{
if (type is INamedTypeSymbol namedType && namedType.ConstructedFrom.SpecialType == SpecialType.System_Nullable_T)
{
return namedType.TypeArguments[0];
}
return type;
}
}