-
Notifications
You must be signed in to change notification settings - Fork 88
/
ResourcesTransform.xslt
164 lines (139 loc) · 4.94 KB
/
ResourcesTransform.xslt
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
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:eventns="http://schemas.microsoft.com/win/2004/08/events"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:user="http://example.com/whatever"
version="1.0"
>
<xsl:output method="text"/>
<!--
This is the main template to generate the output file. This template
contains apply-templates nodes that fill out various parts of the file.
-->
<xsl:template match="/">
<xsl:text>//
//
//
// IMPORTANT: This is generated code. Do not edit.
//
//
//
using System;
using System.Collections.Concurrent;
using System.Globalization;
using System.ComponentModel;
using System.Diagnostics;
using System.Resources;
namespace MS.Dbg
{
internal class Resources
{
private ResourceManager m_resMan;
private CultureInfo m_culture;
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources( CultureInfo ci )
{
m_culture = ci;
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal ResourceManager ResourceManager
{
get
{
if( null == m_resMan )
{
m_resMan = new ResourceManager( "MS.Dbg.Resources", typeof( Resources ).Assembly );
}
return m_resMan;
}
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
internal CultureInfo Culture
{
get { return m_culture; }
set { m_culture = value; }
}
private ConcurrentDictionary< ResourceId, string > m_resources = new ConcurrentDictionary< ResourceId, string >();
public string this[ ResourceId index ]
{
get
{
string resource;
if( !m_resources.TryGetValue( index, out resource ) )
{
resource = ResourceManager.GetString( index.ToString(), m_culture );
m_resources.TryAdd( index, resource );
}
if( null == resource )
{
System.Diagnostics.Debug.Fail( String.Format( Culture, "No resource for resource id {0}. You probably need to either rebuild or get matching binaries.", index ) );
throw new ArgumentException( String.Format( Culture, "No such resource id {0}.", index ), "index" );
}
return resource;
}
}
public static Resources Loc = new Resources( CultureInfo.CurrentUICulture );
public static Resources Neu = new Resources( CultureInfo.InvariantCulture );
public static CultureMap CultureMap = new CultureMap();
</xsl:text>
<xsl:apply-templates select="root/data" mode="GenerateMcsProperties"/>
<xsl:text>
} // end class Resources
class CultureMap
{
private static ConcurrentDictionary< CultureInfo, Resources > sm_cultureMap = new ConcurrentDictionary< CultureInfo, Resources >();
static CultureMap()
{
sm_cultureMap.TryAdd( CultureInfo.CurrentUICulture, Resources.Loc );
sm_cultureMap.TryAdd( CultureInfo.InvariantCulture, Resources.Neu );
}
public Resources this[ CultureInfo ci ]
{
get
{
Resources r;
if( !sm_cultureMap.TryGetValue( ci, out r ) )
{
r = new Resources( ci );
sm_cultureMap.TryAdd( ci, r );
}
return r;
}
}
}
internal enum ResourceId
{
</xsl:text>
<xsl:apply-templates select="root/data" mode="GenerateEnumValues"/>
<xsl:text>
}
}
</xsl:text>
</xsl:template> <!-- end main template -->
<!--
This template is for generating the resource ID enum values.
-->
<xsl:template match="data" mode="GenerateEnumValues">
<xsl:value-of select="@name"/><xsl:text>,
</xsl:text>
</xsl:template>
<!--
This template is for generating the MulticulturalString properties.
-->
<xsl:template match="data" mode="GenerateMcsProperties">
<xsl:text>
public static MulticulturalString </xsl:text><xsl:value-of select="@name"/><xsl:text>
{
get
{
return new MulticulturalString( (ci) => CultureMap[ ci ][ ResourceId.</xsl:text><xsl:value-of select="@name"/><xsl:text> ] );
}
}
</xsl:text>
</xsl:template>
</xsl:stylesheet>