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

Validations

Throwing and catching exceptions is very expensive, so Typely implements validations using the ValidationError class. To avoid additional memory allocation, if all validations succeed, the object returned by the Validate method will be null.

Note that you should use the TryFrom method to perform validation without throwing an exception whenever possible otherwise From.

Method
Mean
Error
StdDev
Gen0
Allocated

ReturnException

5,407.274 ns

28.0004 ns

26.1916 ns

0.0763

240 B

ReturnValidationError

9.879 ns

0.1042 ns

0.0924 ns

0.0153

48 B

Async validations

The validation state of a value object should not depend on external state or services. Therefore, asynchronous calls are not supported.

PreviousUnderlying type comparison

Last updated 2 years ago

πŸ’‚