Coder Social home page Coder Social logo

dirt.env's Introduction

Dirt.Env

Dirt.Env is a simple library for working with environment variables in .NET.

Its goal is to provide some convenience and safety around working with environment variables.

Usage

You can use the default constructor of the Env class to get access to the current environment variables.

var env = new Dirt.Env();

This class implements the IEnv interface, which allows accessing the environment variables in a read-only manner through the API of IReadOnlyDictionary<string, string>.

In addition to general dictionary access, the path environment variable can be accessed through the Path property which returns a read-only list.

You can also use the path separation logic on any environment variable by using the GetPathSeparatedValue(string) method.

The path separator of the current system will be used by default, but this can be configured by using the EnvBuilder class.

EnvBuilder

The EnvBuilder class makes it easy to build up an Env instance with custom environment variables.

var env = new EnvBuilder()
    .WithSystemEnvironment()
    .SetVariable("MY_CUSTOM_VARIABLE", "MY_VALUE")
    .Build();

You can also work with the path variable in a natural way. The underlying path variable used and path separator will be managed by the EnvBuilder class.

var env = new EnvBuilder()
    .WithSystemEnvironment()
    .AppendPath("C:\\My\\Path")
    .AppendPath("C:\\My\\OtherPath")
    .Build();

When working with paths, the EnvBuilder class provides three ways it can handle duplicate paths being appended or prepended:

  • IfDuplicatePath.Supersede will remove any duplicate paths from the list before adding the new path. This is the default.
  • IfDuplicatePath.Ignore will always add the path if it is already in the list. This will result in duplicate paths.
  • IfDuplicatePath.Skip will not add the path if it is already in the list.

This enum is located in the Dirt.Environment namespace.

These strategies can be configured with every addition to the builder or set a default. When set in the builder it will only take effect for future additions.

License

MIT

dirt.env's People

Contributors

dependabot[bot] avatar rhysparry avatar

Watchers

 avatar

dirt.env's Issues

Add XML Documentation

To make it easier to use the library with IDE support, include XML documentation as part of the NuGet package.

Add a changelog

Include a changelog to make it easier to see what's changed between releases

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.