1
+ param (
2
+ [ValidateSet (" Engine" , " Rules" )]
3
+ [string ] $project
4
+ )
5
+
6
+ function Get-StronglyTypeCsFileForResx
7
+ {
8
+ param ($xml , $ModuleName , $ClassName )
9
+
10
+ # Example
11
+ #
12
+ # $ClassName = Full.Name.Of.The.ClassFoo
13
+ # $shortClassName = ClassFoo
14
+ # $namespaceName = Full.Name.Of.The
15
+
16
+ $shortClassName = $ClassName
17
+ $namespaceName = $null
18
+
19
+ $lastIndexOfDot = $className.LastIndexOf (" ." )
20
+ if ($lastIndexOfDot -ne -1 )
21
+ {
22
+ $namespaceName = $className.Substring (0 , $lastIndexOfDot )
23
+ $shortClassName = $className.Substring ($lastIndexOfDot + 1 )
24
+ }
25
+
26
+ $banner = @'
27
+ //------------------------------------------------------------------------------
28
+ // <auto-generated>
29
+ // This code was generated by a New-StronglyTypedCsFileForResx funciton.
30
+ // To add or remove a member, edit your .ResX file then rerun Start-ResGen.
31
+ //
32
+ // Changes to this file may cause incorrect behavior and will be lost if
33
+ // the code is regenerated.
34
+ // </auto-generated>
35
+ //------------------------------------------------------------------------------
36
+
37
+ {0}
38
+ '@
39
+
40
+ $namespace = @'
41
+ namespace {0} {{
42
+ {1}
43
+ }}
44
+ '@
45
+
46
+ $body = @'
47
+ using System;
48
+ using System.Reflection;
49
+
50
+ /// <summary>
51
+ /// A strongly-typed resource class, for looking up localized strings, etc.
52
+ /// </summary>
53
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
54
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
55
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
56
+
57
+ internal class {0} {{
58
+
59
+ private static global::System.Resources.ResourceManager resourceMan;
60
+
61
+ private static global::System.Globalization.CultureInfo resourceCulture;
62
+
63
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
64
+ internal {0}() {{
65
+ }}
66
+
67
+ /// <summary>
68
+ /// Returns the cached ResourceManager instance used by this class.
69
+ /// </summary>
70
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
71
+ internal static global::System.Resources.ResourceManager ResourceManager {{
72
+ get {{
73
+ if (object.ReferenceEquals(resourceMan, null)) {{
74
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{3}", typeof({0}).GetTypeInfo().Assembly);
75
+ resourceMan = temp;
76
+ }}
77
+ return resourceMan;
78
+ }}
79
+ }}
80
+
81
+ /// <summary>
82
+ /// Overrides the current thread's CurrentUICulture property for all
83
+ /// resource lookups using this strongly typed resource class.
84
+ /// </summary>
85
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
86
+ internal static global::System.Globalization.CultureInfo Culture {{
87
+ get {{
88
+ return resourceCulture;
89
+ }}
90
+ set {{
91
+ resourceCulture = value;
92
+ }}
93
+ }}
94
+ {2}
95
+ }}
96
+ '@
97
+
98
+ $entry = @'
99
+
100
+ /// <summary>
101
+ /// Looks up a localized string similar to {1}
102
+ /// </summary>
103
+ internal static string {0} {{
104
+ get {{
105
+ return ResourceManager.GetString("{0}", resourceCulture);
106
+ }}
107
+ }}
108
+ '@
109
+ $entries = $xml.root.data | % {
110
+ if ($_ ) {
111
+ $val = $_.value.Replace (" `n " , " `n ///" )
112
+ $name = $_.name.Replace (' ' , ' _' )
113
+ $entry -f $name , $val
114
+ }
115
+ } | Out-String
116
+
117
+ $bodyCode = $body -f $shortClassName , $ModuleName , $entries , $ClassName
118
+
119
+ if ($NamespaceName )
120
+ {
121
+ $bodyCode = $namespace -f $NamespaceName , $bodyCode
122
+ }
123
+
124
+ $resultCode = $banner -f $bodyCode
125
+
126
+ return $resultCode -replace " `r`n ?|`n " , " `r`n "
127
+ }
128
+
129
+ $projectRoot = Split-Path $MyInvocation.InvocationName
130
+ if (-not (Test-Path " $projectRoot /global.json" ))
131
+ {
132
+ throw " Not in solution root"
133
+ }
134
+ $inputFilePath = Join-Path $projectRoot " $project /Strings.resx"
135
+ $outputFilePath = Join-Path $projectRoot " $project /Strings.cs"
136
+ $className = " Microsoft.Windows.PowerShell.ScriptAnalyzer"
137
+ if ($project -eq " Rules" )
138
+ {
139
+ $className += " .BuiltinRules"
140
+ }
141
+ $className += " .Strings"
142
+ $xml = [xml ](Get-Content - raw $inputFilePath )
143
+ $genSource = Get-StronglyTypeCsFileForResx - xml $xml - ModuleName Foo - ClassName $className
144
+ Set-Content - Encoding Ascii - Path $outputFilePath - Value $genSource
0 commit comments