feO2x / Light.GuardClauses

A lightweight .NET library for expressive Guard Clauses.
MIT License
85 stars 8 forks source link

Conditional assert #73

Closed dominikjeske closed 4 years ago

dominikjeske commented 4 years ago

I have a question about usage of library. Is it possible to do some condition before assert. for example I have code like this

if (!string.IsNullOrEmpty(currency))
{
     currency.MustMatch(_currencyRegex, (s, b) => throw new NumberOfCharsException(nameof(currency), 3));
 }

so I would assert only when there is some value and skip when there is no value. Is there a way to do this with some one liner and library support?

feO2x commented 4 years ago

Hey @bigdnf, No, Light.GuardClauses does not support this scenario out of the box. I would suggest that you write your own assertion if you need to support custom cases like this one.

dominikjeske commented 4 years ago

I like fast response :)