HanumanInstitute.Validators
2.1.8
dotnet add package HanumanInstitute.Validators --version 2.1.8
NuGet\Install-Package HanumanInstitute.Validators -Version 2.1.8
<PackageReference Include="HanumanInstitute.Validators" Version="2.1.8" />
<PackageVersion Include="HanumanInstitute.Validators" Version="2.1.8" />
<PackageReference Include="HanumanInstitute.Validators" />
paket add HanumanInstitute.Validators --version 2.1.8
#r "nuget: HanumanInstitute.Validators, 2.1.8"
#:package HanumanInstitute.Validators@2.1.8
#addin nuget:?package=HanumanInstitute.Validators&version=2.1.8
#tool nuget:?package=HanumanInstitute.Validators&version=2.1.8
HanumanInstitute.Validators
Common validator functions and other extension methods that are used all the time.
<a href="https://www.nuget.org/packages/HanumanInstitute.Validators/"><img src="https://img.shields.io/nuget/v/HanumanInstitute.Validators.svg"></a>
The main goal of this assembly is to add helper extension methods to validate arguments.
Tired of repeating this in every method?
if (value == null) { throw new NullReferenceException(nameof(value)); }
_field = value;
Now you can instead write this!
_field = Check.NotNull(value)
v1 used this syntax
_field = value.CheckNotNull(nameof(value));
Other super useful functions
Check.Range(value, min: 0);
var msg = "Value {0} is invalid.".FormatInvariant(value);
var result = await list.ForEachOrderedAsync(x => DoSomeWorkAsync(x));
Setup
Add NuGet package HanumanInstitute.Validators
Validation Methods
Check.NotNull(Object) / Object.CheckNotNull()
Checks that Object is not null. Throws an exception for parameter 'name' if it is null. Returns Object if it is valid.
Check.NotNullOrEmpty(string) / string.CheckNotNullOrEmpty()
Checks that String is not null or empty.
Check.NotNullOrEmpty(enumerable) / enumerable.CheckNotNullOrEmpty()
Checks that IEnumerable is not null or empty.
Check.AssignableFrom(type, baseType) / type.CheckAssignableFrom(baseType)
Checks that Type can be assigned from baseType (object of same type is valid).
Check.DerivesFrom(type, baseType) / type.CheckDerivesFrom(baseType)
Checks that Type derives from baseType (object of same type is invalid).
Check.EnumValid<T>(enum) / enum.CheckEnumValid()
Checks that an enumeration value is valid. Also works with Flags enumerations.
Check.Range(comparable, min, minInclusive, max, maxInclusive) / comparable.CheckRange
Checks whether value is within valid range. It throws short and meaningful exceptions based on whether min and max were set.
Check.Range(myInt, min: -10, max: 10) // myInt must be between -10 and 10.
Check.Range(myFloat, min: 0, minInclusive: false) // myFloat must be greater than 0.
Check.IsInRange(comparable, min, minInclusive, max, maxInclusive) / comparable.CheckIsInRange
Returns whether value is within valid range.
RangeClusiveAttribute(min, minInclusive, max, maxInclusive)
Validates that a property is within range, allowing to exclude the minimum or maximum value.
List Extensions
ICollection/IList.AddRange()
List.AddRange is notably missing from standard IList interface!! Fixed.
IDictionary.GetValueOrDefault(key, defaultValue = default)
Gets the value for a key, or defaultValue if the key is not found.
IList.AsReadOnly()
List.AsReadOnly is also missing from standard IList interface.
IEnumerable.ForEachAsync(task, callback, maxParallel = 10)
Runs a task on each item of IEnumerable with up to specified parallel tasks. Callback will be invoked once each task is completed, in no particular order.
IEnumerable.ForEachOrderedAsync(task, maxParallel = 10)
Runs a task on each item of IEnumerable with up to specified parallel tasks. It will return an IList containing the result of each operation while preserving the order.
var result = await list.ForEachOrderedAsync(x => DoSomeWorkAsync(x));
IList<T>.CastList<TTo, T>()
Creates a casted list that exposes a derived type while maintaining the same references.
String Extensions
Object.ToStringInvariant()
Converts a value to string using InvariantCulture.
StringBuilder.AppendFormatInvariant()
Formats a string using invariant culture and appends it to the StringBuilder.
String.HasValue()
Returns whether the string contains a value. It is the equivalent of !string.IsNullOrEmpty(value).
String.HasText()
Returns whether the string contains non-whitespace text. It is the equivalent of !string.IsNullOrWhiteSpace(value).
String.Default(defaultValue)
Returns specified default value if the value is null or empty.
String.FormatInvariant(args)
Formats a string using invariant culture. This is a shortcut for string.format(CultureInfo.InvariantCulture, ...)
String.EqualsInvariant(value)
Returns whether the two string values are equal, using InvariantCultureIgnoreCase. Note that extension methods work on null values.
String.Parse<T>()
Parses a string value into specified data type and returns null if conversion fails.
Command Extensions
ICommand.Execute()
Executes a command. This overloads passes null parameter.
ICommand.CanExecute()
Returns whether the command can execute in its current state. This overloads passes null parameter.
ICommand.ExecuteIfCan()
Executes the command if CanExecute if true.
Cloning
Cloning.CopyAllFields(source, target)
Copies all fields from one instance of a class to another using reflection.
Cloning.DeepClone(source, serializerContext)
Performs a deep clone of specified object by serializing and deserializing it. The second parameter is optional and allows passing a Json Source Generator context for increased performance and to avoid reflection.
Other Extensions
Enum.GetFlags()
Returns a list of all enumeration flags that are contained in an enumeration value.
IComparable.Clamp(min, max)
Forces a value to be within specified range.
Type.IsAssignableFromGeneric(genericType)
Returns whether given type is assignable from specified generic base type.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Text.Json (>= 10.0.10)
-
net10.0
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- System.Text.Json (>= 10.0.10)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on HanumanInstitute.Validators:
| Package | Downloads |
|---|---|
|
OntraportApi
Strongly-Typed .NET API for Ontraport (Marketing Automation System) |
|
|
HanumanInstitute.LibMpv
MPV implementation for .NET including OpenGL, Native and Software renderers |
|
|
HanumanInstitute.FFmpeg
.Net wrapper for media encoders such as FFmpeg, X264 and X265, including Avisynth and VapourSynth support. |
|
|
MpvIpcController
Provides remote control of MPV video player via IPC protocol via .NET |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.8 | 97 | 9/17/2026 |
| 2.1.7 | 220 | 8/18/2026 |
| 2.1.6 | 123 | 8/18/2026 |
| 2.1.5 | 329 | 8/8/2026 |
| 2.1.4 | 110 | 8/8/2026 |
| 2.1.3 | 118 | 8/7/2026 |
| 2.1.2 | 1,504 | 3/9/2026 |
| 2.1.1 | 1,453 | 9/14/2024 |
| 2.1.0 | 291 | 9/12/2024 |
| 2.0.1 | 299 | 9/4/2024 |
| 2.0.0 | 1,108 | 8/21/2024 |
| 1.2.2 | 6,413 | 3/19/2023 |
| 1.2.1 | 1,866 | 8/18/2022 |
| 1.2.0 | 1,471 | 6/4/2022 |
| 1.1.0 | 704 | 1/26/2022 |
| 1.0.8 | 4,229 | 10/29/2020 |
| 1.0.7 | 703 | 10/27/2020 |
| 1.0.6 | 643 | 10/26/2020 |
| 1.0.5 | 1,094 | 10/15/2020 |
| 1.0.4 | 1,234 | 10/3/2020 |