Coder Social home page Coder Social logo

suubro / paramulate Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 90 KB

Easy Component and Application Parameterisation for C#

C# 100.00%
command-line-parser configuration parameters params argument-parser argument-parsing cli csharp csharp-library csharp-code

paramulate's Introduction

Paramulate

A framework for parameterising C# components and applications

Table of Contents

Summary

Paramulate is a powerful framework for parameterising C# code, from command line arguments, programmatic defaults, config files, databases or any other source you like! It allows you to easily print your parameters to an output stream and see where individual settings came from.

Philosophy

Paramulate creates a culture around the design of your components with respect to parameterisation. It hopes to inspire developers to follow these mantras when writing applications and libraries:

  • Separate logic: Paramulate encourages developers to separate business logic from configuration and settings, behaviour should be agnostic to the input mechanism
  • Author knows best: sensible defaults should be provided by developers to make using their component easier
  • Customer knows better: advanced users what to change everything, and they know their use-case best
  • Seeing is believing: you should be able to easily see the inputs to the code
  • I'm no Sherlock: tracking down the source of parameters should be trivial
  • Consistency without constraint: Paramulate encourages consistency, but doesn't force a dependency

Example

Given the code:

    public interface IUserDatabaseParams
    {
        [Default("server=PROD;Database=UserDb")]
        string ConnectionString { get; }
        
        [Default("2")]
        int NumRetries { get; }
    }
    
    public interface ITranslatorParams
    {
        [Default("AutoDetect")]
        [Alias("i", "input-language", "(Optional) Use this to choose the input language. " +
                                      "Either 'AutoDetect' or a supported language (e.g. 'Spanish')")]
        string InputLanguage { get; }
        
        [Alias("o", "output-language", "Use this to choose the output language. " +
                                       "Any supported language (e.g. 'Mandarin')")]
        string OutputLanguage { get; }
        
        [Override("NumRetries", "3")]
        IUserDatabaseParams UserDb { get;}
    }
    
    public class TranslatorApp
    {
        public static int Main(string[] args)
        {
            var builder = ParamsBuilder<ITranslatorParams>.New("App",
                new CommandLineValueProvider(args)
            );
            var parameters = builder.Build();
            builder.WriteParams(parameters, Console.Out);
            // ... App Code ...
            return 0;
        }
    }

and the command

TranslatorApp.exe -o English --App.UserDb.ConnectionString "Server=TEST;Database=UserDb7E2A"

You would have the following parameter object initilaised for you:

App:
  InputLanguage: "AutoDetect" (From Default)
  OutputLanguage: "English" (From Command Line)
  UserDb:
    ConnectionString: "Server=TEST;Database=UserDb7E2A" (From Command Line)
    NumRetries: 3 (From Override on UserDb)

Features

TODO

paramulate's People

Contributors

dependabot[bot] avatar suubro avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.