YellowMan.Serializer 1.0.2

dotnet add package YellowMan.Serializer --version 1.0.2
                    
NuGet\Install-Package YellowMan.Serializer -Version 1.0.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="YellowMan.Serializer" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YellowMan.Serializer" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="YellowMan.Serializer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YellowMan.Serializer --version 1.0.2
                    
#r "nuget: YellowMan.Serializer, 1.0.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.
#:package YellowMan.Serializer@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YellowMan.Serializer&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=YellowMan.Serializer&version=1.0.2
                    
Install as a Cake Tool

Greetings from YellowMan! I created this serializer as a specific solution for those who, for some reason, are not suitable for others. My code is not a reference, so I ask you not to be surprised by what you have written. This is my first library, so I would be glad to have your feedback 😃

Serialize JSON

We have a person class.

class Person
{
    [Save] public string Name { get; set; }
    public string City;
    [Save] private int Age;

    public Person(string name, string city, int age)
    {
        Name = name;
        City = city;
        Age = age;
    }
}

We create an instance of it and serialize it using the attribute.

Person person = new Person().SetName("Scot").SetCity("NewYork").SetAge(25);

string json = Serialize("person.json", person, "Scot"); // the default value of useAttribute is true

// Scot
// {
//         "Name":"Scot",
//         "Age":25
// }

And without using the attribute.

Person person = new Person().SetName("Scot").SetCity("NewYork").SetAge(25);

string json = Serialize("person.json", person, "Scot", false);

// Scot
// {
//         "Name":"Scot",
//         "City":"New York"
// }

Next, there will be a long example with different types of data.

class Person
{
    [Save] private string Name { get; set; }
    [Save] private string City;
    [Save] private int Age;
    [Save] private float Float = 36.6F;
    [Save] private double Double = 19.000009999D;
    [Save] private decimal Decimal = 26.0000000340044M;
    [Save] private char Char = 'A';
    [Save] private string String = "Alice";
    [Save] private bool Bool = true;
    [Save] private (int, string) Tuple = (15, "GrGrGr");
    [Save] private int[] Array = new int[] { 1, 32, 1234 };
    [Save] private int[,,,] MultiArray = new int[2, 3, 4, 5];
    [Save] private List<int> List = new List<int>() { 2222, 756 };
    [Save] private Dictionary<int, string> Dictionary = new Dictionary<int, string>() { { 0, "2213" }, { 99, "" } };
    [Save] private PersonTwo PersonTwo = new PersonTwo().SetName("Tod").SetCity("Moscow").SetAge(999);
    [Save] private Vector2 Vector2 = new Vector2(5, 1);
    [Save] private DateTime DateTime = new DateTime(2000, 3, 1);
    [Save] private string Null = null;
	
    public Person SetName(string name)
    {
        Name = name;

        return this;
    }

    public Person SetCity(string city)
    {
        City = city;

        return this;
    }

    public Person SetAge(int age)
    {
        Age = age;

        return this;
    }
}

class PersonTwo
{
    public string Name { get; set; }
    public string City;
    public int Age;
    [Save] public float Float = 36.6F; // public
    [Save] private double Double = 19.000009999D; // private

    public PersonTwo SetName(string name)
    {
        Name = name;

        return this;
    }

    public PersonTwo SetCity(string city)
    {
        City = city;

        return this;
    }

    public PersonTwo SetAge(int age)
    {
        Age = age;

        return this;
    }
}

And here's what it looks like.

Person person = new Person().SetName("Scot").SetCity("NewYork").SetAge(25);

string json = Serialize("person.json", person, "Scot");

// Scot
// {
//         "Name":"Scot",
//         "City":"NewYork",
//         "Age":25,
//         "Float":36.6,
//         "Double":19.000009999,
//         "Decimal":26.0000000340044,
//         "Char":'A',
//         "String":"Alice",
//         "Bool":True,
//         "Tuple":[15,"GrGrGr"],
//         "Array":[1,32,1234],
//         "MultiArray":[///[////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]],///[////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]],////[[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]]],
//         "List":[2222,756],
//         "Dictionary":[
//         {
//                 "Key":0,
//                 "Value":"2213"
//         },
//         {
//                 "Key":99,
//                 "Value":""
//         }],
//         "PersonTwo":
//         {
//                 "Name":"Tod",
//                 "City":"Moscow",
//                 "Age":999,
//                 "Float":36.6
//         },
//         "Vector2":
//         {
//                 "X":5,
//                 "Y":1
//         },
//         "DateTime":"01.03.2000 0:00:00",
//         "Null":null
// }

Deserialize JSON

Person person = Deserialize<Person>("person.json", "Scot");

You can serialize almost any data, including tuples and multidimensional arrays. Use it! P.S. I hope there are no bugs :p

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.

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.0.2 242 4/22/2025
1.0.1 217 4/22/2025
1.0.0 215 4/22/2025