FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PowerShell/src/ResGen/Program.cs at PSObjectFlags · powercode/PowerShell · GitHub
powercode
/
PowerShell
Public
forked from
PowerShell/PowerShell
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
11
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PowerShell
/
src
/
ResGen
/
Program.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
182 lines (156 loc) · 6.38 KB
Breadcrumbs
PowerShell
/
src
/
ResGen
/
Program.cs
Copy path
File metadata and controls
182 lines (156 loc) · 6.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using
System
;
using
System
.
Collections
.
Generic
;
using
System
.
IO
;
using
System
.
Text
;
using
System
.
Xml
.
Linq
;
namespace
ConsoleApplication
{
public
class
Program
{
public
static
void
Main
(
string
[
]
args
)
{
IEnumerable
<
string
>
dirs
;
string
fileFilter
;
if
(
args
.
Length
==
1
)
{
// We are assuming resgen is run with 'dotnet run pathToResxFile.resx'.
fileFilter
=
Path
.
GetFileName
(
args
[
0
]
)
;
string
moduleDirectory
=
Path
.
GetDirectoryName
(
Path
.
GetDirectoryName
(
args
[
0
]
)
)
;
dirs
=
new
List
<
string
>
(
)
{
moduleDirectory
}
;
}
else
{
// We are assuming resgen is run with 'dotnet run'
// so we can use relative path to get a parent directory
// to process all *.resx files in all project subdirectories.
fileFilter
=
"*.resx"
;
dirs
=
Directory
.
EnumerateDirectories
(
".."
)
;
}
foreach
(
string
folder
in
dirs
)
{
string
moduleName
=
Path
.
GetFileName
(
folder
)
;
string
resourcePath
=
Path
.
Combine
(
folder
,
"resources"
)
;
if
(
Directory
.
Exists
(
resourcePath
)
)
{
string
genFolder
=
Path
.
Combine
(
folder
,
"gen"
)
;
if
(
!
Directory
.
Exists
(
genFolder
)
)
{
Directory
.
CreateDirectory
(
genFolder
)
;
}
foreach
(
string
resxPath
in
Directory
.
EnumerateFiles
(
resourcePath
,
fileFilter
)
)
{
string
className
=
Path
.
GetFileNameWithoutExtension
(
resxPath
)
;
string
sourceCode
=
GetStronglyTypeCsFileForResx
(
resxPath
,
moduleName
,
className
)
;
string
outPath
=
Path
.
Combine
(
genFolder
,
className
+
".cs"
)
;
Console
.
WriteLine
(
"ResGen for "
+
outPath
)
;
File
.
WriteAllText
(
outPath
,
sourceCode
)
;
}
}
}
}
private
static
string
GetStronglyTypeCsFileForResx
(
string
xmlPath
,
string
moduleName
,
string
className
)
{
// Example
//
// className = Full.Name.Of.The.ClassFoo
// shortClassName = ClassFoo
// namespaceName = Full.Name.Of.The
string
shortClassName
=
className
;
string
namespaceName
=
null
;
int
lastIndexOfDot
=
className
.
LastIndexOf
(
'.'
)
;
if
(
lastIndexOfDot
!=
-
1
)
{
namespaceName
=
className
.
Substring
(
0
,
lastIndexOfDot
)
;
shortClassName
=
className
.
Substring
(
lastIndexOfDot
+
1
)
;
}
var
entries
=
new
StringBuilder
(
)
;
XElement
root
=
XElement
.
Parse
(
File
.
ReadAllText
(
xmlPath
)
)
;
foreach
(
var
data
in
root
.
Elements
(
"data"
)
)
{
string
value
=
data
.
Value
.
Replace
(
"
\n
"
,
"
\n
///"
)
;
string
name
=
data
.
Attribute
(
"name"
)
.
Value
.
Replace
(
' '
,
'_'
)
;
entries
.
AppendFormat
(
ENTRY
,
name
,
value
)
;
}
string
bodyCode
=
string
.
Format
(
BODY
,
shortClassName
,
moduleName
,
entries
.
ToString
(
)
,
className
)
;
if
(
namespaceName
!=
null
)
{
bodyCode
=
string
.
Format
(
NAMESPACE
,
namespaceName
,
bodyCode
)
;
}
string
resultCode
=
string
.
Format
(
BANNER
,
bodyCode
)
.
Replace
(
"
\r
\n
?|
\n
"
,
"
\r
\n
"
)
;
return
resultCode
;
}
private
static
readonly
string
BANNER
=
@"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a dotnet run from src\ResGen folder.
// To add or remove a member, edit your .resx file then rerun src\ResGen.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
{0}
"
;
private
static
readonly
string
NAMESPACE
=
@"
namespace {0} {{
{1}
}}
"
;
private
static
readonly
string
BODY
=
@"
using System;
using System.Reflection;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""System.Resources.Tools.StronglyTypedResourceBuilder"", ""4.0.0.0"")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class {0} {{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute(""Microsoft.Performance"", ""CA1811:AvoidUncalledPrivateCode"")]
internal {0}() {{
}}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {{
get {{
if (object.ReferenceEquals(resourceMan, null)) {{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager(""{1}.resources.{3}"", typeof({0}).Assembly);
resourceMan = temp;
}}
return resourceMan;
}}
}}
/// <summary>
/// Overrides the current threads CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {{
get {{
return resourceCulture;
}}
set {{
resourceCulture = value;
}}
}}
{2}
}}
"
;
private
static
readonly
string
ENTRY
=
@"
/// <summary>
/// Looks up a localized string similar to {1}
/// </summary>
internal static string {0} {{
get {{
return ResourceManager.GetString(""{0}"", resourceCulture);
}}
}}
"
;
}
}
Back
|
FazBrowse Home
|
New Git URL