Skip to content

Commit b0f48f0

Browse files
Add nullable type handling and improve binary operation detection
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
1 parent 8132a96 commit b0f48f0

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

IntelliTect.Analyzer/IntelliTect.Analyzer/Analyzers/BanImplicitDateTimeToDateTimeOffsetConversion.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,18 @@ private void CheckBinaryOperandPair(OperationAnalysisContext context, IOperation
100100
return;
101101
}
102102

103+
// Unwrap nullable types if present
104+
ITypeSymbol operandType = operand.Type is INamedTypeSymbol { IsValueType: true, OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } nullable
105+
? nullable.TypeArguments[0]
106+
: operand.Type;
107+
108+
ITypeSymbol otherType = otherOperand.Type is INamedTypeSymbol { IsValueType: true, OriginalDefinition.SpecialType: SpecialType.System_Nullable_T } otherNullable
109+
? otherNullable.TypeArguments[0]
110+
: otherOperand.Type;
111+
103112
// Check if operand is DateTime and other operand is DateTimeOffset
104-
bool isDateTimeOperand = SymbolEqualityComparer.Default.Equals(operand.Type, dateTimeType);
105-
bool isDateTimeOffsetOtherOperand = SymbolEqualityComparer.Default.Equals(otherOperand.Type, dateTimeOffsetType);
113+
bool isDateTimeOperand = SymbolEqualityComparer.Default.Equals(operandType, dateTimeType);
114+
bool isDateTimeOffsetOtherOperand = SymbolEqualityComparer.Default.Equals(otherType, dateTimeOffsetType);
106115

107116
if (isDateTimeOperand && isDateTimeOffsetOtherOperand)
108117
{

0 commit comments

Comments
 (0)