Code Monkey home page Code Monkey logo

Comments (10)

ndrwrbgs avatar ndrwrbgs commented on August 20, 2024

Hi xigolle,

At this time the thought is to remove that capability. The value add did not seem worth the complexity added to the APIs and possible feature creep of validating things outside of arguments.

If you could help explain your use case we can suggest solutions or reconsider these ideas.

Thanks!

from ensure.that.

xigolle avatar xigolle commented on August 20, 2024

Hi ndrwrbgs,

Well now when ensureThat throws an error if something is null it is just a generic message like value cannot be null.
But it would be nice if we could set a more custom message so we can inform the user better on what is happening.

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

Some options comes to my mind (note, not saying anything is correct)

  • We keep the Ensure.That (sigh... never ending story)
  • We see this library as a guard clause lib for enforcing contracts, not a validation for end user.... and then skip support for custom messages
  • We add an optional argument (param, opts) => opts.CustomMessage($"This value {param} is no good")

from ensure.that.

xigolle avatar xigolle commented on August 20, 2024

To be honest I really like the last idea. That way you can still use the lib as a guard clause but leave it open for additional messages.

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

Decision is to add something like:

(param, opts) => opts.CustomMessage($"This value {param} is no good")

Note. It should be possible to (later on) extend this with something like:

(param, opts) => opts.CustomException(new FooException())

from ensure.that.

ndrwrbgs avatar ndrwrbgs commented on August 20, 2024

What’s the expected type of opts here?

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

I will call it EnsureOptions

from ensure.that.

ndrwrbgs avatar ndrwrbgs commented on August 20, 2024

😃 I meant what’s it’s purpose. To encapsulate the input arguments?

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

Nope. To contain optional customizations of the exception or message:

EnsureArg.IsTrue(true, "myParam", o => o.WithMessage("asdf"));

or

EnsureArg.IsTrue(true, "myParam", o => o.WithException(new FooException("Schnitzel!"));

The latter takes precedence.

from ensure.that.

danielwertheim avatar danielwertheim commented on August 20, 2024

Something like this: 1b6411c

Will probably add WithExtraMessage to ease migration from obsolete Ensure.That and perhaps change for Funcs.

from ensure.that.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.