https://github.com/shuttle/shuttle.core.contract
Performs asserts/assumptions to prevent invalid code execution.
https://github.com/shuttle/shuttle.core.contract
Last synced: about 1 month ago
JSON representation
Performs asserts/assumptions to prevent invalid code execution.
- Host: GitHub
- URL: https://github.com/shuttle/shuttle.core.contract
- Owner: Shuttle
- License: bsd-3-clause
- Created: 2017-12-27T07:19:32.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-04T18:58:03.000Z (about 2 months ago)
- Last Synced: 2025-04-04T19:50:12.686Z (about 2 months ago)
- Language: C#
- Size: 77.1 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shuttle.Core.Contract
```
PM> Install-Package Shuttle.Core.Contract
```A guard implementation that performs assertions/assumptions to prevent invalid code execution.
# Guard
```c#
void Against(bool assertion, string message) where TException : Exception
```Throws exception `TException` with the given `message` if the `assertion` is false. If exception type `TException` does not have a constructor that accepts a `message` then an `InvalidOperationException` is thrown instead.
---
```c#
string AgainstEmpty(string? value, [CallerArgumentExpression("value")] string? name = null)
```Throws a `ArgumentNullException` if the given `value` is `null` or empty/whitespace; else returns the `value`.
---
```c#
Guid AgainstEmpty(Guid value, [CallerArgumentExpression("value")] string? name = null)
```Throws and `ArgumentException` when the `value` is equal to an empty `Guid` (`{00000000-0000-0000-0000-000000000000}`); else returns the `value`.
---
```c#
IEnumerable AgainstEmpty(IEnumerable enumerable, [CallerArgumentExpression("enumerable")] string? name = null)
```Throws an `ArgumentException` if the given `enumerable` does not contain any entries; else returns the `enumerable`.
---
```c#
T AgainstNull(T? value, [CallerArgumentExpression("value")] string? name = null)
```Throws a `ArgumentNullException` if the given `value` is `null`; else returns the `value`.
---
```c#
TEnum AgainstUndefinedEnum(object? value, [CallerArgumentExpression("value")] string? name = null)
```Throws an `InvalidOperationException` if the provided `value` cannot be found in the given `TEnum`; else returns the `value` as `TEnum`.