-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (70 loc) · 2.49 KB
/
Program.cs
File metadata and controls
77 lines (70 loc) · 2.49 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
68
69
70
71
72
73
74
75
76
77
namespace ManualGenerator
{
using Microsoft.DevSkim.LanguageProtoInterop;
using System.Text;
/// <summary>
/// Run this to generate the update settinsg method for all implemented settings
/// </summary>
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine(Execute());
}
public static string Execute()
{
StringBuilder source = new StringBuilder();
source.Append($@"// <auto-generated/>
namespace Microsoft.DevSkim.VisualStudio
{{
using System;
using Microsoft.DevSkim.LanguageProtoInterop;
using System.Collections.Generic;
internal partial class VisualStudioSettingsManager
{{
partial void UpdateSettings(string propertyName)
{{
switch(propertyName)
{{
");
string baseIndentation = " ";
var props = typeof(IDevSkimOptions).GetProperties().Select(x => (x.Name, x.PropertyType));
foreach (var prop in props)
{
var typeNameString = GetTypeNameString(prop.PropertyType);
source.Append($@"{baseIndentation}case ""{prop.Name}"":
{{
var res = Get<{typeNameString}>(propertyName);
if (res.Item1 == ValueResultEnum.Success)
{{
_currentSettings.{prop.Name} = res.Item2{ConditionallyUseNullCoalescing(typeNameString)}
}}
break;
}}
");
}
source.Append($@"{baseIndentation}default: break;
}}
}}
}}
}}");
return source.ToString();
}
private static string ConditionallyUseNullCoalescing(string typeNameString)
{
return typeNameString.StartsWith("List") ? $" ?? new {typeNameString}();" : ";";
}
private static string GetTypeNameString(Type propPropertyType)
{
return propPropertyType.Name switch
{
"String" => "string",
"List`1" => $"List<{GetTypeNameString(propPropertyType.GetGenericArguments()[0])}>",
"Boolean" => "bool",
"Int32" => "int",
"CommentStylesEnum" => "CommentStylesEnum",
_ => "string"
};
}
}
}