https://github.com/dennis198/dotserial
DotSerial is a lightweight cross-platform C# library for serializing and deserializing .NET objects.
https://github.com/dennis198/dotserial
cross-platform deserialization dotnet json serialization xml yaml
Last synced: 5 months ago
JSON representation
DotSerial is a lightweight cross-platform C# library for serializing and deserializing .NET objects.
- Host: GitHub
- URL: https://github.com/dennis198/dotserial
- Owner: Dennis198
- License: mit
- Created: 2025-08-14T11:28:06.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2026-01-21T16:57:58.000Z (5 months ago)
- Last Synced: 2026-01-22T04:38:25.633Z (5 months ago)
- Topics: cross-platform, deserialization, dotnet, json, serialization, xml, yaml
- Language: C#
- Homepage: https://github.com/Dennis198/DotSerial
- Size: 569 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# DotSerial
DotSerial is a lightweight cross-platform C# library for serializing and deserializing .NET objects.
It allows developers to easily mark properties for serialization using a simple attribute, and provides functionality to save and load
objects from files in different data serialization formats.
If you encounter any errors, you can create an issues at [GitHub](https://github.com/Dennis198/DotSerial/issues),
## Features
- Simple attribute-based serialization with **`[DotSerialName]`** for custom naming
- Ignore properties with **`[DotSerialIgnore]`**
- Save objects to a file and load them back in different data serialization formats
- Serialize/Deserialize .NET objects
- Developer-friendly and lightweight
---
## Installation
Add **DotSerial** to your project [nuget](https://www.nuget.org/packages/Dennis198.DotSerial).
Or include the source in your project.
---
## Usage
### Mark properties with `DotSerialName`
```csharp
using DotSerial;
public class Example
{
[DotSerialName("Example_Boolean")]
public bool Boolean { get; set; }
[DotSerialName("Example_Number")]
public int Number { get; set; }
[DotSerialName("Example_Text")]
public string Text { get; set; }
}
```
### Serialize and Deserialize
```csharp
var obj = new Example
{
Boolean = true,
Number = 42,
Text = "Hello DotSerial!"
};
// Serialize (Json)
var serialized = DotSerialJson.Serialize(obj);
//{
// "Example_Boolean": "true",
// "Example_Number": "42",
// "Example_Text": "Hello DotSerial!"
//}
// Deserialize back
Example result = DotSerialJson.Deserialize(serialized);
```
### Save and Load from File
```csharp
// Save to file
DotSerialJson.SaveToFile("example.json", obj);
// Load from file
Example resultLoad = DotSerialJson.LoadFromFile("example.json");
```
---
## Attribute Reference
- **`[DotSerialName(string name)]`**
- Assign a custom **Name** to each property you want to serialize.
- The name must be unique within the class.
- Properties without this attribute will be named after the propertie.
- **`[DotSerialName(string name)]`**
- Properties with this attribute will be ignored.
Example:
```csharp
[DotSerialName("User_Name")]
public string Name { get; set; }
[DotSerialName("User_Age")]
public int Age { get; set; }
public int Occupation { get; set; }
[DotSerialIgnore]
public int Gender { get; set; }
//{
// "User_Name": "Randy",
// "User_Age": "42",
// "Occupation": "Magician"
//}
```
---
## Notes
- Use DotSerialXml for Xml, DotSerialJson for Json or DotSerialYaml for yaml.
- Properties without **`DotSerialName`** will be named as the propertie.
- Currently only **XMml Json and Yaml format** is supported. Other formats will be added in the future.
---
## License
MIT License – free to use and modify.