Daniel-Balk / Dalk.PropertiesSerializer

a properties serializer for c#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dalk.PropertiesSerializer

A properties serializer for C#

Documentation

import the classes

// import the serializer classes
using Dalk.PropertiesSerializer;

create a type to serialize

using Dalk.PropertiesSerializer;

public class TestObject
{
    // use the attribute to specify a custom name
    [PropertyName("test_int")]
    public int TestInt { get; set; }
    public string TestString { get; set; }
    public bool TestBool { get; set; }
    public SecondTestObject SecondTestObject { get; set; }
}

serialize an object

string properties = Serializer.Serialize(@object);

deserialize a string

var @object = Serializer.Deserialize<TestObject>(properties);

create a custom type serializer

using System;
using Dalk.PropertiesSerializer.TypeSerializers;

[TypeSerializer]
public class TestTypeSerializer : ITypeSerializer
{
    public object Deserialize(string o) => TestType.Parse(o);

    Type type = typeof(TestType);
    public Type GetCType() => type;

    public string Serialize(object o) => o.ToString();
}

register all type type serializers from the current assembly

Serializer.LoadTypeSerializersFromAssembly(Assembly.GetAssembly(GetType()));

add an object as a type serializer

Serializer.AddCustomTypeSerializer(new TestTypeSerializer());

About

a properties serializer for c#

License:GNU General Public License v3.0


Languages

Language:C# 61.1%Language:HTML 14.4%Language:CSS 12.2%Language:JavaScript 8.6%Language:Batchfile 2.1%Language:Dockerfile 1.5%