AlienFruit.Otml.Serializer
1.2.7
dotnet add package AlienFruit.Otml.Serializer --version 1.2.7
NuGet\Install-Package AlienFruit.Otml.Serializer -Version 1.2.7
<PackageReference Include="AlienFruit.Otml.Serializer" Version="1.2.7" />
paket add AlienFruit.Otml.Serializer --version 1.2.7
#r "nuget: AlienFruit.Otml.Serializer, 1.2.7"
// Install AlienFruit.Otml.Serializer as a Cake Addin #addin nuget:?package=AlienFruit.Otml.Serializer&version=1.2.7 // Install AlienFruit.Otml.Serializer as a Cake Tool #tool nuget:?package=AlienFruit.Otml.Serializer&version=1.2.7
C# serializer implementation
<br/>
OtmlSerializer class
You can use the Serializer
to convert the .NET object to OTML and back.
Creating a serializer
Getting serializer with default settings:
var serializer = OtmlSerializer.Create();
<br/>
To create a serializer, you can use the builder:
var serializer = OtmlSerializer.Build()
.WihParserVersion(new Version(1, 0))
.WithEncoding(Encoding.UTF8)
.Create();
Builder methods
SerializerBuilder WihParserVersion(Version version)
Sets the version of the document to serialize to. The version for deserialization is read from the document declaration, or the maximum version of the desalizer is taken from the package if there is no declaration at the beginning of the document.
<br/>
public SerializerBuilder WithEncoding(Encoding encoding)
Specifies the encoding for serialization. When deserializing, the encoding is determined automatically.
If you do not specify the encoding, the default encoding will be selected: UTF-8
<br/>
SerializerBuilder WithContainer(ResolverContainer container)
Allows you to register your implementation to serialize / deserialize data types which the serializer does not support.
Serialization/Deserialization
The next class will be used in examples:
public class Foo
{
public string Name { get; set; }
public string StringValue { get; set; }
public int IntValue { get; set; }
}
Serialization to string
:
var fooClass = new Foo
{
Name = "Name",
StringValue = "Value",
IntValue = 123
};
var serializer = OtmlSerializer.Create();
string result = serializer.Serialize(fooClass);
Serialization to Stream
:
var fooClass = new Foo
{
Name = "Name",
StringValue = "Value",
IntValue = 123
};
var serializer = OtmlSerializer.Create();
using (var stream = File.OpenWrite("C:\\result.otml"))
{
serializer.Serialize(fooClass, stream);
}
Deserialization
Deserialization from string
:
var serializer = OtmlSerializer.Create();
var source =
"@Foo\n" +
"\tName: Name\n" +
"\tStringValue : Value\n" +
"\tIntValue : 123";
Foo result = serializer.Deserialize<Foo>(source);
Deserialization from Stream
:
var source =
"@Foo\n" +
"\tName: Name\n" +
"\tStringValue : Value\n" +
"\tIntValue : 123";
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(source)))
{
Foo result = serializer.Deserialize<Foo>(stream);
}
Product | Versions 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. |
.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. |
-
.NETStandard 2.1
- AlienFruit.Otml (>= 1.2.7)
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.2.7 | 74 | 11/4/2024 |
1.2.6 | 45 | 10/3/2024 |
1.2.5 | 103 | 8/30/2024 |
1.2.4 | 41 | 8/29/2024 |
1.2.2 | 278 | 11/14/2023 |
1.2.1 | 119 | 8/8/2023 |
1.2.0 | 617 | 8/13/2020 |
1.1.1 | 591 | 12/20/2019 |
1.1.0 | 589 | 11/28/2019 |
1.0.8 | 670 | 4/9/2019 |
1.0.7 | 694 | 2/17/2019 |
1.0.6 | 736 | 12/6/2018 |
1.0.5 | 702 | 12/6/2018 |
1.0.4 | 742 | 12/4/2018 |
1.0.3 | 761 | 11/30/2018 |
1.0.2 | 751 | 11/20/2018 |
1.0.2-alpha0001 | 587 | 11/20/2018 |
1.0.0 | 760 | 11/13/2018 |