angelinn / Fluffy.INI

Ini file serializer for .NET Standard and .NET Framework.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fluffy.Ini

Build status

What is Fluffy.Ini?

Fluffy.Ini is a .NET Standard and .NET Framework serializer that converts classes to ini configuration files.

Sections

  1. How to use?

  2. Serialization

  3. Deserialization

  4. FluffyIgnore

  5. FluffyComment

  6. Why?

  7. License

How to use?

The main class is FluffyConverter.

Two types of configuration are available

  • Single section - one class with primitive types
  • Multiple sections - one root class with section classes as properties

Can you say that again?

Sure.

Serialization

  • Single section

Example:

public class Settings
{
    public string Resolution { get; set; }
    public int Volume { get; set; }
}

Settings settings = new Settings
{
       Resolution = "1920x1080",
       Volume = 80
};

string ini = FluffyConverter.SerializeObject(settings);
File.WriteAllText("config.ini", ini);

produces

[Settings]
Resolution=1920x1080
Volume=80
  • Multiple sections - one class for the root object and one class per section with only primitive types.

Example:

public class DisplaySettings
{
    public string Resolution { get; set; }
}

public class VolumeSettings
{
    public int Volume { get; set; }
}

public class Settings
{
    public DisplaySettings Display { get; set; }
    public VolumeSettings Volume { get; set; }
}

Settings settings = new Settings
{
    Display = new DisplaySettings
    {
        Resolution = "1920x1080"
    },
    Volume = new VolumeSettings
    {
        Volume = 80
    }
};

string ini = FluffyConverter.SerializeObject(settings);
File.WriteAllText("config.ini", ini);

produces

[Display]
Resolution=1920x1080

[Volume]
Volume=80

Deserialization

string ini = File.ReadAllText("config.ini");
Settings settings = FluffyConverter.DeserializeObject<Settings>(ini);

FluffyIgnore

You can ignore a certain property putting the [FluffyIgnore] attribute above it

public class Settings
{
    [FluffyIgnore]
    public int SettingID { get; set; }
    public int Volume { get; set; }
}

FluffyComment

Want a comment in your ini file? Sure.

public class Settings
{
    [FluffyComment("Wow. What a configuration setting!")]
    public int Volume { get; set; }
}

Why?

I was working on a project at work that needed a configuration file. This project was using .NET Standard 1.4 and I could not find a suitable library that could serialize a class to an ini file. So, there we go!

License

This project is licensed under the terms of the MIT license.

About

Ini file serializer for .NET Standard and .NET Framework.

License:MIT License


Languages

Language:C# 100.0%