Mercurial > pub > ModelGenerator
comparison xslt/generator.csharp.xsl @ 5:6f67d3a6b950
sync
| author | cin |
|---|---|
| date | Fri, 02 Mar 2018 18:34:19 +0300 |
| parents | d240adc2ac70 |
| children | 1f4009d4afb6 |
comparison
equal
deleted
inserted
replaced
| 4:d240adc2ac70 | 5:6f67d3a6b950 |
|---|---|
| 24 <xsl:template match="m:entity" mode="document"> | 24 <xsl:template match="m:entity" mode="document"> |
| 25 <xsl:apply-templates select="." mode="entity"/> | 25 <xsl:apply-templates select="." mode="entity"/> |
| 26 </xsl:template> | 26 </xsl:template> |
| 27 | 27 |
| 28 <xsl:template match="m:entity" mode="entity"> | 28 <xsl:template match="m:entity" mode="entity"> |
| 29 <!-- select all members --> | |
| 29 <xsl:variable name="members"> | 30 <xsl:variable name="members"> |
| 30 <xsl:apply-templates mode="fiter-members"/> | 31 <xsl:apply-templates mode="fiter-members"/> |
| 31 </xsl:variable> | 32 </xsl:variable> |
| 33 | |
| 32 <cs:class modifiers="partial"> | 34 <cs:class modifiers="partial"> |
| 35 <!-- generate class name --> | |
| 33 <xsl:attribute name="name"> | 36 <xsl:attribute name="name"> |
| 34 <xsl:apply-templates select="." mode="class-name"/> | 37 <xsl:apply-templates select="." mode="class-name"/> |
| 35 </xsl:attribute> | 38 </xsl:attribute> |
| 39 <xsl:attribute name="modifiers"> | |
| 40 <xsl:apply-templates select="." mode="class-modifiers"/> | |
| 41 </xsl:attribute> | |
| 42 | |
| 36 <xsl:apply-templates mode="class-attributes" /> | 43 <xsl:apply-templates mode="class-attributes" /> |
| 37 <xsl:apply-templates select="exsl:node-set($members)" mode="members" /> | 44 <xsl:apply-templates select="exsl:node-set($members)" mode="members" /> |
| 38 </cs:class> | 45 </cs:class> |
| 39 </xsl:template> | 46 </xsl:template> |
| 40 | 47 |
| 43 <xsl:value-of select="@name"/> | 50 <xsl:value-of select="@name"/> |
| 44 </xsl:template> | 51 </xsl:template> |
| 45 | 52 |
| 46 <xsl:template match="*[@clr:name]" mode="class-name"> | 53 <xsl:template match="*[@clr:name]" mode="class-name"> |
| 47 <xsl:value-of select="@clr:name"/> | 54 <xsl:value-of select="@clr:name"/> |
| 55 </xsl:template> | |
| 56 | |
| 57 <!-- class-modifiers --> | |
| 58 <xsl:template match="*" mode="class-modifiers"> | |
| 59 <xsl:text>partial</xsl:text> | |
| 48 </xsl:template> | 60 </xsl:template> |
| 49 | 61 |
| 50 <!-- class-attributes --> | 62 <!-- class-attributes --> |
| 51 <xsl:template match="*|text()" mode="class-attributes" /> | 63 <xsl:template match="*|text()" mode="class-attributes" /> |
| 52 | 64 |
| 62 <xsl:template match="*|text()" mode="members" /> | 74 <xsl:template match="*|text()" mode="members" /> |
| 63 | 75 |
| 64 <xsl:template match="m:primaryKey | m:property | m:thisKey | clr:association" mode="members"> | 76 <xsl:template match="m:primaryKey | m:property | m:thisKey | clr:association" mode="members"> |
| 65 <t:trace msg="{name()} {@name}"/> | 77 <t:trace msg="{name()} {@name}"/> |
| 66 <xsl:apply-templates select="." mode="property"/> | 78 <xsl:apply-templates select="." mode="property"/> |
| 67 </xsl:template> | |
| 68 | |
| 69 <xsl:template match="m:thisKey" mode="members"> | |
| 70 <xsl:variable name="properties"> | |
| 71 | |
| 72 </xsl:variable> | |
| 73 </xsl:template> | 79 </xsl:template> |
| 74 | 80 |
| 75 <!-- hasA and hasMany doesn't generate members itself, they delegate this work to inner members --> | 81 <!-- hasA and hasMany doesn't generate members itself, they delegate this work to inner members --> |
| 76 <xsl:template match="m:hasA | m:hasMany" mode="members"> | 82 <xsl:template match="m:hasA | m:hasMany" mode="members"> |
| 77 <t:trace msg="{name()} {@name}" /> | 83 <t:trace msg="{name()} {@name}" /> |
| 139 <xsl:apply-templates select="." mode="property-extension" /> | 145 <xsl:apply-templates select="." mode="property-extension" /> |
| 140 <xsl:apply-templates select="." mode="property-accessors"/> | 146 <xsl:apply-templates select="." mode="property-accessors"/> |
| 141 </cs:property> | 147 </cs:property> |
| 142 </xsl:template> | 148 </xsl:template> |
| 143 | 149 |
| 150 | |
| 144 <!-- property-name --> | 151 <!-- property-name --> |
| 145 <xsl:template match="m:hasA/clr:association[not(@name|@clr:name)]" mode="property-name"> | 152 <xsl:template match="m:hasA/clr:association[not(@name|@clr:name)]" mode="property-name"> |
| 146 <!-- if the association doesn't define a name, use it from the parent node --> | 153 <!-- if the association doesn't define a name, use it from the parent node --> |
| 147 <xsl:apply-templates select=".." mode="property-name"/> | 154 <xsl:apply-templates select=".." mode="property-name"/> |
| 148 </xsl:template> | 155 </xsl:template> |
| 159 <xsl:template match="*" mode="property-modifiers"> | 166 <xsl:template match="*" mode="property-modifiers"> |
| 160 <xsl:text>public</xsl:text> | 167 <xsl:text>public</xsl:text> |
| 161 </xsl:template> | 168 </xsl:template> |
| 162 | 169 |
| 163 <!-- property-type --> | 170 <!-- property-type --> |
| 171 <xsl:template match="*" mode="property-type"> | |
| 172 <xsl:apply-templates select="." mode="member-type"/> | |
| 173 </xsl:template> | |
| 174 | |
| 164 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> | 175 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> |
| 165 <xsl:apply-templates select=".." mode="property-type"/> | 176 <xsl:apply-templates select=".." mode="property-type"/> |
| 166 </xsl:template> | 177 </xsl:template> |
| 167 | 178 |
| 168 <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="property-type"> | 179 <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="property-type"> |
| 170 <xsl:apply-templates select=".." mode="property-type"/> | 181 <xsl:apply-templates select=".." mode="property-type"/> |
| 171 </cs:array> | 182 </cs:array> |
| 172 </xsl:template> | 183 </xsl:template> |
| 173 | 184 |
| 174 <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> | 185 <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> |
| 175 <xsl:call-template name="getPrimaryKey"> | 186 <xsl:variable name="otherKey"> |
| 176 <xsl:with-param name="type" select="../@type"/> | |
| 177 </xsl:call-template> | |
| 178 </xsl:template> | |
| 179 | |
| 180 <xsl:template match="m:hasA[@type and boolean(@optional)]/m:thisKey" mode="property-type"> | |
| 181 <cs:nullable> | |
| 182 <xsl:call-template name="getPrimaryKey"> | 187 <xsl:call-template name="getPrimaryKey"> |
| 183 <xsl:with-param name="type" select="../@type"/> | 188 <xsl:with-param name="type" select="../@type"/> |
| 184 </xsl:call-template> | 189 </xsl:call-template> |
| 185 </cs:nullable> | 190 </xsl:variable> |
| 186 </xsl:template> | 191 <xsl:choose> |
| 187 | 192 <xsl:when test="@optional"> |
| 188 <xsl:template match="*" mode="property-type"> | 193 </xsl:when> |
| 189 <xsl:apply-templates select="." mode="member-type"/> | 194 <cs:nullable> |
| 195 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> | |
| 196 </cs:nullable> | |
| 197 <xsl:otherwise> | |
| 198 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> | |
| 199 </xsl:otherwise> | |
| 200 </xsl:choose> | |
| 190 </xsl:template> | 201 </xsl:template> |
| 191 | 202 |
| 192 <!-- property-attributes --> | 203 <!-- property-attributes --> |
| 193 <xsl:template match="m:primaryKey" mode="property-attributes"> | 204 <xsl:template match="m:primaryKey" mode="property-attributes"> |
| 194 <cs:attribute> | 205 <cs:attribute> |
| 327 <xsl:apply-templates select="." mode="member-type"/> | 338 <xsl:apply-templates select="." mode="member-type"/> |
| 328 </xsl:template> | 339 </xsl:template> |
| 329 <!-- field-initializer --> | 340 <!-- field-initializer --> |
| 330 <xsl:template match="*|text()" mode="field-initializer"/> | 341 <xsl:template match="*|text()" mode="field-initializer"/> |
| 331 | 342 |
| 332 <xsl:template name="getKeyClrMemberName"> | 343 <xsl:template name="getClrKeyReference"> |
| 333 <xsl:param name="explicitMemberName" select="''"/> | |
| 334 <xsl:param name="type"/> | 344 <xsl:param name="type"/> |
| 335 <xsl:param name="short" select="false()"/> | 345 <xsl:variable name="primaryKey"> |
| 346 <xsl:call-template name="getPrimaryKey"> | |
| 347 <xsl:with-param name="type" select="$type"/> | |
| 348 </xsl:call-template> | |
| 349 </xsl:variable> | |
| 350 | |
| 351 <xsl:apply-templates select="exsl:node-set($primaryKey)" mode="clr-member-reference"/> | |
| 352 </xsl:template> | |
| 353 | |
| 354 <!-- --> | |
| 355 <xsl:template name="getClrMemberReference"> | |
| 356 <xsl:param name="type"/> | |
| 357 <xsl:param name="memberName"/> | |
| 358 <xsl:param name="scope" select="members"/> | |
| 359 <xsl:variable name="member"> | |
| 360 <xsl:call-template name="getMembers"> | |
| 361 <xsl:with-param name="memberName" select="$memberName"/> | |
| 362 <xsl:with-param name="type" select="$type"/> | |
| 363 </xsl:call-template> | |
| 364 </xsl:variable> | |
| 365 | |
| 366 <xsl:apply-templates select="exsl:node-set($member)" mode="clr-member-reference"/> | |
| 367 </xsl:template> | |
| 368 | |
| 369 <xsl:template match="*" mode="clr-member-reference"> | |
| 370 <xsl:param name="$type" select="@declaringType"/> | |
| 336 <cs:member> | 371 <cs:member> |
| 337 <xsl:choose> | 372 <xsl:attribute name="name"> |
| 338 <xsl:when test="$explicitMemberName"> | 373 <xsl:apply-templates select="." mode="member-name"/> |
| 339 <xsl:attribute name="name"> | 374 </xsl:attribute> |
| 340 <xsl:value-of select="$explicitMemberName"/> | 375 <xsl:call-template name="getClrType"> |
| 341 </xsl:attribute> | 376 <xsl:with-param name="type" select="$type"/> |
| 342 </xsl:when> | 377 </xsl:call-template> |
| 343 <xsl:otherwise> | |
| 344 <xsl:attribute name="name"> | |
| 345 <xsl:call-template name="getKeyName"> | |
| 346 <xsl:with-param name="type" select="$type"/> | |
| 347 </xsl:call-template> | |
| 348 </xsl:attribute> | |
| 349 </xsl:otherwise> | |
| 350 </xsl:choose> | |
| 351 <xsl:if test="not($short)"> | |
| 352 <xsl:call-template name="getClrType"> | |
| 353 <xsl:with-param name="type" select="$type"/> | |
| 354 </xsl:call-template> | |
| 355 </xsl:if> | |
| 356 </cs:member> | 378 </cs:member> |
| 357 </xsl:template> | 379 </xsl:template> |
| 358 | 380 |
| 359 <xsl:template name="getClrMemberName"> | |
| 360 <xsl:param name="memberName"/> | |
| 361 <xsl:param name="type"/> | |
| 362 <xsl:param name="explicitMemberName" select="''"/> | |
| 363 <xsl:param name="short" select="false()"/> | |
| 364 <cs:member> | |
| 365 <xsl:choose> | |
| 366 <xsl:when test="$explicitMemberName"> | |
| 367 <xsl:attribute name="name"> | |
| 368 <xsl:value-of select="$explicitMemberName"/> | |
| 369 </xsl:attribute> | |
| 370 </xsl:when> | |
| 371 <xsl:otherwise> | |
| 372 <xsl:attribute name="name"> | |
| 373 <xsl:call-template name="getClrPropertyName"> | |
| 374 <xsl:with-param name="member" select="$memberName"/> | |
| 375 <xsl:with-param name="type" select="$type"/> | |
| 376 </xsl:call-template> | |
| 377 </xsl:attribute> | |
| 378 </xsl:otherwise> | |
| 379 </xsl:choose> | |
| 380 <xsl:if test="not($short)"> | |
| 381 <xsl:call-template name="getClrType"> | |
| 382 <xsl:with-param name="type" select="$type"/> | |
| 383 </xsl:call-template> | |
| 384 </xsl:if> | |
| 385 </cs:member> | |
| 386 </xsl:template> | |
| 387 | |
| 388 <!-- lookups for the specified member for the specified type | |
| 389 and returns the CLR property name --> | |
| 390 <xsl:template name="getClrPropertyName"> | |
| 391 <xsl:param name="type"/> | |
| 392 <xsl:param name="member"/> | |
| 393 <!-- prevents cyclic references --> | |
| 394 <xsl:param name="seen" select="/.."/> | |
| 395 <xsl:for-each select="$module"> | |
| 396 <xsl:apply-templates select="key('type', $type)" | |
| 397 mode="member-lookup"> | |
| 398 <xsl:with-param name="member" select="$member"/> | |
| 399 <xsl:with-param name="seen" select="$seen"/> | |
| 400 </xsl:apply-templates> | |
| 401 </xsl:for-each> | |
| 402 </xsl:template> | |
| 403 | 381 |
| 404 <!-- resolves CLR type for the given type --> | 382 <!-- resolves CLR type for the given type --> |
| 405 <xsl:template name="getClrType"> | 383 <xsl:template name="getClrType"> |
| 406 <xsl:param name="type" /> | 384 <xsl:param name="type" /> |
| 407 <xsl:param name="typeArgs" select="/.." /> | 385 <xsl:param name="typeArgs" select="/.." /> |
