Typely
GitHub
  • Overview
    • πŸ‘Welcome!
  • Validations
    • πŸ“Common
    • πŸ”’Number
    • βš–οΈComparable
    • ✏️String
  • Customize errors
    • 🌎Localization
    • πŸ”Sensitive data
  • General
    • 🧩Class VS Struct
    • πŸ–ΌοΈSupported frameworks
    • πŸš€Benchmarks
    • ⚠️Limitations
  • Design decisions
    • πŸ”„Conversions
    • ℹ️Use of interfaces
    • πŸ€Έβ€β™‚οΈUnderlying type comparison
    • πŸ’‚Validations
Powered by GitBook
On this page
Edit on GitHub
  1. Design decisions

Underlying type comparison

Why is there no implementation of IEquatable and IComparable on the underlying type?

Premise : It would be cool if we could check for equality and be able to compare a value object with a primitive type.

We could implement IEquatable<PrimitiveType> and IComparable<PrimitiveType> on the value object but it would be one sided.

See the following:

var name = Name.From("Joe");
name.Equals("Joe"); // Returns true
"Joe".Equals(name); // Returns false

Due to the inconsistency, no equality or comparison will be implemented on the underlying type.

PreviousUse of interfacesNextValidations

Last updated 2 years ago

πŸ€Έβ€β™‚οΈ