Skip to content

Commit 47565f6

Browse files
author
sam.gerene
committed
[Add] documentation to ISerializer and Serializer
1 parent baf6f02 commit 47565f6

File tree

4 files changed

+179
-42
lines changed

4 files changed

+179
-42
lines changed

SysML2.NET.Serializer/ISerializer.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,78 @@ namespace SysML2.NET.Serializer.Json
2828

2929
using SysML2.NET.DTO;
3030

31+
/// <summary>
32+
/// The purpose of the <see cref="ISerializer"/> is to write an <see cref="IElement"/> and <see cref="IEnumerable{IElement}"/>
33+
/// as JSON to a <see cref="Stream"/>
34+
/// </summary>
3135
public interface ISerializer
3236
{
37+
/// <summary>
38+
/// Serialize an <see cref="IEnumerable{IElement}"/> as JSON to a target <see cref="Stream"/>
39+
/// </summary>
40+
/// <param name="elements">
41+
/// The <see cref="IEnumerable{IElement}"/> that shall be serialized
42+
/// </param>
43+
/// <param name="serializationModeKind">
44+
/// The <see cref="SerializationModeKind"/> to use
45+
/// </param>
46+
/// <param name="stream">
47+
/// The target <see cref="Stream"/>
48+
/// </param>
49+
/// <param name="jsonWriterOptions">
50+
/// The <see cref="JsonWriterOptions"/> to use
51+
/// </param>
3352
void Serialize(IEnumerable<IElement> elements, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions);
3453

54+
/// <summary>
55+
/// Serialize an <see cref="IElement"/> as JSON to a target <see cref="Stream"/>
56+
/// </summary>
57+
/// <param name="element">
58+
/// The <see cref="IElement"/> that shall be serialized
59+
/// </param>
60+
/// <param name="serializationModeKind">
61+
/// The <see cref="SerializationModeKind"/> to use
62+
/// </param>
63+
/// <param name="stream">
64+
/// The target <see cref="Stream"/>
65+
/// </param>
66+
/// <param name="jsonWriterOptions">
67+
/// The <see cref="JsonWriterOptions"/> to use
68+
/// </param>
3569
void Serialize(IElement element, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions);
3670

71+
/// <summary>
72+
/// Asynchronously serialize an <see cref="IEnumerable{IElement}"/> as JSON to a target <see cref="Stream"/>
73+
/// </summary>
74+
/// <param name="elements">
75+
/// The <see cref="IEnumerable{IElement}"/> that shall be serialized
76+
/// </param>
77+
/// <param name="serializationModeKind">
78+
/// The <see cref="SerializationModeKind"/> to use
79+
/// </param>
80+
/// <param name="stream">
81+
/// The target <see cref="Stream"/>
82+
/// </param>
83+
/// <param name="jsonWriterOptions">
84+
/// The <see cref="JsonWriterOptions"/> to use
85+
/// </param>
3786
Task SerializeAsync(IEnumerable<IElement> elements, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken);
3887

88+
/// <summary>
89+
/// Asynchronously serialize an <see cref="IElement"/> as JSON to a target <see cref="Stream"/>
90+
/// </summary>
91+
/// <param name="element">
92+
/// The <see cref="IElement"/> that shall be serialized
93+
/// </param>
94+
/// <param name="serializationModeKind">
95+
/// The <see cref="SerializationModeKind"/> to use
96+
/// </param>
97+
/// <param name="stream">
98+
/// The target <see cref="Stream"/>
99+
/// </param>
100+
/// <param name="jsonWriterOptions">
101+
/// The <see cref="JsonWriterOptions"/> to use
102+
/// </param>
39103
Task SerializeAsync(IElement element, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken);
40104
}
41105
}

SysML2.NET.Serializer/Serializer.cs

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace SysML2.NET.Serializer.Json
2222
{
23-
using System;
2423
using System.Collections.Generic;
2524
using System.IO;
2625
using System.Text.Json;
@@ -31,11 +30,26 @@ namespace SysML2.NET.Serializer.Json
3130
using SysML2.NET.Serializer.Json.AutoGenSerializer;
3231

3332
/// <summary>
34-
/// The purpose of the <see cref="Serializer"/> is to write an <see cref="IEnumerable{T}"/> of
35-
/// <see cref="Element"/> as JSON to a <see cref="Stream"/>
33+
/// The purpose of the <see cref="Serializer"/> is to write an <see cref="IElement"/> and <see cref="IEnumerable{IElement}"/>
34+
/// as JSON to a <see cref="Stream"/>
3635
/// </summary>
3736
public class Serializer : ISerializer
3837
{
38+
/// <summary>
39+
/// Serialize an <see cref="IEnumerable{IElement}"/> as JSON to a target <see cref="Stream"/>
40+
/// </summary>
41+
/// <param name="elements">
42+
/// The <see cref="IEnumerable{IElement}"/> that shall be serialized
43+
/// </param>
44+
/// <param name="serializationModeKind">
45+
/// The <see cref="SerializationModeKind"/> to use
46+
/// </param>
47+
/// <param name="stream">
48+
/// The target <see cref="Stream"/>
49+
/// </param>
50+
/// <param name="jsonWriterOptions">
51+
/// The <see cref="JsonWriterOptions"/> to use
52+
/// </param>
3953
public void Serialize(IEnumerable<IElement> elements, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions)
4054
{
4155
using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
@@ -55,46 +69,88 @@ public void Serialize(IEnumerable<IElement> elements, SerializationModeKind seri
5569
}
5670
}
5771

72+
/// <summary>
73+
/// Serialize an <see cref="IElement"/> as JSON to a target <see cref="Stream"/>
74+
/// </summary>
75+
/// <param name="element">
76+
/// The <see cref="IElement"/> that shall be serialized
77+
/// </param>
78+
/// <param name="serializationModeKind">
79+
/// The <see cref="SerializationModeKind"/> to use
80+
/// </param>
81+
/// <param name="stream">
82+
/// The target <see cref="Stream"/>
83+
/// </param>
84+
/// <param name="jsonWriterOptions">
85+
/// The <see cref="JsonWriterOptions"/> to use
86+
/// </param>
5887
public void Serialize(IElement element, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions)
5988
{
60-
throw new NotImplementedException();
61-
62-
//using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
63-
//{
64-
// element.Serialize(writer, serializationModeKind);
65-
// writer.Flush();
66-
//}
89+
using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
90+
{
91+
var serializationAction = SerializationProvider.Provide(element.GetType());
92+
serializationAction(element, writer, serializationModeKind);
93+
writer.Flush();
94+
}
6795
}
6896

97+
/// <summary>
98+
/// Asynchronously serialize an <see cref="IEnumerable{IElement}"/> as JSON to a target <see cref="Stream"/>
99+
/// </summary>
100+
/// <param name="elements">
101+
/// The <see cref="IEnumerable{IElement}"/> that shall be serialized
102+
/// </param>
103+
/// <param name="serializationModeKind">
104+
/// The <see cref="SerializationModeKind"/> to use
105+
/// </param>
106+
/// <param name="stream">
107+
/// The target <see cref="Stream"/>
108+
/// </param>
109+
/// <param name="jsonWriterOptions">
110+
/// The <see cref="JsonWriterOptions"/> to use
111+
/// </param>
69112
public async Task SerializeAsync(IEnumerable<IElement> elements, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken)
70113
{
71-
throw new NotImplementedException();
72-
73-
//using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
74-
//{
75-
// writer.WriteStartArray();
114+
using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
115+
{
116+
writer.WriteStartArray();
76117

77-
// foreach (var element in elements)
78-
// {
79-
// element.Serialize(writer, serializationModeKind);
80-
// await writer.FlushAsync(cancellationToken);
81-
// }
118+
foreach (var element in elements)
119+
{
120+
var serializationAction = SerializationProvider.Provide(element.GetType());
121+
serializationAction(element, writer, serializationModeKind);
122+
await writer.FlushAsync(cancellationToken);
123+
}
82124

83-
// writer.WriteEndArray();
125+
writer.WriteEndArray();
84126

85-
// await writer.FlushAsync(cancellationToken);
86-
//}
127+
await writer.FlushAsync(cancellationToken);
128+
}
87129
}
88130

131+
/// <summary>
132+
/// Asynchronously serialize an <see cref="IElement"/> as JSON to a target <see cref="Stream"/>
133+
/// </summary>
134+
/// <param name="element">
135+
/// The <see cref="IElement"/> that shall be serialized
136+
/// </param>
137+
/// <param name="serializationModeKind">
138+
/// The <see cref="SerializationModeKind"/> to use
139+
/// </param>
140+
/// <param name="stream">
141+
/// The target <see cref="Stream"/>
142+
/// </param>
143+
/// <param name="jsonWriterOptions">
144+
/// The <see cref="JsonWriterOptions"/> to use
145+
/// </param>
89146
public async Task SerializeAsync(IElement element, SerializationModeKind serializationModeKind, Stream stream, JsonWriterOptions jsonWriterOptions, CancellationToken cancellationToken)
90147
{
91-
throw new NotImplementedException();
92-
93-
//using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
94-
//{
95-
// element.Serialize(writer, serializationModeKind);
96-
// await writer.FlushAsync(cancellationToken);
97-
//}
148+
using (var writer = new Utf8JsonWriter(stream, jsonWriterOptions))
149+
{
150+
var serializationAction = SerializationProvider.Provide(element.GetType());
151+
serializationAction(element, writer, serializationModeKind);
152+
await writer.FlushAsync(cancellationToken);
153+
}
98154
}
99155
}
100-
}
156+
}
Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<Version>0.1.0</Version>
6+
<Description>A .NET implementation of the OMG SysML v2 JSON serializer.</Description>
7+
<PackageId>SysML2.NET.Serializer.Json</PackageId>
8+
<Company>RHEA System S.A.</Company>
9+
<Copyright>Copyright 2022 RHEA System S.A.</Copyright>
10+
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
11+
<RepositoryUrl>https://github.com/RHEAGROUP/SysML2.NET.git</RepositoryUrl>
12+
<RepositoryType>Git</RepositoryType>
13+
<Authors>Sam Gerené</Authors>
14+
<RequireLicenseAcceptance>true</RequireLicenseAcceptance>
15+
<PackageReleaseNotes>
16+
[Initial] Release
17+
</PackageReleaseNotes>
18+
</PropertyGroup>
619

7-
<ItemGroup>
8-
<PackageReference Include="System.Text.Json" Version="6.0.5" />
9-
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="System.Text.Json" Version="6.0.5" />
22+
</ItemGroup>
1023

11-
<ItemGroup>
12-
<ProjectReference Include="..\SysML2.NET\SysML2.NET.csproj" />
13-
</ItemGroup>
24+
<ItemGroup>
25+
<ProjectReference Include="..\SysML2.NET\SysML2.NET.csproj" />
26+
</ItemGroup>
1427

15-
</Project>
28+
<ItemGroup>
29+
<Folder Include="AutoGenSerializer\" />
30+
</ItemGroup>
31+
32+
</Project>

SysML2.NET/SysML2.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1313
<RepositoryUrl>https://github.com/RHEAGROUP/SysML2.NET.git</RepositoryUrl>
1414
<RepositoryType>Git</RepositoryType>
15-
<Authors>Sam Gerene</Authors>
15+
<Authors>Sam Gerené</Authors>
1616
<RequireLicenseAcceptance>true</RequireLicenseAcceptance>
1717
<PackageReleaseNotes>
1818
[Initial] Release

0 commit comments

Comments
 (0)