Coder Social home page Coder Social logo

thrower's Introduction

thrower's People

Contributors

pomma89 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

thrower's Issues

Resharper warning "Possible multiple enumeration of IEnumerable" when validating enumerable parameters

I've been using this library for my guard clauses for a while, and I quite like it. However, I've recently started using R# and it's causing me to see (and have to suppress) a number of warnings about potential multiple enumerations when I'm using validations like Raise.ArgumentNullException.IfIsNull(someEnumerableParameter);

This is easy to fix - all that's needed is to add [NoEnumeration] from JetBrains.Annotations to any parameters in externally-accessible methods that can accept enumerable parameters, e.g.

public void IfIsNull<TArg>([NoEnumeration] TArg argument)
{
    if (ReferenceEquals(argument, null))
    {
        throw new ArgumentNullException();
    }
}

I'd do this myself and submit a pull request, but for some reason your project literally crashes Visual Studio 2017 every time I try to open it (not sure what's up with that).

JetBrains Annotations: Part II

Thanks again for the annotating your methods with [NoEnumeration]. If possible, I'd like to expand on that to further support integration with Resharper.

One improvement that would be really nice would be to annotate the null guard methods, like this:

[ContractAnnotation("argument:null => halt")]
public void IfIsNull<TArg>(TArg argument, string argumentName, string message = null)
{
    // ...
}

For methods that only take a single parameter, the contract can be simplified:

[ContractAnnotation("null => halt")]
public void IfIsNull<TArg>(TArg argument)
{
    // ...
}

I'm still unable to open the Pommalabs.Thrower solution reliably without Visual Studio crashing, so I can't submit a pull request. However, I've tested these changes with simple analogs of some of your methods:

2017-09-18_11-27-38

Can I pass in multiple parameters?

First of all, very nicely done!

I want to be able to pass in multiple parameters. Here is my use case...

if (!File.Exists(pdfPath)) throw new FileNotFoundException("PDF file not found" pdfPath);

I want to change this to ...

Raise<FileNotFoundException>.If(!File.Exists(pdfPath), "PDF file not found", pdfPath);

I can't find a way to pass in the pdfpath as the third parameter so it will be included as the second parameter of the FileNotFoundException. Is this possible?

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.