Fully managed library providing convenience methods to perform argument checks.
Project repository has been moved to GitLab:
Fully managed library providing convenience methods to perform argument checks.
Home Page: https://gitlab.com/pommalabs/thrower
Fully managed library providing convenience methods to perform argument checks.
Project repository has been moved to GitLab:
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).
Raise ArgumentNullException if an instance of that type has no value.
Would be nice to localize default messages.
It can be done with resources or default .NET messages (they uses resources anyway).
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:
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.