Config-Handling.Net 1.0.8

Additional Details

No longer supported version.

There is a newer version of this package available.
See the version list below for details.
dotnet add package Config-Handling.Net --version 1.0.8                
NuGet\Install-Package Config-Handling.Net -Version 1.0.8                
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="Config-Handling.Net" Version="1.0.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Config-Handling.Net --version 1.0.8                
#r "nuget: Config-Handling.Net, 1.0.8"                
#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 Config-Handling.Net as a Cake Addin
#addin nuget:?package=Config-Handling.Net&version=1.0.8

// Install Config-Handling.Net as a Cake Tool
#tool nuget:?package=Config-Handling.Net&version=1.0.8                

ConfigHandling.Net

ConfigHandling.Net takes care of all your config or options objects. It takes care of saving, loading, and persistence of objects in memory. Config objects are saved in a centralized location.

Table of contents

Usage

Calling Objects

This library is made to make simple calls to config objects:

ExampleConfig Config = ConfigMapper.Get<ExampleConfig>();

INewConfig

This interface allows the programmer to create a config file for when the config files are missing or never have been given. The interface only adds one method: SetNewInformation()

This method is called upon when the system detects that it's missing the config file. It then initializes a new instance of that config type and checks whether or not it has implemented the interface. If it has SetNewInformation() is called. In this method, the programmer can put down which default values need to be filled in. If the interface has not been implemented, the system creates a config file based upon a normally constructed object of that type.

The reason it is recommended you always use this interface comes from the amount of data that is sometimes assigned to the properties of the config object. It not necessary to initialize all its default values every time with preset values.

Config Objects

Customizing the XML

To customize how your data is saved, you can use the XML serialization attributes or use the IXMLSerializable Interface to expand your data handling further. To customize config objects use the following directions: XML Attributes MSDN

Customizing the JSON

For .Net Framework

The .Net framework version of this library uses the DataContractJsonSerializer. When .Net framework 5 drops, this will be replaced with the new JSON system. To customize config objects use the following directions: How to use DataContractJsonSerializer

For .Net Core

The .Net core version uses the new System.Text.Json serialization. To customize config objects use the following directions: Customize JSON names and values

Compile

For .Net Core

This section is only required when not using the Nuget package. To compile for .net Core add an conditional compilation symbol named: 'NETCORE'.
Found under Properties → Build.

Compatiblity

The C# code is .Net 4.8 and .Net-Core 3.1 Compatible

Example

This ExampleConfig class has 3 properties that get saved to a JSON file.

  • The class gets save to: "%Config Folder%\DaanV2\General\Example Config.config"
  • INewConfig is implemented so that when ConfigMapper needs to create the fill, the object gets filled with default values.

Class file of ExampleConfig

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using DaanV2.Config;

[Config("Example Config", "DaanV2\\General")]
[Serializable, DataContract]
public class ExampleConfig : INewConfig {
    /// <summary>Creates a new instance of <see cref="ExampleConfig"/></summary>
    public ExampleConfig() {
        this.MultiThread = false;
        this.TrimData = false;
        this.DefaultValues = new List<string>();
    }

    /// <summary>Some property for the config</summary>
    [DataMember]
    public Boolean MultiThread { get; set; }

    /// <summary>Some property for the config</summary>
    [DataMember]
    public Boolean TrimData { get; set; }

    /// <summary>Some property for the config</summary>
    [DataMember]
    public List<String> DefaultValues { get; set; }

    /// <summary>Fills the object with default values when the ConfigMapper cannot find the file containing the data</summary>
    public void SetNewInformation() {
        this.MultiThread = true;
        this.TrimData = true;
        this.DefaultValues = new List<string>() {
            "Foo",
            "Bar"
        };
    }
}

JSON file of ExampleConfig

{
    "MultiThread": true,
    "TrimData": true,
    "DefaultValues": [ "Foo", "Bar" ]
}

Configuring the system

The ConfigMapper reads its options from the ConfigLoader class. Which reads it value from a config.ini file. If it does not exist, then it is created with default values. This file is written to the same folder as the executing program.

Default config.ini file

Config Extension=.config
Config Folder=\configs\
Config Serializer Name=json

Problems

If any problem is arising, then explore the possibility of preloading the system. Either through a task or just call one of the following methods:

Name Description
ConfigOptions.Preload Causes a 10 ms delay while the config.ini file is loaded/created and set.
ConfigLoader.Preload Causes a 20 ms delay while it calls ConfigOptions.Preload, and initializes it own internal serialization factories.
ConfigMapper.Preload Causes a 30 ms delay while it calls ConfigLoader.Preload, after which it starts on reflecting on all loaded assemblies and collect all config objects marked as config objects, whereby each config gets loaded into memory and files created if missing.

If problems persist report them as issues to the repository

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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • 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.

Added the ability to not use presistance on config objects