MazeNET.SerializationXml
2.0.1
See the version list below for details.
dotnet add package MazeNET.SerializationXml --version 2.0.1
NuGet\Install-Package MazeNET.SerializationXml -Version 2.0.1
<PackageReference Include="MazeNET.SerializationXml" Version="2.0.1" />
<PackageVersion Include="MazeNET.SerializationXml" Version="2.0.1" />
<PackageReference Include="MazeNET.SerializationXml" />
paket add MazeNET.SerializationXml --version 2.0.1
#r "nuget: MazeNET.SerializationXml, 2.0.1"
#:package MazeNET.SerializationXml@2.0.1
#addin nuget:?package=MazeNET.SerializationXml&version=2.0.1
#tool nuget:?package=MazeNET.SerializationXml&version=2.0.1
MazeNET.SerializationXml
.NET XML Serialization Helper - Clean Architecture
✨ Features
- ✅ Clean Architecture design pattern
- ✅ Interface-based abstractions
- ✅ Multi-targeting support: .NET Framework 4.8, .NET 9.0, .NET 10.0
- ✅ Nullable reference types support for .NET 9+
- ✅ Comprehensive XML documentation
- ✅ Backward compatible API
🏗️ Architecture
MazeNET.SerializationXml/
├── Core/
│ ├── Interfaces/
│ │ ├── IXmlSerializer.cs
│ │ ├── IXmlFileOperations.cs
│ │ └── IXmlDocumentConverter.cs
│ └── Options/
│ ├── XmlOptions.cs
│ ├── XmlDeclarationOptions.cs
│ └── XmlOptionsBuilder.cs
└── Infrastructure/
├── Converters/
│ ├── XmlSerializerService.cs
│ └── XmlFileOperationsService.cs
└── Extensions/
└── XmlExtensions.cs
📦 Installation
Install from NUGET https://www.nuget.org/packages/MazeNET.SerializationXml/
Install-Package MazeNET.SerializationXml
Or via .NET CLI:
dotnet add package MazeNET.SerializationXml
🚀 Usage
Include package into your project:
using MazeNET.SerializationXml;
using MazeNET.SerializationXml.Core.Interfaces;
using MazeNET.SerializationXml.Core.Options;
📖 API Reference
Using Facade (Simple API - Backward Compatible)
SerializeObject
SerializeObject to XmlDocument:
var doc = XmlConverter.SerializeObject(myObject);
// -- Serialize with config
var doc = XmlConverter.SerializeObject(myObject, builder =>
builder.RootElement("Products")
.RemoveDeclaration()
.RemoveTagCDDATA()
.RemoveSchema());
// -- OR add options with builder function:
var doc = XmlConverter.SerializeObject(myObject).Builder(builder =>
builder.RootElement("RootName")
.RemoveDeclaration()
.RemoveTagCDDATA()
.RemoveSchema());
DeserializeObject
// From XML string
var myObject = XmlConverter.DeserializeObject<MyType>(xmlString);
// From XmlDocument
var myObject = XmlConverter.DeserializeObject<MyType>(xmlDocument);
ConvertToString
// Convert XmlDocument to string
var xmlString = xmlDocument.ConvertToString();
// OR chain with serialization
var xmlString = XmlConverter.SerializeObject(myObject).ConvertToString();
Load file XML to XmlDocument:
var path = @"C:\Invoices.xml";
var doc = XmlConverter.LoadXml(path);
Load file XML to Object:
var path = @"C:\Invoices.xml";
var data = XmlConverter.FileToObject<Invoice>(path);
Save data to file XML:
// Save object to file
var path = @"C:\Invoices.xml";
XmlConverter.SaveToFile(path, myObject);
// Save XmlDocument to file
var path = @"C:\Invoices.xml";
XmlConverter.SaveToFile<Invoice>(path, xmlDocument);
Using Interfaces (Dependency Injection)
For modern applications using dependency injection:
using MazeNET.SerializationXml.Core.Interfaces;
using MazeNET.SerializationXml.Infrastructure.Converters;
// Register in your DI container
services.AddSingleton<IXmlSerializer, XmlSerializerService>();
services.AddSingleton<IXmlFileOperations, XmlFileOperationsService>();
// Use in your classes
public class MyService
{
private readonly IXmlSerializer _xmlSerializer;
private readonly IXmlFileOperations _fileOps;
public MyService(IXmlSerializer xmlSerializer, IXmlFileOperations fileOps)
{
_xmlSerializer = xmlSerializer;
_fileOps = fileOps;
}
public void SaveData(MyData data, string path)
{
var xmlDoc = _xmlSerializer.Serialize(data);
_fileOps.SaveToFile(path, xmlDoc);
}
public MyData LoadData(string path)
{
return _fileOps.LoadFromFile<MyData>(path);
}
}
🔧 Configuration Options
XmlOptionsBuilder Methods
RootElement(string name)- Set root element nameAddDeclaration(XmlDeclarationOptions)- Add XML declarationRemoveDeclaration(bool)- Remove XML declarationRemoveSchema(bool)- Remove XML schemaRemoveTagCDDATA(bool)- Remove CDATA tagsAddPrefix(string)- Add XML prefix
XmlDeclarationOptions Properties
Version- XML version (default: "1.0")Encoding- XML encoding (default: UTF-8)Standalone- Standalone declaration (default: true)
🔄 Migration from v1.x
If you're upgrading from CodeMazeNET.Serialization.Xml v1.x:
// Old namespace (v1.x)
using CodeMazeNET.Serialization.Xml;
// New namespace (v2.x)
using MazeNET.SerializationXml;
The API remains the same, so your existing code will work with just the namespace change!
📝 Example
using MazeNET.SerializationXml;
using MazeNET.SerializationXml.Core.Options;
public class Invoice
{
public int Id { get; set; }
public string Customer { get; set; }
public decimal Amount { get; set; }
}
// Serialize
var invoice = new Invoice
{
Id = 1,
Customer = "John Doe",
Amount = 150.00m
};
var xmlDoc = XmlConverter.SerializeObject(invoice, builder =>
builder.RootElement("Invoice")
.RemoveSchema()
.AddDeclaration(new XmlDeclarationOptions
{
Version = "1.0",
Encoding = Encoding.UTF8,
Standalone = true
}));
// Save to file
XmlConverter.SaveToFile("invoice.xml", invoice);
// Load from file
var loadedInvoice = XmlConverter.FileToObject<Invoice>("invoice.xml");
// Deserialize from XML string
var xmlString = xmlDoc.ConvertToString();
var deserializedInvoice = XmlConverter.DeserializeObject<Invoice>(xmlString);
🎯 Benefits of Clean Architecture
- Separation of Concerns - Core business logic separated from infrastructure
- Testability - Easy to mock interfaces for unit testing
- Maintainability - Clear structure makes code easier to understand and modify
- Flexibility - Easy to swap implementations without changing client code
- Dependency Inversion - High-level modules don't depend on low-level modules
Thanks
Thanks for use, if it's helpful for you please send me 1 star! ⭐
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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 is compatible. 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 Framework | net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- No dependencies.
-
net10.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v2.0.1 - Restructured with Clean Architecture, new namespace MazeNET.SerializationXml, added multi-targeting support for .NET Framework 4.8, .NET 9, and .NET 10