mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
Fix NotYamlSerializable analyzer ignoring nullable structs (#5934)
Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user