0
|
1 <?xml version="1.0" encoding="UTF-8" ?>
|
|
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
3
|
|
4 <xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
|
|
5
|
|
6 <!-- parameters passed in by the TransformCodeGenerator -->
|
|
7 <xsl:param name="generator"></xsl:param>
|
|
8 <xsl:param name="version"></xsl:param>
|
|
9 <xsl:param name="filename"></xsl:param>
|
|
10 <xsl:param name="date-created"></xsl:param>
|
|
11 <xsl:param name="created-by"></xsl:param>
|
|
12 <xsl:param name="namespace"></xsl:param>
|
|
13 <xsl:param name="output"></xsl:param>
|
|
14
|
|
15 <!-- support variables -->
|
|
16 <xsl:variable name="lf" xml:space="preserve"> </xsl:variable>
|
|
17 <xsl:variable name="t1" xml:space="preserve">	</xsl:variable>
|
|
18 <xsl:variable name="t2" xml:space="preserve">		</xsl:variable>
|
|
19 <xsl:variable name="t3" xml:space="preserve">			</xsl:variable>
|
|
20 <xsl:variable name="t4" xml:space="preserve">				</xsl:variable>
|
|
21 <xsl:variable name="t5" xml:space="preserve">					</xsl:variable>
|
|
22 <xsl:variable name="t6" xml:space="preserve">						</xsl:variable>
|
|
23 <xsl:variable name="t7" xml:space="preserve">							</xsl:variable>
|
|
24 <xsl:variable name="t8" xml:space="preserve">								</xsl:variable>
|
|
25 <xsl:variable name="s1" xml:space="preserve"> </xsl:variable>
|
|
26 <xsl:variable name="s2" xml:space="preserve">  </xsl:variable>
|
|
27 <xsl:variable name="s3" xml:space="preserve">   </xsl:variable>
|
|
28 <xsl:variable name="s4" xml:space="preserve">    </xsl:variable>
|
|
29 <xsl:variable name="s5" xml:space="preserve">     </xsl:variable>
|
|
30 <xsl:variable name="s6" xml:space="preserve">      </xsl:variable>
|
|
31 <xsl:variable name="s7" xml:space="preserve">       </xsl:variable>
|
|
32 <xsl:variable name="s8" xml:space="preserve">        </xsl:variable>
|
|
33
|
|
34 <!-- customization -->
|
|
35 <xsl:variable name="methodname" select="'To'"/>
|
|
36
|
|
37 <xsl:variable name="padding" select="string-length('DateTimeOffset?')"/>
|
|
38 <xsl:variable name="objectpad" select="$padding - string-length('object')"/>
|
|
39
|
|
40 <!-- the root of all evil -->
|
|
41 <xsl:template match="/">
|
|
42 <!--<xsl:call-template name="header-comment"/>-->
|
|
43 <xsl:apply-templates select="code"/>
|
|
44 </xsl:template>
|
|
45
|
|
46 <xsl:template name="header-comment">
|
|
47 <xsl:value-of select="$lf"/>
|
|
48 <xsl:text>#region Generated File</xsl:text>
|
|
49 <xsl:value-of select="$lf"/>
|
|
50 <xsl:text>/*</xsl:text>
|
|
51 <xsl:value-of select="$lf"/>
|
|
52 <xsl:text> * GENERATED FILE -- DO NOT EDIT</xsl:text>
|
|
53 <xsl:value-of select="$lf"/>
|
|
54 <xsl:text> *</xsl:text>
|
|
55 <xsl:value-of select="$lf"/>
|
|
56 <xsl:text> * Generator: </xsl:text>
|
|
57 <xsl:value-of select="$generator"/>
|
|
58 <xsl:value-of select="$lf"/>
|
|
59 <xsl:text> * Version: </xsl:text>
|
|
60 <xsl:value-of select="$version"/>
|
|
61 <xsl:value-of select="$lf"/>
|
|
62 <xsl:text> *</xsl:text>
|
|
63 <xsl:value-of select="$lf"/>
|
|
64 <xsl:text> *</xsl:text>
|
|
65 <xsl:value-of select="$lf"/>
|
|
66 <xsl:text> * Generated code from "</xsl:text>
|
|
67 <xsl:value-of select="$filename"/>
|
|
68 <xsl:text>"</xsl:text>
|
|
69 <xsl:value-of select="$lf"/>
|
|
70 <xsl:text> *</xsl:text>
|
|
71 <xsl:value-of select="$lf"/>
|
|
72 <xsl:text> * Created: </xsl:text>
|
|
73 <xsl:value-of select="$date-created"/>
|
|
74 <xsl:value-of select="$lf"/>
|
|
75 <xsl:text> * By: </xsl:text>
|
|
76 <xsl:value-of select="$created-by"/>
|
|
77 <xsl:value-of select="$lf"/>
|
|
78 <xsl:text> *</xsl:text>
|
|
79 <xsl:value-of select="$lf"/>
|
|
80 <xsl:text> */</xsl:text>
|
|
81 <xsl:value-of select="$lf"/>
|
|
82 <xsl:text>#endregion</xsl:text>
|
|
83 <xsl:value-of select="$lf"/>
|
|
84 </xsl:template>
|
|
85
|
|
86 <xsl:template match="code">
|
|
87 <xsl:apply-templates select="using|br"/>
|
|
88 <xsl:value-of select="$lf"/>
|
|
89 <xsl:text>namespace </xsl:text>
|
|
90 <xsl:value-of select="$namespace"/>
|
|
91 <xsl:value-of select="$lf"/>
|
|
92 <xsl:text>{</xsl:text>
|
|
93 <xsl:value-of select="$lf"/>
|
|
94 <xsl:call-template name="class"/>
|
|
95 <xsl:text>}</xsl:text>
|
|
96 <xsl:value-of select="$lf"/>
|
|
97 </xsl:template>
|
|
98
|
|
99 <xsl:template match="using">
|
|
100 <xsl:if test="@condition">
|
|
101 <xsl:text>#if </xsl:text>
|
|
102 <xsl:value-of select="@condition"/>
|
|
103 <xsl:value-of select="$lf"/>
|
|
104 </xsl:if>
|
|
105 <xsl:text>using </xsl:text>
|
|
106 <xsl:value-of select="@namespace"/>
|
|
107 <xsl:text>;</xsl:text>
|
|
108 <xsl:if test="@condition">
|
|
109 <xsl:value-of select="$lf"/>
|
|
110 <xsl:text>#endif</xsl:text>
|
|
111 </xsl:if>
|
|
112 <xsl:value-of select="$lf"/>
|
|
113 </xsl:template>
|
|
114
|
|
115 <!-- the class definition -->
|
|
116 <xsl:template name="class">
|
|
117 <xsl:value-of select="$t1"/>
|
|
118 <xsl:text>/// <summary>Converts a base data type to another base data type.</summary></xsl:text>
|
|
119 <xsl:value-of select="$lf"/>
|
|
120 <xsl:value-of select="$t1"/>
|
|
121 <xsl:text>public class Convert</xsl:text>
|
|
122 <xsl:value-of select="$lf"/>
|
|
123 <xsl:value-of select="$t1"/>
|
|
124 <xsl:text>{</xsl:text>
|
|
125 <xsl:value-of select="$lf"/>
|
|
126 <xsl:value-of select="$lf"/>
|
|
127 <xsl:apply-templates select="converter|comment"/>
|
|
128 <xsl:apply-templates select="region"/>
|
|
129
|
|
130 <xsl:value-of select="$lf"/>
|
|
131 <xsl:value-of select="$t2"/>
|
|
132 <xsl:text>private static Exception CreateInvalidCastException(Type originalType, Type conversionType)</xsl:text>
|
|
133 <xsl:value-of select="$lf"/>
|
|
134 <xsl:value-of select="$t2"/>
|
|
135 <xsl:text>{</xsl:text>
|
|
136 <xsl:value-of select="$lf"/>
|
|
137 <xsl:value-of select="$t3"/>
|
|
138 <xsl:text>return new InvalidCastException(string.Format(</xsl:text>
|
|
139 <xsl:value-of select="$lf"/>
|
|
140 <xsl:value-of select="$t4"/>
|
|
141 <xsl:text>Resources.Convert_InvalidCast, originalType.FullName, conversionType.FullName));</xsl:text>
|
|
142 <xsl:value-of select="$lf"/>
|
|
143 <xsl:value-of select="$t2"/>
|
|
144 <xsl:text>}</xsl:text>
|
|
145 <xsl:value-of select="$lf"/>
|
|
146
|
|
147 <xsl:value-of select="$t1"/>
|
|
148 <xsl:text>}</xsl:text>
|
|
149 <xsl:value-of select="$lf"/>
|
|
150 </xsl:template>
|
|
151
|
|
152 <!-- region -->
|
|
153 <xsl:template match="region">
|
|
154 <xsl:value-of select="$t2"/>
|
|
155 <xsl:text>#region </xsl:text>
|
|
156 <xsl:value-of select="@name"/>
|
|
157 <xsl:value-of select="$lf"/>
|
|
158 <xsl:value-of select="$lf"/>
|
|
159 <xsl:apply-templates select="converter|comment"/>
|
|
160 <xsl:apply-templates select="region"/>
|
|
161 <xsl:value-of select="$t2"/>
|
|
162 <xsl:text>#endregion</xsl:text>
|
|
163 <xsl:value-of select="$lf"/>
|
|
164 <xsl:value-of select="$lf"/>
|
|
165 </xsl:template>
|
|
166
|
|
167 <!-- declarations -->
|
|
168 <xsl:template match="converter">
|
|
169 <xsl:variable name="tonullable" select="@nullable='true'"/>
|
|
170 <xsl:variable name="fulltype">
|
|
171 <xsl:value-of select="@type"/>
|
|
172 <xsl:if test="$tonullable">
|
|
173 <xsl:text>?</xsl:text>
|
|
174 </xsl:if>
|
|
175 </xsl:variable>
|
|
176 <xsl:variable name="typepad" select="$padding - string-length($fulltype)"/>
|
|
177 <xsl:variable name="notclscompliant" select="/code/type[@name=current()/@type]/@clscompliant='false'"/>
|
|
178 <xsl:variable name="condition" select="/code/type[@name=current()/@type]/@condition"/>
|
|
179
|
|
180 <xsl:if test="$condition">
|
|
181 <xsl:value-of select="$t2"/>
|
|
182 <xsl:text>#if </xsl:text>
|
|
183 <xsl:value-of select="$condition"/>
|
|
184 <xsl:value-of select="$lf"/>
|
|
185 </xsl:if>
|
|
186
|
|
187 <xsl:value-of select="$t2"/>
|
|
188 <xsl:text>#region </xsl:text>
|
|
189 <xsl:value-of select="$fulltype"/>
|
|
190 <xsl:value-of select="$lf"/>
|
|
191 <xsl:value-of select="$lf"/>
|
|
192
|
|
193 <xsl:apply-templates select="group|from|comment|br" mode ="body">
|
|
194 <xsl:with-param name="totype" select="@type"/>
|
|
195 <xsl:with-param name="toname">
|
|
196 <xsl:choose>
|
|
197 <xsl:when test="@name">
|
|
198 <xsl:value-of select="@name"/>
|
|
199 </xsl:when>
|
|
200 <xsl:otherwise>
|
|
201 <xsl:value-of select="@type"/>
|
|
202 </xsl:otherwise>
|
|
203 </xsl:choose>
|
|
204 </xsl:with-param>
|
|
205 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
206 <xsl:with-param name="code" select="default/text()"/>
|
|
207 </xsl:apply-templates>
|
|
208
|
|
209 <xsl:value-of select="$t2"/>
|
|
210 <xsl:text>/// <summary>Converts the value of a specified object to an equivalent <c></xsl:text>
|
|
211 <xsl:value-of select="$fulltype"/>
|
|
212 <xsl:text></c> value.</summary></xsl:text>
|
|
213 <xsl:value-of select="$lf"/>
|
|
214
|
|
215 <xsl:if test="$notclscompliant">
|
|
216 <xsl:value-of select="$t2"/>
|
|
217 <xsl:text>[CLSCompliant(false)]</xsl:text>
|
|
218 <xsl:value-of select="$lf"/>
|
|
219 </xsl:if>
|
|
220
|
|
221 <xsl:value-of select="$t2"/>
|
|
222 <xsl:text>public static </xsl:text>
|
|
223 <xsl:value-of select="$fulltype"/>
|
|
224 <xsl:value-of select="$s1"/>
|
|
225 <xsl:value-of select="$methodname"/>
|
|
226 <xsl:if test="$tonullable">
|
|
227 <xsl:text>Nullable</xsl:text>
|
|
228 </xsl:if>
|
|
229 <xsl:choose>
|
|
230 <xsl:when test="@name">
|
|
231 <xsl:value-of select="@name"/>
|
|
232 </xsl:when>
|
|
233 <xsl:otherwise>
|
|
234 <xsl:value-of select="@type"/>
|
|
235 </xsl:otherwise>
|
|
236 </xsl:choose>
|
|
237 <xsl:text>(object p)</xsl:text>
|
|
238 <xsl:call-template name ="writeSpaces">
|
|
239 <xsl:with-param name="count" select="$objectpad"/>
|
|
240 </xsl:call-template>
|
|
241 <xsl:call-template name="writecode">
|
|
242 <xsl:with-param name="code">
|
|
243 <xsl:apply-templates select="default">
|
|
244 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
245 </xsl:apply-templates>
|
|
246 </xsl:with-param>
|
|
247 </xsl:call-template>
|
|
248
|
|
249 <xsl:value-of select="$lf"/>
|
|
250
|
|
251 <xsl:value-of select="$lf"/>
|
|
252 <xsl:value-of select="$t2"/>
|
|
253 <xsl:text>#endregion</xsl:text>
|
|
254 <xsl:value-of select="$lf"/>
|
|
255
|
|
256 <xsl:if test="$condition">
|
|
257 <xsl:value-of select="$lf"/>
|
|
258 <xsl:value-of select="$t2"/>
|
|
259 <xsl:text>#endif</xsl:text>
|
|
260 </xsl:if>
|
|
261
|
|
262 <xsl:value-of select="$lf"/>
|
|
263 </xsl:template>
|
|
264
|
|
265 <!-- body -->
|
|
266 <xsl:template match="group" mode="body">
|
|
267 <xsl:param name="totype"/>
|
|
268 <xsl:param name="toname"/>
|
|
269 <xsl:param name="tonullable"/>
|
|
270 <xsl:param name="code"/>
|
|
271
|
|
272 <!--
|
|
273 <xsl:if test="@nullable='true'">
|
|
274 <xsl:text>#if FW2</xsl:text>
|
|
275 <xsl:value-of select="$lf"/>
|
|
276 </xsl:if>
|
|
277 -->
|
|
278
|
|
279 <xsl:if test="@name">
|
|
280 <xsl:value-of select="$t2"/>
|
|
281 <xsl:text>// </xsl:text>
|
|
282 <xsl:value-of select="@name"/>
|
|
283 <xsl:value-of select="$lf"/>
|
|
284 <xsl:value-of select="$t2"/>
|
|
285 <xsl:text>// </xsl:text>
|
|
286 <xsl:value-of select="$lf"/>
|
|
287 </xsl:if>
|
|
288 <xsl:apply-templates select="group|from|comment|br|include" mode="body">
|
|
289 <xsl:with-param name="fromnullable" select="@nullable='true'"/>
|
|
290 <xsl:with-param name="totype" select="$totype"/>
|
|
291 <xsl:with-param name="toname" select="$toname"/>
|
|
292 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
293 <xsl:with-param name="group" select="."/>
|
|
294 <xsl:with-param name="code">
|
|
295 <xsl:choose>
|
|
296 <xsl:when test ="default/text()">
|
|
297 <xsl:value-of select="default/text()"/>
|
|
298 </xsl:when>
|
|
299 <xsl:otherwise>
|
|
300 <xsl:value-of select="$code"/>
|
|
301 </xsl:otherwise>
|
|
302 </xsl:choose>
|
|
303 </xsl:with-param>
|
|
304 </xsl:apply-templates>
|
|
305 <xsl:value-of select="$lf"/>
|
|
306
|
|
307 <!--
|
|
308 <xsl:if test="@nullable='true'">
|
|
309 <xsl:text>#endif</xsl:text>
|
|
310 <xsl:value-of select="$lf"/>
|
|
311 </xsl:if>
|
|
312 -->
|
|
313 </xsl:template>
|
|
314
|
|
315 <xsl:template match="from" mode="body">
|
|
316 <xsl:param name="fromnullable"/>
|
|
317 <xsl:param name="totype"/>
|
|
318 <xsl:param name="toname"/>
|
|
319 <xsl:param name="tonullable"/>
|
|
320 <xsl:param name="code"/>
|
|
321
|
|
322 <xsl:call-template name="frombody">
|
|
323 <xsl:with-param name="fromtype" select="@type"/>
|
|
324 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
325 <xsl:with-param name="totype" select="$totype"/>
|
|
326 <xsl:with-param name="toname" select="$toname"/>
|
|
327 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
328 <xsl:with-param name="code" select="$code"/>
|
|
329 </xsl:call-template>
|
|
330 </xsl:template>
|
|
331
|
|
332 <xsl:template match="include" mode="body">
|
|
333 <xsl:param name="fromnullable"/>
|
|
334 <xsl:param name="totype"/>
|
|
335 <xsl:param name="toname"/>
|
|
336 <xsl:param name="tonullable"/>
|
|
337 <xsl:param name="group"/>
|
|
338 <xsl:param name="code"/>
|
|
339 <xsl:call-template name="includebody">
|
|
340 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
341 <xsl:with-param name="totype" select="$totype"/>
|
|
342 <xsl:with-param name="toname" select="$toname"/>
|
|
343 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
344 <xsl:with-param name="group" select="$group"/>
|
|
345 <xsl:with-param name="code" select="$code"/>
|
|
346 <xsl:with-param name="template" select="@template"/>
|
|
347 </xsl:call-template>
|
|
348 </xsl:template>
|
|
349
|
|
350 <xsl:template match="include" mode="runtime">
|
|
351 <xsl:param name="totype"/>
|
|
352 <xsl:param name="toname"/>
|
|
353 <xsl:param name="tonullable"/>
|
|
354 <xsl:param name="fromnullable"/>
|
|
355 <xsl:param name="default"/>
|
|
356 <xsl:param name="group"/>
|
|
357 <xsl:call-template name="includeruntime">
|
|
358 <xsl:with-param name="totype" select="$totype"/>
|
|
359 <xsl:with-param name="toname" select="$toname"/>
|
|
360 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
361 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
362 <xsl:with-param name="group" select="$group"/>
|
|
363 <xsl:with-param name="default" select="$default"/>
|
|
364 <xsl:with-param name="template" select="@template"/>
|
|
365 </xsl:call-template>
|
|
366 </xsl:template>
|
|
367
|
|
368 <xsl:template name="includebody">
|
|
369 <xsl:param name="fromnullable"/>
|
|
370 <xsl:param name="totype"/>
|
|
371 <xsl:param name="toname"/>
|
|
372 <xsl:param name="tonullable"/>
|
|
373 <xsl:param name="group"/>
|
|
374 <xsl:param name="code"/>
|
|
375 <xsl:param name="template"/>
|
|
376 <xsl:for-each select="/code/template[@name=$template]/*">
|
|
377 <xsl:choose>
|
|
378 <xsl:when test="name()='type'">
|
|
379 <xsl:variable name ="fromtype" select="@name"/>
|
|
380 <xsl:if test="not($fromtype=$totype and $fromnullable=$tonullable) and not($group/from[@type=$fromtype])">
|
|
381 <xsl:call-template name="frombody">
|
|
382 <xsl:with-param name="fromtype" select="$fromtype"/>
|
|
383 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
384 <xsl:with-param name="totype" select="$totype"/>
|
|
385 <xsl:with-param name="toname" select="$toname"/>
|
|
386 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
387 <xsl:with-param name="code" select="$code"/>
|
|
388 </xsl:call-template>
|
|
389 </xsl:if>
|
|
390 </xsl:when>
|
|
391 <xsl:when test="name()='include'">
|
|
392 <xsl:call-template name="includebody">
|
|
393 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
394 <xsl:with-param name="totype" select="$totype"/>
|
|
395 <xsl:with-param name="toname" select="$toname"/>
|
|
396 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
397 <xsl:with-param name="group" select="$group"/>
|
|
398 <xsl:with-param name="code" select="$code"/>
|
|
399 <xsl:with-param name="template" select="@template"/>
|
|
400 </xsl:call-template>
|
|
401 </xsl:when>
|
|
402 <xsl:when test="name()='br'">
|
|
403 <xsl:value-of select="$lf"/>
|
|
404 </xsl:when>
|
|
405 </xsl:choose>
|
|
406 </xsl:for-each>
|
|
407 </xsl:template>
|
|
408
|
|
409 <xsl:template name="includeruntime">
|
|
410 <xsl:param name="totype"/>
|
|
411 <xsl:param name="toname"/>
|
|
412 <xsl:param name="tonullable"/>
|
|
413 <xsl:param name="fromnullable"/>
|
|
414 <xsl:param name="group"/>
|
|
415 <xsl:param name="default"/>
|
|
416 <xsl:param name="template"/>
|
|
417 <xsl:for-each select="/code/template[@name=$template]/*">
|
|
418 <xsl:choose>
|
|
419 <xsl:when test="name()='type'">
|
|
420 <xsl:variable name ="fromtype" select="@name"/>
|
|
421 <xsl:if test="not($fromtype=$totype and $fromnullable=$tonullable) and not($group/from[@type=$fromtype])">
|
|
422 <xsl:call-template name="fromruntime">
|
|
423 <xsl:with-param name="fromtype" select="$fromtype"/>
|
|
424 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
425 <xsl:with-param name="totype" select="$totype"/>
|
|
426 <xsl:with-param name="toname" select="$toname"/>
|
|
427 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
428 <xsl:with-param name="default" select="$default"/>
|
|
429 </xsl:call-template>
|
|
430 </xsl:if>
|
|
431 </xsl:when>
|
|
432 <xsl:when test="name()='include'">
|
|
433 <xsl:call-template name="includeruntime">
|
|
434 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
435 <xsl:with-param name="totype" select="$totype"/>
|
|
436 <xsl:with-param name="toname" select="$toname"/>
|
|
437 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
438 <xsl:with-param name="group" select="$group"/>
|
|
439 <xsl:with-param name="default" select="$default"/>
|
|
440 <xsl:with-param name="template" select="@template"/>
|
|
441 </xsl:call-template>
|
|
442 </xsl:when>
|
|
443 <xsl:when test="name()='br'">
|
|
444 <xsl:value-of select="$lf"/>
|
|
445 </xsl:when>
|
|
446 </xsl:choose>
|
|
447 </xsl:for-each>
|
|
448 </xsl:template>
|
|
449
|
|
450 <xsl:template name="frombody">
|
|
451 <xsl:param name="fromtype"/>
|
|
452 <xsl:param name="fromnullable"/>
|
|
453 <xsl:param name="totype"/>
|
|
454 <xsl:param name="toname"/>
|
|
455 <xsl:param name="tonullable"/>
|
|
456 <xsl:param name="code"/>
|
|
457
|
|
458 <xsl:variable name="notclscompliant" select="/code/type[@name=$totype]/@clscompliant='false' or /code/type[@name=$fromtype]/@clscompliant='false'"/>
|
|
459 <xsl:variable name="fromcondition" select="/code/type[@name=$fromtype]/@condition"/>
|
|
460 <xsl:variable name="tocondition" select="/code/type[@name=$totype]/@condition"/>
|
|
461
|
|
462 <xsl:variable name="fromfulltype">
|
|
463 <xsl:value-of select="$fromtype"/>
|
|
464 <xsl:if test="$fromnullable">
|
|
465 <xsl:text>?</xsl:text>
|
|
466 </xsl:if>
|
|
467 </xsl:variable>
|
|
468 <xsl:variable name="fromtypepad" select="$padding - string-length($fromfulltype)"/>
|
|
469 <xsl:variable name="tofulltype">
|
|
470 <xsl:value-of select="$totype"/>
|
|
471 <xsl:if test="$tonullable">
|
|
472 <xsl:text>?</xsl:text>
|
|
473 </xsl:if>
|
|
474 </xsl:variable>
|
|
475
|
|
476 <xsl:if test="$fromcondition and not ($fromcondition = $tocondition)">
|
|
477 <xsl:value-of select="$t2"/>
|
|
478 <xsl:text>#if </xsl:text>
|
|
479 <xsl:value-of select="$fromcondition"/>
|
|
480 <xsl:value-of select="$lf"/>
|
|
481 </xsl:if>
|
|
482
|
|
483 <xsl:value-of select="$t2"/>
|
|
484 <xsl:text>/// <summary>Converts the value from <c></xsl:text>
|
|
485 <xsl:value-of select="$fromfulltype"/>
|
|
486 <xsl:text></c> to an equivalent <c></xsl:text>
|
|
487 <xsl:value-of select="$tofulltype"/>
|
|
488 <xsl:text></c> value.</summary></xsl:text>
|
|
489 <xsl:value-of select="$lf"/>
|
|
490
|
|
491 <xsl:if test="$notclscompliant">
|
|
492 <xsl:value-of select="$t2"/>
|
|
493 <xsl:text>[CLSCompliant(false)]</xsl:text>
|
|
494 <xsl:value-of select="$lf"/>
|
|
495 </xsl:if>
|
|
496
|
|
497 <xsl:value-of select="$t2"/>
|
|
498 <xsl:text>public static </xsl:text>
|
|
499 <xsl:value-of select="$tofulltype"/>
|
|
500 <xsl:value-of select="$s1"/>
|
|
501
|
|
502 <xsl:value-of select="$methodname"/>
|
|
503 <xsl:if test="$tonullable">
|
|
504 <xsl:text>Nullable</xsl:text>
|
|
505 </xsl:if>
|
|
506 <xsl:value-of select="$toname"/>
|
|
507 <xsl:text>(</xsl:text>
|
|
508 <xsl:value-of select="$fromfulltype"/>
|
|
509 <xsl:text> p)</xsl:text>
|
|
510 <xsl:call-template name ="writeSpaces">
|
|
511 <xsl:with-param name="count" select="$fromtypepad"/>
|
|
512 </xsl:call-template>
|
|
513 <xsl:call-template name="writecode">
|
|
514 <xsl:with-param name="code">
|
|
515 <xsl:choose>
|
|
516 <xsl:when test ="text()">
|
|
517 <xsl:value-of select="text()"/>
|
|
518 </xsl:when>
|
|
519 <xsl:otherwise>
|
|
520 <xsl:value-of select="$code"/>
|
|
521 </xsl:otherwise>
|
|
522 </xsl:choose>
|
|
523 </xsl:with-param>
|
|
524 </xsl:call-template>
|
|
525 <xsl:if test="$fromcondition and not ($fromcondition = $tocondition)">
|
|
526 <xsl:value-of select="$lf"/>
|
|
527 <xsl:value-of select="$t2"/>
|
|
528 <xsl:text>#endif</xsl:text>
|
|
529 </xsl:if>
|
|
530 <xsl:value-of select="$lf"/>
|
|
531 </xsl:template>
|
|
532
|
|
533 <xsl:template match="from" mode="runtime">
|
|
534 <xsl:param name="totype"/>
|
|
535 <xsl:param name="toname"/>
|
|
536 <xsl:param name="tonullable"/>
|
|
537 <xsl:param name="fromnullable"/>
|
|
538 <xsl:param name="default"/>
|
|
539 <xsl:call-template name="fromruntime">
|
|
540 <xsl:with-param name="fromtype" select="@type"/>
|
|
541 <xsl:with-param name="fromnullable" select="$fromnullable"/>
|
|
542 <xsl:with-param name="totype" select="$totype"/>
|
|
543 <xsl:with-param name="toname" select="$toname"/>
|
|
544 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
545 <xsl:with-param name="template" select="@template"/>
|
|
546 <xsl:with-param name="default" select="@default"/>
|
|
547 </xsl:call-template>
|
|
548 </xsl:template>
|
|
549
|
|
550
|
|
551 <!-- runtime -->
|
|
552 <xsl:template name="fromruntime">
|
|
553 <xsl:param name="fromtype"/>
|
|
554 <xsl:param name="totype"/>
|
|
555 <xsl:param name="toname"/>
|
|
556 <xsl:param name="tonullable"/>
|
|
557 <xsl:param name="fromnullable"/>
|
|
558 <xsl:param name="default"/>
|
|
559 <xsl:variable name="fromfullname">
|
|
560 <xsl:value-of select="$fromtype"/>
|
|
561 <xsl:if test="$fromnullable">
|
|
562 <xsl:text>?</xsl:text>
|
|
563 </xsl:if>
|
|
564 </xsl:variable>
|
|
565
|
|
566 <xsl:if test="text() or $default">
|
|
567 <xsl:variable name="typepad" select="$padding - string-length($fromfullname)"/>
|
|
568 <xsl:variable name="fromcondition" select="/code/type[@name=current()/@type]/@condition"/>
|
|
569 <xsl:variable name="tocondition" select="/code/type[@name=$totype]/@condition"/>
|
|
570
|
|
571 <xsl:if test="$fromcondition and not ($fromcondition = $tocondition)">
|
|
572 <xsl:value-of select="$t3"/>
|
|
573 <xsl:text>#if </xsl:text>
|
|
574 <xsl:value-of select="$fromcondition"/>
|
|
575 <xsl:value-of select="$lf"/>
|
|
576 </xsl:if>
|
|
577 <xsl:value-of select="$t3"/>
|
|
578 <xsl:text>if (p is </xsl:text>
|
|
579 <xsl:value-of select="$fromfullname"/>
|
|
580 <xsl:text>) </xsl:text>
|
|
581 <xsl:call-template name ="writeSpaces">
|
|
582 <xsl:with-param name="count" select="$typepad"/>
|
|
583 </xsl:call-template>
|
|
584 <xsl:text>return </xsl:text>
|
|
585 <xsl:value-of select="$methodname"/>
|
|
586 <xsl:if test="$tonullable">
|
|
587 <xsl:text>Nullable</xsl:text>
|
|
588 </xsl:if>
|
|
589 <xsl:value-of select="$toname"/>
|
|
590 <xsl:text>((</xsl:text>
|
|
591 <xsl:value-of select="$fromfullname"/>
|
|
592 <xsl:text>)p);</xsl:text>
|
|
593 <xsl:if test="$fromcondition and not ($fromcondition = $tocondition)">
|
|
594 <xsl:value-of select="$lf"/>
|
|
595 <xsl:value-of select="$t3"/>
|
|
596 <xsl:text>#endif</xsl:text>
|
|
597 </xsl:if>
|
|
598 <xsl:value-of select="$lf"/>
|
|
599 </xsl:if>
|
|
600 </xsl:template>
|
|
601
|
|
602 <xsl:template match="group" mode="runtime">
|
|
603 <xsl:param name="totype"/>
|
|
604 <xsl:param name="toname"/>
|
|
605 <xsl:param name="tonullable"/>
|
|
606 <xsl:param name="fromnullable"/>
|
|
607 <xsl:param name="default"/>
|
|
608
|
|
609 <xsl:variable name="fromnullablelocal" select="@nullable='true' or $fromnullable"/>
|
|
610 <xsl:variable name="defaultcode">
|
|
611 <xsl:choose>
|
|
612 <xsl:when test="default/text()">
|
|
613 <xsl:value-of select="default/text()"/>
|
|
614 </xsl:when>
|
|
615 <xsl:otherwise>
|
|
616 <xsl:value-of select="$default"/>
|
|
617 </xsl:otherwise>
|
|
618 </xsl:choose>
|
|
619 </xsl:variable>
|
|
620
|
|
621 <xsl:if test="not($fromnullablelocal)">
|
|
622
|
|
623 <xsl:if test="@name">
|
|
624 <xsl:value-of select="$lf"/>
|
|
625 <xsl:value-of select="$t3"/>
|
|
626 <xsl:text>// </xsl:text>
|
|
627 <xsl:value-of select="@name"/>
|
|
628 <xsl:value-of select="$lf"/>
|
|
629 <xsl:value-of select="$t3"/>
|
|
630 <xsl:text>//</xsl:text>
|
|
631 </xsl:if>
|
|
632 <xsl:value-of select="$lf"/>
|
|
633 <xsl:apply-templates select="group|from|br|include" mode ="runtime">
|
|
634 <xsl:with-param name="totype" select="$totype"/>
|
|
635 <xsl:with-param name="toname" select="$toname"/>
|
|
636 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
637 <xsl:with-param name="fromnullable" select="$fromnullablelocal"/>
|
|
638 <xsl:with-param name="default" select="$defaultcode"/>
|
|
639 <xsl:with-param name="group" select="."/>
|
|
640 </xsl:apply-templates>
|
|
641 </xsl:if>
|
|
642
|
|
643 </xsl:template>
|
|
644
|
|
645 <!-- default -->
|
|
646 <xsl:template match="default">
|
|
647 <xsl:param name="tonullable"/>
|
|
648 <xsl:if test="@nullvalue">
|
|
649 <xsl:value-of select="$lf"/>
|
|
650 <xsl:value-of select="$t3"/>
|
|
651 <xsl:text>if (p == null || p is DBNull) return </xsl:text>
|
|
652 <xsl:value-of select="@nullvalue"/>
|
|
653 <xsl:text>;</xsl:text>
|
|
654 <xsl:value-of select="$lf"/>
|
|
655 </xsl:if>
|
|
656 <xsl:value-of select="$lf"/>
|
|
657 <xsl:value-of select="$t3"/>
|
|
658 <xsl:text>if (p is </xsl:text>
|
|
659 <xsl:value-of select="../@type"/>
|
|
660 <xsl:text>) return (</xsl:text>
|
|
661 <xsl:value-of select="../@type"/>
|
|
662 <xsl:text>)p;</xsl:text>
|
|
663 <xsl:value-of select="$lf"/>
|
|
664 <xsl:if test="not(@noruntime) and @nullvalue">
|
|
665 <xsl:apply-templates select="../from|../group|../br|../include" mode="runtime">
|
|
666 <xsl:with-param name="totype" select="../@type"/>
|
|
667 <xsl:with-param name="toname">
|
|
668 <xsl:choose>
|
|
669 <xsl:when test="../@name">
|
|
670 <xsl:value-of select="../@name"/>
|
|
671 </xsl:when>
|
|
672 <xsl:otherwise>
|
|
673 <xsl:value-of select="../@type"/>
|
|
674 </xsl:otherwise>
|
|
675 </xsl:choose>
|
|
676 </xsl:with-param>
|
|
677 <xsl:with-param name="tonullable" select="$tonullable"/>
|
|
678 </xsl:apply-templates>
|
|
679 </xsl:if>
|
|
680 <xsl:value-of select="text()"/>
|
|
681 <xsl:if test="not(@nothrow) and @nullvalue">
|
|
682 <xsl:value-of select="$lf"/>
|
|
683 <xsl:value-of select="$t3"/>
|
|
684 <xsl:text>throw CreateInvalidCastException(p.GetType(), typeof(</xsl:text>
|
|
685 <xsl:value-of select="../@type"/>
|
|
686 <xsl:if test="$tonullable">
|
|
687 <xsl:text>?</xsl:text>
|
|
688 </xsl:if>
|
|
689 <xsl:text>));</xsl:text>
|
|
690 </xsl:if>
|
|
691 </xsl:template>
|
|
692
|
|
693 <!-- comments -->
|
|
694 <xsl:template name ="comment">
|
|
695 <xsl:if test="text()">
|
|
696 <xsl:value-of select="$lf"/>
|
|
697 <xsl:value-of select="$t3"/>
|
|
698 <xsl:text>// </xsl:text>
|
|
699 <xsl:value-of select="text()"/>
|
|
700 <xsl:value-of select="$lf"/>
|
|
701 <xsl:value-of select="$t3"/>
|
|
702 <xsl:text>//</xsl:text>
|
|
703 </xsl:if>
|
|
704 <xsl:value-of select="$lf"/>
|
|
705 </xsl:template>
|
|
706
|
|
707 <xsl:template match="comment">
|
|
708 <xsl:call-template name="comment"/>
|
|
709 </xsl:template>
|
|
710
|
|
711 <xsl:template match="comment" mode ="partial">
|
|
712 <xsl:if test="not(@tonullable) or @tonullable!='true'">
|
|
713 <xsl:call-template name="comment"/>
|
|
714 </xsl:if>
|
|
715 </xsl:template>
|
|
716
|
|
717 <xsl:template match="comment" mode ="nuldef">
|
|
718 <xsl:if test="@tonullable='true'">
|
|
719 <xsl:call-template name="comment"/>
|
|
720 </xsl:if>
|
|
721 </xsl:template>
|
|
722
|
|
723 <xsl:template match="comment" mode ="body">
|
|
724 <xsl:if test="not(@tonullable) or @tonullable!='true'">
|
|
725 <xsl:call-template name="comment"/>
|
|
726 </xsl:if>
|
|
727 </xsl:template>
|
|
728
|
|
729 <xsl:template match="comment" mode ="nulbody">
|
|
730 <xsl:if test="@tonullable='true'">
|
|
731 <xsl:call-template name="comment"/>
|
|
732 </xsl:if>
|
|
733 </xsl:template>
|
|
734
|
|
735 <xsl:template match="br">
|
|
736 <xsl:value-of select="$lf"/>
|
|
737 </xsl:template>
|
|
738
|
|
739 <xsl:template match="br" mode="def">
|
|
740 <xsl:value-of select="$lf"/>
|
|
741 </xsl:template>
|
|
742
|
|
743 <xsl:template match="br" mode="body">
|
|
744 <xsl:value-of select="$lf"/>
|
|
745 </xsl:template>
|
|
746
|
|
747 <xsl:template match="br" mode="runtime">
|
|
748 <xsl:value-of select="$lf"/>
|
|
749 </xsl:template>
|
|
750
|
|
751 <!-- support function -->
|
|
752 <xsl:template name="writecode">
|
|
753 <xsl:param name="code"/>
|
|
754 <xsl:choose>
|
|
755 <xsl:when test="contains($code, ' ')">
|
|
756 <!-- multi-line -->
|
|
757 <xsl:value-of select="$lf"/>
|
|
758 <xsl:value-of select="$t2"/>
|
|
759 <xsl:text>{</xsl:text>
|
|
760 <xsl:value-of select="$code"/>
|
|
761 <xsl:value-of select="$lf"/>
|
|
762 <xsl:value-of select="$t2"/>
|
|
763 <xsl:text>}</xsl:text>
|
|
764 </xsl:when>
|
|
765 <xsl:otherwise>
|
|
766 <!-- single-line -->
|
|
767 <xsl:text> { </xsl:text>
|
|
768 <xsl:value-of select="$code"/>
|
|
769 <xsl:text> }</xsl:text>
|
|
770 </xsl:otherwise>
|
|
771 </xsl:choose>
|
|
772 </xsl:template>
|
|
773
|
|
774 <!-- support function -->
|
|
775 <xsl:template name="writeSpaces">
|
|
776 <xsl:param name="count"/>
|
|
777 <xsl:choose>
|
|
778 <xsl:when test="$count<1"/>
|
|
779 <xsl:when test="$count=1">
|
|
780 <xsl:value-of select="$s1"/>
|
|
781 </xsl:when>
|
|
782 <xsl:when test="$count=2">
|
|
783 <xsl:value-of select="$s2"/>
|
|
784 </xsl:when>
|
|
785 <xsl:when test="$count=3">
|
|
786 <xsl:value-of select="$s3"/>
|
|
787 </xsl:when>
|
|
788 <xsl:when test="$count=4">
|
|
789 <xsl:value-of select="$s4"/>
|
|
790 </xsl:when>
|
|
791 <xsl:when test="$count=5">
|
|
792 <xsl:value-of select="$s5"/>
|
|
793 </xsl:when>
|
|
794 <xsl:when test="$count=6">
|
|
795 <xsl:value-of select="$s6"/>
|
|
796 </xsl:when>
|
|
797 <xsl:when test="$count=7">
|
|
798 <xsl:value-of select="$s7"/>
|
|
799 </xsl:when>
|
|
800 <xsl:when test="$count=8">
|
|
801 <xsl:value-of select="$s8"/>
|
|
802 </xsl:when>
|
|
803 <xsl:otherwise>
|
|
804 <xsl:value-of select="$s8"/>
|
|
805 <xsl:call-template name ="writeSpaces">
|
|
806 <xsl:with-param name="count" select="$count - 8"/>
|
|
807 </xsl:call-template>
|
|
808 </xsl:otherwise>
|
|
809 </xsl:choose>
|
|
810 </xsl:template>
|
|
811
|
|
812 </xsl:stylesheet>
|