Skip to content

sergeyt/xserializer

Repository files navigation

Build Status Build Status Build status NuGet Version NuGet Downloads

XSerializer

Simple schema-oriented serialization engine for .NET

Features

  • Multiple output formats XML, JSON, JsonML. Easy to implement custom writer/reader.
  • High performance with streaming serialization
  • Fluent API to declare serialization schema

Examples

Example Schema Definition

var schema =
	Scope.New("http://test.com")
	// custom simple types seriablizable to string
	.Type(s => Length.Parse(s), x => x.IsValid ? x.ToString() : "")
	.Type(s => ExpressionInfo.Parse(s), x => x.ToString())
	.Enum(DataElementOutput.Auto);

schema.Element<Report>()
	.Attributes()
	.Add(x => x.Name)
	.End()
	.Elements()
	.Add(x => x.Width)
	.Add(x => x.Body)
	.End();

schema.Element<Body>()
	.Elements()
	.Add(x => x.Height)
	.Add(x => x.ReportItems)
	.End();

var item = schema.Element<ReportItem>()
	.Attributes()
	.Add(x => x.Name)
	.End()
	.Elements()
	.Add(x => x.DataElementName)
	.Add(x => x.DataElementOutput)
	.End();

item.Sub<TextBox>()
	.Elements()
	.Add(x => x.Value)
	.End();

item.Sub<Rectangle>()
	.Elements()
	.Add(x => x.ReportItems)
	.End();

Serialization Example

// init report instance
var report = new Report();
// ...

// get xml/json string using schema defined earlier
var xml = schema.ToXmlString(report);
var json = schema.ToString(report, Format.Json);

// load state from xml string
schema.ReadXmlString(xml, report);

About

Simple schema-oriented serialization engine for .NET.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages