private string GetDescription(ValueTypeEqualityImplementations equalsOrHashCode) { switch (equalsOrHashCode) { case ValueTypeEqualityImplementations.Equals: return(nameof(Equals)); case ValueTypeEqualityImplementations.GetHashCode: return(nameof(GetHashCode)); case ValueTypeEqualityImplementations.All: return($"{nameof(Equals)} and {nameof(GetHashCode)}"); default: throw new InvalidOperationException($"Invalid value '{equalsOrHashCode}'"); } }
public static bool HasDefaultEqualsOrHashCodeImplementations(this ITypeSymbol type, out ValueTypeEqualityImplementations valueTypeEquality) { valueTypeEquality = ValueTypeEqualityImplementations.All; foreach (var member in type.GetMembers()) { if (member.Name == nameof(Equals) && member.IsOverride) { valueTypeEquality &= ~ValueTypeEqualityImplementations.Equals; } if (member.Name == nameof(GetHashCode) && member.IsOverride) { valueTypeEquality &= ~ValueTypeEqualityImplementations.GetHashCode; } } return(valueTypeEquality != ValueTypeEqualityImplementations.None); }