All Projects → lecaillon → Preconditions

lecaillon / Preconditions

Licence: MIT license
Preconditions.NET provides convenience static methods to help check that a method or a constructor is invoked with proper parameter or not.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Preconditions

can-npm-publish
A command line tool that check to see if `npm publish` is possible.
Stars: ✭ 61 (+258.82%)
Mutual labels:  check
vetr
Trust, but Verify
Stars: ✭ 66 (+288.24%)
Mutual labels:  argument-checks
kirby3-doctor
Plugin to check health of your CMS installation
Stars: ✭ 19 (+11.76%)
Mutual labels:  check
es-feature-detection
ECMAScript feature and API detection
Stars: ✭ 16 (-5.88%)
Mutual labels:  check
ArgCheck.jl
Package for checking function arguments
Stars: ✭ 73 (+329.41%)
Mutual labels:  argument-checks
ArgMacros.jl
Fast, flexible, macro-based, Julia package for parsing command line arguments.
Stars: ✭ 29 (+70.59%)
Mutual labels:  argument-checks
diffido
Watch web pages for changes
Stars: ✭ 19 (+11.76%)
Mutual labels:  check
minecraft-server-status
PHP library to check Minecraft Servers Status
Stars: ✭ 36 (+111.76%)
Mutual labels:  check
fluentcheck
Fluent assertions for Python
Stars: ✭ 79 (+364.71%)
Mutual labels:  check
filter-anything
A simple (TypeScript) integration of "pick" and "omit" to filter props of an object
Stars: ✭ 19 (+11.76%)
Mutual labels:  guard
PanicTrigger
An app for emergency situation
Stars: ✭ 19 (+11.76%)
Mutual labels:  guard
is-primitive
Is the typeof value a javascript primitive?
Stars: ✭ 35 (+105.88%)
Mutual labels:  check
check-ssl
Check the expiration date of your ssl-cert with bash (implemented for Nagios/Icinga)
Stars: ✭ 14 (-17.65%)
Mutual labels:  check
python-license-check
Check python packages from requirement.txt and report issues
Stars: ✭ 111 (+552.94%)
Mutual labels:  check
react-health-check
Lightweight React hook for checking health of API services.
Stars: ✭ 28 (+64.71%)
Mutual labels:  check
shallow-equal-object
Shallow equal check object that support TypeScript.
Stars: ✭ 21 (+23.53%)
Mutual labels:  check
type-guards
Simple utility for runtime type checking which also assigns the correct type if used with TypeScript.
Stars: ✭ 30 (+76.47%)
Mutual labels:  guard
pdsl
The expressive declarative toolkit for composing predicates in TypeScript or JavaScript
Stars: ✭ 64 (+276.47%)
Mutual labels:  guard
CheckableTextView
A simple and flexible Checked TextView or Checkable TextView
Stars: ✭ 108 (+535.29%)
Mutual labels:  check
check
Contao Check
Stars: ✭ 49 (+188.24%)
Mutual labels:  check

Preconditions.NET AppVeyor build status NuGet

Preconditions.NET is a personal, free-time project with no funding. If you use Evolve in your daily work and feel that it makes your life easier, consider supporting its development via GitHub Sponsors ❤️ and by adding a star to this repository

Introduction

Preconditions.NET provides convenience static methods to help check that a method or a constructor is invoked with proper parameter or not. In other words it checks the pre-conditions. The goal of this class is to improve readability of code.

Preconditions.NET returns the tested value on success, allowing to check and call a method at the same time.

On failure it always throws an ArgumentException, ArgumentNullException or ArgumentOutOfRangeException.

Why Preconditions.NET v2 ?

Preconditions.NET v2.0.0 is a complete rewrite that takes advantage of nullable types, the NotNull attribute and the new .NET 6 CallerArgumentExpression attribute. It is no more mandatory to pass the parameter name being checked.

It also adds new methods (cf. checklist) and remove Check.Zero().

How to use it ?

Because Preconditions.NET is only one code file, you can either copy the Check.cs class or include the NuGet package to your project :

PM> Install-Package Preconditions.NET

Example

public class Employee : Person
{
    public Employee(string name, string id) : base(Check.NotNullOrEmpty(name))
    {
        Id = Check.NullableButNotEmpty(id);
    }

    public string Id { get; }
}

The checklist

  • Check.NotNull(object)
  • Check.NullableButNotEmpty (string)
  • Check.NotNullOrEmpty(string)
  • Check.NotNullOrEmpty(IEnumerable)
  • Check.HasNoNulls(IEnumerable)
  • Check.NotEmpty(Guid)
  • Check.FileExists()
  • Check.DirectoryExists()
  • Check.Positive()
  • Check.PositiveOrNull()
  • Check.Negative()
  • Check.NegativeOrNull()
  • Check.NotNegative()
  • Check.NotNegativeOrNull()
  • Check.True(Func)

Feedback and issues

Feedback, improvements, ideas are welcomed. Feel free to create new issues at the issues section.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].