Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kurnakovv/genericenvironment

GenericEnvironment is generic System.Environment class library.
https://github.com/kurnakovv/genericenvironment

csharp nuget

Last synced: about 2 months ago
JSON representation

GenericEnvironment is generic System.Environment class library.

Awesome Lists containing this project

README

        



GenericEnvironment

[![NuGet](https://img.shields.io/nuget/v/Kurnakov.GenericEnvironment.svg)](https://www.nuget.org/packages/Kurnakov.GenericEnvironment)
[![NuGet download](https://img.shields.io/nuget/dt/Kurnakov.GenericEnvironment.svg)](https://www.nuget.org/packages/Kurnakov.GenericEnvironment)
![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2FKurnakovMaksim%GenericEnvironment&countColor=%23263759&style=flat)
[![Build/Test](https://github.com/KurnakovMaksim/GenericEnvironment/actions/workflows/dotnet.yml/badge.svg)](https://github.com/KurnakovMaksim/GenericEnvironment/actions/workflows/dotnet.yml)
[![Codecov](https://codecov.io/gh/kurnakovv/GenericEnvironment/branch/main/graph/badge.svg)](https://codecov.io/gh/kurnakovv/GenericEnvironment)

# Description

GenericEnvironment is generic System.Environment class library.

# How is it work

Environment variables
``` json
...

"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"YourIntVariable": "12345",
"YourBoolVariable": "true",
"YourStringVariable": "YourStringVariable"
...
}

...
```

Get variables with strict types
``` cs
int yourIntVariable = GenericEnvironment.GetEnvironmentVariable("YourIntVariable");
bool yourBoolVariable = GenericEnvironment.GetEnvironmentVariable("YourBoolVariable");
string yourStringVariable = GenericEnvironment.GetEnvironmentVariable("YourStringVariable");

// Output
// yourIntVariable - 12345
// yourBoolVariable - true
// yourStringVariable - "YourStringVariable"
```

Exceptions
``` cs
GenericEnvironment.GetEnvironmentVariable(null); // ArgumentNullException because name parameter is null.
GenericEnvironment.GetEnvironmentVariable("InvalidName"); // InvalidOperationException because variable not found by name.
GenericEnvironment.GetEnvironmentVariable("YourBoolVariable"); // InvalidCastException because type is nullable (bool?)
GenericEnvironment.GetEnvironmentVariable("YourIntVariable"); // FormatException because cannot convert variable to type (bool -> int)
```

# Full docs
* [GenericEnvironment.GetEnvironmentVariable](DocsReadMe.md#genericenvironmentgetenvironmentvariable)
* [GenericEnvironment.TryGetEnvironmentVariable](DocsReadMe.md#genericenvironmenttrygetenvironmentvariable)
* [GenericEnvironment.GetEnvironmentVariableOrDefault](DocsReadMe.md#genericenvironmentgetenvironmentvariableordefault)

# Reason
C# is a strictly typed language and I want to work environment variables as strictly typed variables. This library solves this problem.

# Give a star ⭐
I hope this library is useful for you, if so please give a star for this repository, thank you :)