MazeNET.SerializationXml 2.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package MazeNET.SerializationXml --version 2.0.2
                    
NuGet\Install-Package MazeNET.SerializationXml -Version 2.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="MazeNET.SerializationXml" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MazeNET.SerializationXml" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="MazeNET.SerializationXml" />
                    
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 MazeNET.SerializationXml --version 2.0.2
                    
#r "nuget: MazeNET.SerializationXml, 2.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 MazeNET.SerializationXml@2.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=MazeNET.SerializationXml&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=MazeNET.SerializationXml&version=2.0.2
                    
Install as a Cake Tool

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 name
  • AddDeclaration(XmlDeclarationOptions) - Add XML declaration
  • RemoveDeclaration(bool) - Remove XML declaration
  • RemoveSchema(bool) - Remove XML schema
  • RemoveTagCDDATA(bool) - Remove CDATA tags
  • AddPrefix(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

  1. Separation of Concerns - Core business logic separated from infrastructure
  2. Testability - Easy to mock interfaces for unit testing
  3. Maintainability - Clear structure makes code easier to understand and modify
  4. Flexibility - Easy to swap implementations without changing client code
  5. 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 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 is compatible.  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 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 Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.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.

Version Downloads Last Updated
2.1.0 93 2/6/2026
2.0.2 101 12/30/2025
2.0.1 90 12/30/2025
2.0.0 118 12/6/2025

v2.0.2 - Restructured with Clean Architecture, new namespace MazeNET.SerializationXml, added multi-targeting support for .NET Framework 4.8, .NET 9, and .NET 10