GithubHelp home page GithubHelp logo

mcjt / settingsprovider.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jakeginnivan/settingsprovider.net

0.0 2.0 0.0 3.02 MB

Simple Settings provider for .net applications

License: MIT License

Batchfile 0.30% C# 76.71% PowerShell 2.99% XSLT 20.00%

settingsprovider.net's Introduction

SettingsProvider.NET

The aim of settings provider is to quickly give you a simple way to store application settings and read metadata about those settings, like description, name, default values etc

v2 Has added a few things to make versioning easier, the Key attribute allows you to rename properties, and types are no longer fully qualified (so you can move classes)

Usage

Start of by creating your settings class, marking up with metadata

public class MySettings
{
    [DefaultValue("Jake")]
    [DisplayName("Your Name")]
    public string Name { get; set; }

    [DefaultValue(true)]
    [Description("Should Some App Remember your name?")]
    public bool RememberMe { get;set; }

    public List<Guid> Favourites { get;set; }

    [Key("OriginalName")]
    public string Renamed { get; set; }

    [ProtectedString]
    public string Encrypted { get; set; }
}

Reading Settings

var settingsProvider = new SettingsProvider(); //By default uses IsolatedStorage for storage
var mySettings = settingsProvider.GetSettings<MySettings>();
Assert.True(mySettings.RememberMe); 

Saving Settings

var settingsProvider = new SettingsProvider(); //By default uses IsolatedStorage for storage
var mySettings = new MySettings { Name = "Mr Ginnivan" };
settingsProvider.Save(mySettings);

Settings MetaData

This is handy if you want to generate a UI for your settings

var settingsProvider = new SettingsProvider();
foreach (var setting in settingsProvider.ReadSettingMetadata<MySettings>())
{
    Console.WriteLine("{0} ({1}) - {2}", setting.DisplayName, setting.Description, setting.DefaultValue);
}
// Prints:
//
// Your Name () - Jake
// RememberMe (Should Some App Remember your name?) - true

Additional Notes

  • Nested complex types do not have the same features and simply use the DataContractJsonSerializer to serialise

settingsprovider.net's People

Contributors

jakeginnivan avatar anovitsky avatar xelio avatar samgerene avatar

Watchers

 avatar James Cloos 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.