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 pathSetEmptyStringsBuilder.cs
More file actions
53 lines (46 loc) · 1.67 KB
/
SetEmptyStringsBuilder.cs
File metadata and controls
53 lines (46 loc) · 1.67 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
// 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 SetEmptyStringsBuilder : IPropertyVisitor
{
private readonly StringBuilder _builder;
private readonly int _indent;
public SetEmptyStringsBuilder(int indent)
{
_indent = indent;
_builder = new StringBuilder();
}
public void OnProperty(SourceProductionContext context, CsvRecordModel model, CsvPropertyModel property)
{
switch (property.Type)
{
case "string":
if (_builder.Length > 0)
{
_builder.AppendLine();
_builder.AppendLine();
}
_builder.Append(' ', _indent);
_builder.AppendFormat("if ({0} is null)", property.Name);
_builder.AppendLine();
_builder.Append(' ', _indent);
_builder.AppendLine("{");
_builder.Append(' ', _indent + 4);
_builder.AppendFormat("{0} = string.Empty;", property.Name);
_builder.AppendLine();
_builder.Append(' ', _indent);
_builder.Append("}");
break;
}
}
public void Finish(SourceProductionContext context, CsvRecordModel model)
{
}
public string GetResult()
{
return _builder.ToString();
}
}
}