com.protostream.nuget.env
1.0.0
dotnet add package com.protostream.nuget.env --version 1.0.0
NuGet\Install-Package com.protostream.nuget.env -Version 1.0.0
<PackageReference Include="com.protostream.nuget.env" Version="1.0.0" />
paket add com.protostream.nuget.env --version 1.0.0
#r "nuget: com.protostream.nuget.env, 1.0.0"
// Install com.protostream.nuget.env as a Cake Addin #addin nuget:?package=com.protostream.nuget.env&version=1.0.0 // Install com.protostream.nuget.env as a Cake Tool #tool nuget:?package=com.protostream.nuget.env&version=1.0.0
CEnvironment NuGet Package
CEnvironment
is a utility package for .NET applications that simplifies reading configuration values from environment variables or a local JSON configuration file. This package allows you to set a local JSON file as a backup configuration source, helping streamline application setup.
Features
- Retrieve configuration values from environment variables or a local JSON file.
- Convert configuration values to different types:
string
,bool
,int
, anddouble
. - Ideal for managing app settings in development and production environments.
Installation
Install via NuGet Package Manager:
dotnet add package com.protostream.nuget.env
Or in Visual Studio:
- Go to Project > Manage NuGet Packages...
- Search for
com.protostream.nuget.env
. - Install the package.
Usage
1. Set a Local Configuration File
To use a local JSON file as a fallback configuration source, set the path using SetLocalConfig
.
using com.protostream.nuget.env;
CEnvironment.SetLocalConfig("path/to/config.json");
2. Retrieve Values
CEnvironment
provides methods to get values as various types.
string? value = CEnvironment.GetValue("MyKey");
bool isEnabled = CEnvironment.GetBool("IsEnabled");
int retryCount = CEnvironment.GetInt("RetryCount");
double threshold = CEnvironment.GetDouble("Threshold");
Example JSON Configuration File
In the JSON file, define keys and values as follows:
{
"MyKey": "SomeValue",
"IsEnabled": "true",
"RetryCount": "5",
"Threshold": "0.75"
}
Methods
- SetLocalConfig(string path): Sets the path for the local JSON file.
- GetValue(string key): Retrieves the value as a string.
- GetBool(string key): Retrieves the value as a boolean.
- GetInt(string key): Retrieves the value as an integer.
- GetDouble(string key): Retrieves the value as a double.
License
This package is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.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 |
---|---|---|
1.0.0 | 165 | 10/14/2024 |