Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 2.74 KB

ReadMe.md

File metadata and controls

64 lines (49 loc) · 2.74 KB

GenericEnvironment

NuGet NuGet download Visitors Build/Test Codecov

Description

GenericEnvironment is generic System.Environment class library.

How is it work

Environment variables

...

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

...

Get variables with strict types

int yourIntVariable = GenericEnvironment.GetEnvironmentVariable<int>("YourIntVariable");
bool yourBoolVariable = GenericEnvironment.GetEnvironmentVariable<bool>("YourBoolVariable");
string yourStringVariable = GenericEnvironment.GetEnvironmentVariable<string>("YourStringVariable");

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

Exceptions

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

Full docs

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 :)