https://github.com/misinformeddna/yellowcounter.nails
A few Ruby and Rails-like extension methods for .NET
https://github.com/misinformeddna/yellowcounter.nails
Last synced: over 1 year ago
JSON representation
A few Ruby and Rails-like extension methods for .NET
- Host: GitHub
- URL: https://github.com/misinformeddna/yellowcounter.nails
- Owner: MisinformedDNA
- License: mit
- Created: 2018-07-05T20:29:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-15T06:07:36.000Z (almost 8 years ago)
- Last Synced: 2024-05-01T14:07:53.434Z (about 2 years ago)
- Language: C#
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/YellowCounter.Nails/)
# YellowCounter.Nails
A few Ruby and Rails-like extension methods for .NET
I always found it odd that when I wanted to know if a value _was_ entered, by the user, I had to ask if it _wasn't_ entered.
Not only that, I had to ask if wasn't null and wasn't empty.
All I want to know is if the user provided a value!
I'm sure there were similar reasons for why Ruby and Ruby on Rails felt then need to include these methods in their frameworks.
This library replicate 4 simple methods with simple abstractions.
As such, this library is very small and simple, but, IMO, the value lies in its simplicity.
## IsNull()
Determines whether the instance is null.
```csharp
object value = null;
int? number = null;
Console.WriteLine(value == null); // true
Console.WriteLine(value.IsNull()); // true
Console.WriteLine(number == null); // true
Console.WriteLine(number.IsNull()); // true
```
## IsEmpty()
Determines whether the collection or string is empty. This is equivalent to testing the length of the collection or string for a value of zero.
```csharp
int[] array = new int[0];
string str = string.Empty;
Console.WriteLine(array.Length == 0); // true
Console.WriteLine(array.IsEmpty()); // true
Console.WriteLine(str.Length == 0); // true
Console.WriteLine(str.IsEmpty()); // true
```
## IsBlank()
Determines whether the instance is null, empty, whitespace or false.
- On a collection, this is equivalent to `IsEmpty()`.
- On a string, this is equivalent to `string.IsNullOrWhiteSpace()`.
- On a bool, this is equivalent to comparing to `false`
- On any other object, this is equivalent to `IsNull`
## IsPresent()
Determines whether the instance is present. This is the opposite of `IsBlank()`