Trustsoft.Conditions
2.0.0-rc1
dotnet add package Trustsoft.Conditions --version 2.0.0-rc1
NuGet\Install-Package Trustsoft.Conditions -Version 2.0.0-rc1
<PackageReference Include="Trustsoft.Conditions" Version="2.0.0-rc1" />
paket add Trustsoft.Conditions --version 2.0.0-rc1
#r "nuget: Trustsoft.Conditions, 2.0.0-rc1"
// Install Trustsoft.Conditions as a Cake Addin #addin nuget:?package=Trustsoft.Conditions&version=2.0.0-rc1&prerelease // Install Trustsoft.Conditions as a Cake Tool #tool nuget:?package=Trustsoft.Conditions&version=2.0.0-rc1&prerelease
Trustsoft.Conditions
An extremely easy to use library that helps to check method arguments by conditions.
Usage:
// --- Requires.That() ---
// Requires.That will throw an exception, when some condition is not held
public void FirstMethod(int arg1, int arg2)
{
// This line will throw an exception when arg1 >= arg2
Requires.That(() => arg1).IsLessThan(arg2);
// This will check that arg2
// - is in range 1..46
Requires.That(arg2, "arg2").IsInRange(1,46);
// Several checks can be added.
Requires.That(arg1).IsInRange(100,1000).IsEven().IsTrue(x => x > 50, "Must be over 500");
// Do something
}
// --- Validate.That() ---
// Validate.That makes possible to get a list of all error conditions
public void SecondMethod(string arg1)
{
// Get a list of errors
IEnumerable<KeyValuePair<ViolationType, string>> errors = Validate.That(() => arg1).IsNotNull().GetErrors();
}
Complete list of checks:
The following checks are available. New checks can easily be made by creating an extension method.
For object:
- Evaluate
- IsNull
- IsNotNull
- IsOfType
- IsNotOfType
For Nullable<T>:
- IsNull
- IsNotNull
For Guid:
- IsEmpty
- IsNotEmpty
For bool and bool?:
- IsTrue
- IsFalse
For int and long (and other numeric types):
- IsNegative, IsNotNegative
- IsPositive, IsNotPositive
- IsInRange, IsNotInRange
- IsGreaterThan, IsNotGreaterThan
- IsGreaterOrEqual, IsNotGreaterOrEqual
- IsLessThan, IsNotLessThan
- IsLessOrEqual, IsNotLessOrEqual
- IsEqualTo, IsNotEqualTo
- IsOdd
- IsEven
For string:
- Contains, DoesNotContain
- IsMatch, IsNotMatch
- IsEmpty, IsNotEmpty
- IsNullOrEmpty, IsNotNullOrEmpty
- IsNullOrWhiteSpace, IsNotNullOrWhiteSpace
- StartsWith, DoesNotStartWith
- EndsWith, DoesNotEndWith
- HasLength, DoesNotHaveLength
- IsShorterThan, IsShorterOrEqual
- IsLongerThan, IsLongerOrEqual
For IComparable (Int32, Double, String, Char, DateTime and other classes implementing the interface)
- IsInRange, IsNotInRange
- IsGreaterThan, IsNotGreaterThan
- IsGreaterOrEqual, IsNotGreaterOrEqual
- IsLessThan, IsNotLessThan
- IsLessOrEqual, IsNotLessOrEqual
- IsEqualTo, IsNotEqualTo
For IEnumerable:
- IsEmpty, IsNotEmpty
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. 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 is compatible. 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 is compatible. 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. |
.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 | net35 is compatible. net40 is compatible. net403 was computed. net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 is compatible. net471 was computed. net472 was computed. net48 is compatible. 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. |
-
.NETFramework 3.5
- No dependencies.
-
.NETFramework 4.0
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.7
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0-rc1 | 85 | 1/4/2025 |
1.0.1 | 1,446 | 12/28/2018 |
1.0.0.2 | 1,660 | 3/6/2016 |
1.0.0.1 | 1,515 | 3/6/2016 |
1.0.0 | 1,760 | 3/5/2016 |
0.9.9.9 | 1,561 | 2/21/2016 |
0.9.9.7 | 1,588 | 2/10/2016 |
0.9.9.6 | 1,857 | 2/5/2016 |
0.9.9.5 | 1,566 | 2/5/2016 |
0.9.9.4 | 2,012 | 3/23/2015 |
0.9.9.3 | 1,936 | 3/22/2015 |
0.9.9.2 | 2,198 | 10/17/2014 |
ChangeLog
---------
2.0.0-rc1 Add more targets.
2.0.0-rc1 Update XML Doc comments.
2.0.0-rc1 Update T4 templating.
2.0.0-rc1 Switch to SDK-style project.
2.0.0-rc1 Moved to VS2022.
1.0.1 Update string validations.