Files
codeql/csharp/ql/test/query-tests/Likely Bugs/InconsistentCompareTo/InconsistentCompareTo.cs
2018-08-02 17:53:23 +01:00

57 lines
1.4 KiB
C#

using System;
class GoodNotIComparable
{
public int CompareTo(object other) { return 0; }
}
class GoodComparable : IComparable
{
public int CompareTo(object other) { return 0; }
public override bool Equals(object other) { return false; }
public override int GetHashCode() { return 0; }
}
class GoodComparableT<T> : IComparable<T>
{
public int CompareTo(T other) { return 0; }
public override bool Equals(object other) { return false; }
public override int GetHashCode() { return 0; }
}
class GoodComparableInt : IComparable<int>
{
public int CompareTo(int other) { return 0; }
public override bool Equals(object other) { return false; }
public override int GetHashCode() { return 0; }
}
abstract class GoodComparableAbstract : IComparable
{
public abstract int CompareTo(object other);
}
class BadComparable : IComparable
{
public int CompareTo(object other) { return 0; }
public override int GetHashCode() { return 0; }
}
class BadComparableInt : IComparable<int>
{
public int CompareTo(int x) { return 0; }
public override int GetHashCode() { return 0; }
}
class BadComparableT<T> : IComparable<T>
{
public int CompareTo(T t) { return 0; }
public override int GetHashCode() { return 0; }
}
class BadComparableNewEquals : IComparable
{
public int CompareTo(object other) { return 0; }
public new bool Equals(object other) { return false; }
}