This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMessagePackFormatterSerializeBuilder.cs
More file actions
67 lines (59 loc) · 2.01 KB
/
MessagePackFormatterSerializeBuilder.cs
File metadata and controls
67 lines (59 loc) · 2.01 KB
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
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
namespace NuGet.Insights
{
public class MessagePackFormatterSerializeBuilder : IPropertyVisitor
{
private readonly StringBuilder _builder;
private readonly int _indent;
public MessagePackFormatterSerializeBuilder(int indent)
{
_indent = indent;
_builder = new StringBuilder();
}
public void OnProperty(SourceProductionContext context, CsvRecordModel model, CsvPropertyModel property)
{
if (_builder.Length > 0)
{
_builder.AppendLine();
}
_builder.Append(' ', _indent);
switch (property.Type)
{
case "bool":
case "byte":
case "char":
case "double":
case "float":
case "int":
case "long":
case "sbyte":
case "string":
case "short":
case "uint":
case "ulong":
case "ushort":
_builder.AppendFormat("writer.Write(value.{0});", property.Name);
break;
default:
if (property.IsEnum)
{
_builder.AppendFormat("writer.Write(({0})value.{1});", property.UnderlyingEnumType, property.Name);
}
else
{
_builder.AppendFormat("MessagePackSerializer.Serialize(ref writer, value.{0}, options);", property.Name);
}
break;
}
}
public void Finish(SourceProductionContext context, CsvRecordModel model)
{
}
public string GetResult()
{
return _builder.ToString();
}
}
}