1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ConverterSerializationGenerator.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.CodeDom.Compiler;
using NosSmooth.PacketSerializersGenerator.Data;
using NosSmooth.PacketSerializersGenerator.Extensions;
namespace NosSmooth.PacketSerializersGenerator;
/// <summary>
/// Various templates for converter serialization.
/// </summary>
public class ConverterSerializationGenerator
{
private readonly string _builderVariable = "builder";
private readonly IndentedTextWriter _textWriter;
/// <summary>
/// Initializes a new instance of the <see cref="ConverterSerializationGenerator"/> class.
/// </summary>
/// <param name="textWriter">The text writer.</param>
public ConverterSerializationGenerator(IndentedTextWriter textWriter)
{
_textWriter = textWriter;
}
/// <summary>
/// Push level to the string enumerator.
/// </summary>
/// <param name="separator">The separator.</param>
public void SetAfterSeparatorOnce(char separator)
{
_textWriter.WriteLine(@$"{_builderVariable}.SetAfterSeparatorOnce('{separator}');");
}
/// <summary>
/// Push level to the string enumerator.
/// </summary>
/// <param name="separator">The separator.</param>
public void PushLevel(char separator)
{
_textWriter.WriteLine
(@$"{_builderVariable}.PushLevel('{separator}');");
}
/// <summary>
/// Pop level from the string enumerator.
/// </summary>
public void PopLevel()
{
_textWriter.WriteLine($"{_builderVariable}.PopLevel();");
}
/// <summary>
/// Prepare the level to the string enumerator.
/// </summary>
/// <param name="separator">The separator.</param>
public void PrepareLevel(char separator)
{
_textWriter.WriteLine
($@"{_builderVariable}.PrepareLevel('{separator}');");
}
/// <summary>
/// Prepare the level to the string enumerator.
/// </summary>
public void RemovePreparedLevel()
{
_textWriter.WriteLine($@"{_builderVariable}.RemovePreparedLevel();");
}
}