Skip to content

GenericEnvironment is generic System.Environment class library.

License

Notifications You must be signed in to change notification settings

kurnakovv/GenericEnvironment

Repository files navigation

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

About

GenericEnvironment is generic System.Environment class library.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages