diff --git a/src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs b/src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs index 6d560c76c1..57b927d41f 100644 --- a/src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs +++ b/src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs @@ -153,9 +153,41 @@ public int GetHashCode(ImmutableArray 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); + } + } } 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); + } } }