✅ Is there a way you can check if an object’s equality operator will compare by reference?

I want to implement a data validation attribute like [UniqueValues] for ASP.NET model binding which will basically just call .Distinct() and check the count against the original list.

This however won’t work with plain classes, only value types, records, or classes that implement IEquatable. Is there a way I can check an
object
instance to see if it will be compared by reference, and if so throw an exception?
Was this page helpful?