Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,41 @@ public int GetHashCode(ImmutableArray<TypedConstant> obj)
{
hashCode.Add(typedConstant.Kind);
hashCode.Add(SymbolEqualityComparer.Default.GetHashCode(typedConstant.Type));

if (!typedConstant.IsNull)
{
if (typedConstant.Kind == TypedConstantKind.Array)
{
hashCode.Add(GetHashCode(typedConstant.Values));
}
else
{
AddTypedConstantValueHash(ref hashCode, typedConstant);
}
Comment thread
Evangelink marked this conversation as resolved.
}
}

return hashCode.ToHashCode();
}

private static void AddTypedConstantValueHash(ref RoslynHashCode hashCode, TypedConstant typedConstant)
{
if (typedConstant.Kind == TypedConstantKind.Primitive)
{
switch (typedConstant.Type?.SpecialType)
{
case SpecialType.System_Single:
// BitConverter.SingleToInt32Bits isn't available on netstandard2.0, so we use BitConverter.GetBytes instead.
hashCode.Add(BitConverter.ToInt32(BitConverter.GetBytes((float)typedConstant.Value!), 0));
return;

case SpecialType.System_Double:
hashCode.Add(BitConverter.DoubleToInt64Bits((double)typedConstant.Value!));
return;
}
}

hashCode.Add(typedConstant.Value);
}
}
}