UtilityPack.Settings 1.2.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package UtilityPack.Settings --version 1.2.2                
NuGet\Install-Package UtilityPack.Settings -Version 1.2.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UtilityPack.Settings" Version="1.2.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UtilityPack.Settings --version 1.2.2                
#r "nuget: UtilityPack.Settings, 1.2.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UtilityPack.Settings as a Cake Addin
#addin nuget:?package=UtilityPack.Settings&version=1.2.2

// Install UtilityPack.Settings as a Cake Tool
#tool nuget:?package=UtilityPack.Settings&version=1.2.2                

Settings

Settings expose a class to easly manage persistent data of a programa, but with additional options, like crypting the final file, or choosing exactly where place it on disk relative to the program executible.

Every program can create a definition class and then create an instance of Setting passing the definition class as a generic parameter, this allow to work with specific types when reading or writing data using the instance.

Enum SettLocation

  • ROOT
    C:/
  • CUSTOM
    Custom Path
  • EXEDIR
    ../exe_directory/
  • PROGDATA
    C:/ProgramData/
  • APPDATAROAM
    ../AppData/Roaming
  • APPDATALOCA
    ../AppData/Local

Class Settings< T >

Property

  • data : public T
    Property holding all the data, Loaded after calling "Load()" and saved on disk after calling "Save()"
  • path : public string
    Path where save the setting file. (Default same directory as the exe)
  • name : public string
    Name of the setting file, withotu extension. (Default "settings")
  • crypt : public bool
    If true, automatically use "SaveCrypt()" when calling "Save()" and "LoadCrypt()" when calling "Load()". (Default false)
  • prettyPrint : public bool
    If true pretty print the json file

Methods

  • SetLocation(SettLocation location, string? customDir) : void
    Set the settings file save location. When location == SettLocation.CUSTOM, the "customDir" parameter work as a full path. In every other cases "customDir" works as an additional final string to the base path.

  • Load()
    Load the settings from the file and parse them to the "data" property. If the file is not present it will be created with the default parameters

  • Save()
    Save the settings data to file

  • LoadCrypt()
    Load the settings from the file, decrypt and parse them to the "data" property. If the file is not present it will be created with the default parameters. Automaticlay done when calling "Load()" if "crypt" is set to true

  • SaveCrypt()
    Save the settings data to file, but crypting them, making it unreadable to human. Automaticlay done when calling "Save()" if "crypt" is set to true

Example

    // Definition class with default values
    public class ProgramData 
    {
        public bool   isActive { get; set;} = false;
        public string Name     { get; set;} = "Michael";
        public int    Uses     { get; set;} = 123;
    }

    class Program
    {
        // Create the Setting instance, passing the definition class as generic parameter
        // Making the instance static allow us to access data from every where in the program
        public static Settings<ProgramData> setting = new();

        static void Main()
        {
            // Choose setting configuration ad load the data
            setting.crypt = true;
            setting.SetLocation(SettLocation.PROGDATA, "ProgramName/");
            setting.Load();
          
            // Change a some values
            setting.data.Uses += 1;

            // Save the setting to file
            setting.Save();

            // Read a value from the setting data
            string name = setting.data.Name;
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp3.0 is compatible.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.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.2.4 463 5/31/2022
1.2.3 395 5/31/2022
1.2.2 417 5/16/2022
1.2.1 415 3/29/2022
1.1.2 420 3/4/2022
1.1.1 433 2/17/2022
1.1.0 418 2/4/2022
1.0.3.2 431 2/4/2022
1.0.3.1 421 1/31/2022
1.0.3 435 1/31/2022
1.0.2 255 1/5/2022
1.0.1 254 1/4/2022
1.0.0 257 12/24/2021