Skip to content

shirakawayohane/Config.cs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Config.cs

Installation

The library provides in NuGet Package. This is available for .NET Standard 2.0 compatibles.

dotnet add package Config.cs --version 2.0.1

Important Note

For the flexibility and performance and maintanance reasons, Public API has drastically changed from v1.0^. Please note that there is no compatibility between v1 and v2.

This library use dynamic code generation for flexibility, which means this lib cannot be used in AOT environment (e.g. IL2CPP of Unity) But, feel free to send PRs or issues. Contribution is welcome.

Quick Start

Usage is very simple. Suppose that you want to perpetuate static class like this.

public static class TestClass
{
    public static int value1 = 1;
    public static string value2 = "abc";
    public static Alphabet alphabet = Alphabet.B;
    public static int[] arr = new[] { 1, 2, 3, 4 };

    public static class ChildClass
    {
        public static float value = 1;
        public static class GrancChildClass
        {
            public static string message = "hello";
        }
    }
}
public enum Alphabet
{
    A, B, C
}

First, Instantiate serializer. You can control how to serialize/deserialize data by specifying Resolver of Utf8Json

using Config.cs;
using Utf8Json;
/*=================================*/

var serializer = new StaticJsonSerializer(typeof(ParentClass), Utf8Json.Resolvers.StandardResolver.Default);

You can call Config.cs.JsonSerializer.Serialize/Deserialize

//static class -> byte[] (UTF8)
byte[] data = serializer.Save();

//byte[] -> directory write to static class
serializer.Load(byte[] data);

In this case, the decoded data will be

{"value1":1,"value2":"abc","alphabet":"B","arr":[1,2,3,4],"ChildClass":{"value":1,"GrancChildClass":{"message":"hello"}}}

Special Thanks

Thanks to Utf8Json library, the development was smooth, and thic package made stable and fast.

I owe to the author neuecc.

About

This repository aims to help us to configure in type safe way, by serializing/deserializeing static classes.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages