All Projects → ardalis → Guardclauses

ardalis / Guardclauses

Licence: mit
A simple package with guard clause extensions.

Projects that are alternatives of or similar to Guardclauses

Run Aspnetcore
A starter kit for your next ASP.NET Core web application. Boilerplate for ASP.NET Core reference application, demonstrating a layered application architecture with applying Clean Architecture and DDD best practices. Download 100+ page eBook PDF from here ->
Stars: ✭ 227 (-70.4%)
Mutual labels:  dotnet-core, clean-architecture, design-patterns, clean-code
Clean Architecture Manga
🌀 Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
Stars: ✭ 3,104 (+304.69%)
Mutual labels:  dotnet-core, clean-architecture, design-patterns, clean-code
Designpatternsincsharp
Samples associated with Pluralsight design patterns in c# courses.
Stars: ✭ 149 (-80.57%)
Mutual labels:  patterns, dotnet-core, design-patterns, pattern
Aspnet Core Clean Arch
It is a clean architecture project template which is based on hexagonal-architecture principles built with .Net core.
Stars: ✭ 60 (-92.18%)
Mutual labels:  dotnet-core, clean-architecture, clean-code
Sample Dotnet Core Cqrs Api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
Stars: ✭ 1,273 (+65.97%)
Mutual labels:  clean-architecture, design-patterns, clean-code
Todo
✅ Commad-Line Task management with storage on your GitHub 🔥
Stars: ✭ 111 (-85.53%)
Mutual labels:  dotnet-core, clean-architecture, clean-code
Architecture
.NET 6, ASP.NET Core 6, Entity Framework Core 6, C# 10, Angular 13, Clean Code, SOLID, DDD.
Stars: ✭ 2,285 (+197.91%)
Mutual labels:  dotnet-core, clean-architecture, clean-code
Dotnet New Caju
Learn Clean Architecture with .NET Core 3.0 🔥
Stars: ✭ 228 (-70.27%)
Mutual labels:  clean-architecture, design-patterns, clean-code
clean architecture typescript example
This repository provides an implementation (or at least an attempt) of Uncle Bob's Clean Architecture with Typescript.
Stars: ✭ 78 (-89.83%)
Mutual labels:  clean-code, design-patterns, clean-architecture
Modular Monolith With Ddd
Full Modular Monolith application with Domain-Driven Design approach.
Stars: ✭ 6,210 (+709.65%)
Mutual labels:  clean-architecture, design-patterns, clean-code
eShopOnWeb
Sample ASP.NET Core 6.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
Stars: ✭ 8,250 (+975.62%)
Mutual labels:  clean-code, design-patterns, clean-architecture
Cp Ddd Framework
A lightweight flexible development framework for complex business architecture with full ecosystem!轻量级业务中台开发框架,中台架构的顶层设计和完整解决方案!
Stars: ✭ 566 (-26.21%)
Mutual labels:  clean-architecture, design-patterns, clean-code
iOS-Clean-Architecture-Example
An iOS app designed using clean architecture and MVVM.
Stars: ✭ 50 (-93.48%)
Mutual labels:  patterns, clean-code, clean-architecture
Clean Ts Api
API em NodeJs usando Typescript, TDD, Clean Architecture, Design Patterns e SOLID principles
Stars: ✭ 619 (-19.3%)
Mutual labels:  clean-architecture, design-patterns, clean-code
Go Realworld Clean
a clean architecture implementation of the realworldapp : https://github.com/gothinkster/realworld
Stars: ✭ 301 (-60.76%)
Mutual labels:  clean-architecture, clean-code
Reminders
An iOS application written in Swift to demonstrate how to implement a Clean Architecture in iOS
Stars: ✭ 293 (-61.8%)
Mutual labels:  clean-architecture, clean-code
Clean Architecture
Clean architecture sample
Stars: ✭ 318 (-58.54%)
Mutual labels:  clean-architecture, clean-code
Clean Code Dotnet
🛁 Clean Code concepts and tools adapted for .NET
Stars: ✭ 4,425 (+476.92%)
Mutual labels:  clean-architecture, clean-code
Cleanaspnetcorewebapi
Starter project for creating APIs built on ASP.NET Core using clean architecture.
Stars: ✭ 279 (-63.62%)
Mutual labels:  clean-architecture, clean-code
Blog Core
Modular blog using Blazor with clean domain-driven design patterns
Stars: ✭ 345 (-55.02%)
Mutual labels:  dotnet-core, clean-architecture

NuGetNuGet publish Ardalis.GuardClauses to nuget

Guard Clauses

A simple package with guard clause extensions.

Give a Star! ⭐️

If you like or are using this project please give it a star. Thanks!

Usage

    public void ProcessOrder(Order order)
    {
    	Guard.Against.Null(order, nameof(order));

        // process order here
    }

    // OR

    public class Order
    {
        private string _name;
        private int _quantity;
        private long _max;
        private decimal _unitPrice;
        private DateTime _dateCreated;

        public Order(string name, int quantity, long max, decimal unitPrice, DateTime dateCreated)
        {
            _name = Guard.Against.NullOrWhiteSpace(name, nameof(name));
            _quantity = Guard.Against.NegativeOrZero(quantity, nameof(quantity));
            _max = Guard.Against.Zero(max, nameof(max));
            _unitPrice = Guard.Against.Negative(unitPrice, nameof(unitPrice));
            _dateCreated = Guard.Against.OutOfSQLDateRange(dateCreated, nameof(dateCreated));
        }
    }

Supported Guard Clauses

  • Guard.Against.Null (throws if input is null)
  • Guard.Against.NullOrEmpty (throws if string, guid or array input is null or empty)
  • Guard.Against.NullOrWhiteSpace (throws if string input is null, empty or whitespace)
  • Guard.Against.OutOfRange (throws if integer/DateTime/enum input is outside a provided range)
  • Guard.Against.OutOfSQLDateRange (throws if DateTime input is outside the valid range of SQL Server DateTime values)
  • Guard.Against.Zero (throws if number input is zero)

Extending with your own Guard Clauses

To extend your own guards, you can do the following:

    // Using the same namespace will make sure your code picks up your 
    // extensions no matter where they are in your codebase.
    namespace Ardalis.GuardClauses
    {
        public static class FooGuard
        {
            public static void Foo(this IGuardClause guardClause, string input, string parameterName)
            {
                if (input?.ToLower() == "foo")
                    throw new ArgumentException("Should not have been foo!", parameterName);
            }
        }
    }

    // Usage
    public void SomeMethod(string something)
    {
        Guard.Against.Foo(something, nameof(something));
    }

References

Build Notes

  • Remember to update the PackageVersion in the csproj file and then a build on master should automatically publish the new package to nuget.org.
  • Add a release with form 1.3.2 to GitHub Releases in order for the package to actually be published to Nuget. Otherwise it will claim to have been successful but is lying to you.
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].