Mercurial > pub > ModelGenerator
comparison xslt/generator.csharp.xsl @ 6:1f4009d4afb6
working on model to csharp transform
| author | cin |
|---|---|
| date | Mon, 05 Mar 2018 10:37:47 +0300 |
| parents | 6f67d3a6b950 |
| children | 3fe157be5141 |
comparison
equal
deleted
inserted
replaced
| 5:6f67d3a6b950 | 6:1f4009d4afb6 |
|---|---|
| 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 <!-- select all members --> |
| 30 <xsl:variable name="members"> | 30 <xsl:variable name="members"> |
| 31 <xsl:apply-templates mode="fiter-members"/> | 31 <xsl:apply-templates mode="filter-members"/> |
| 32 </xsl:variable> | 32 </xsl:variable> |
| 33 | 33 |
| 34 <cs:class modifiers="partial"> | 34 <cs:class modifiers="partial"> |
| 35 <!-- generate class name --> | 35 <!-- generate class name --> |
| 36 <xsl:attribute name="name"> | 36 <xsl:attribute name="name"> |
| 136 | 136 |
| 137 <!-- property --> | 137 <!-- property --> |
| 138 | 138 |
| 139 <xsl:template match="*" mode="property"> | 139 <xsl:template match="*" mode="property"> |
| 140 <cs:property modifiers="public"> | 140 <cs:property modifiers="public"> |
| 141 <xsl:attribute name="name"><xsl:apply-templates select="." mode="property-name"/></xsl:attribute> | 141 <xsl:attribute name="name"><xsl:apply-templates select="." mode="member-name"/></xsl:attribute> |
| 142 <xsl:attribute name="modifiers"><xsl:apply-templates select="." mode="property-modifiers"/></xsl:attribute> | 142 <xsl:attribute name="modifiers"><xsl:apply-templates select="." mode="member-modifiers"/></xsl:attribute> |
| 143 <xsl:apply-templates select="." mode="property-type"/> | 143 <xsl:apply-templates select="." mode="member-type"/> |
| 144 <xsl:apply-templates select="." mode="property-attributes"/> | 144 <xsl:apply-templates select="." mode="member-attributes"/> |
| 145 <xsl:apply-templates select="." mode="property-extension" /> | 145 <xsl:apply-templates select="." mode="member-extension" /> |
| 146 <xsl:apply-templates select="." mode="property-accessors"/> | 146 <xsl:apply-templates select="." mode="property-accessors"/> |
| 147 </cs:property> | 147 </cs:property> |
| 148 </xsl:template> | 148 </xsl:template> |
| 149 | 149 |
| 150 | 150 |
| 151 <!-- property-name --> | 151 <!-- member-name --> |
| 152 <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="member-name"> |
| 153 <!-- 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 --> |
| 154 <xsl:apply-templates select=".." mode="property-name"/> | 154 <xsl:apply-templates select=".." mode="member-name"/> |
| 155 </xsl:template> | 155 </xsl:template> |
| 156 <xsl:template match="m:hasMany/clr:association[not(@name|@clr:name)]" mode="property-name"> | 156 <xsl:template match="m:hasMany/clr:association[not(@name|@clr:name)]" mode="member-name"> |
| 157 <!-- if the association doesn't define a name, use it from the parent node --> | 157 <!-- if the association doesn't define a name, use it from the parent node --> |
| 158 <xsl:apply-templates select=".." mode="property-name"/> | 158 <xsl:apply-templates select=".." mode="member-name"/> |
| 159 </xsl:template> | 159 </xsl:template> |
| 160 | 160 |
| 161 <xsl:template match="*" mode="property-name"> | 161 <!-- member-modifiers --> |
| 162 <xsl:apply-templates select="." mode="member-name"/> | 162 <xsl:template match="*" mode="member-modifiers"> |
| 163 </xsl:template> | |
| 164 | |
| 165 <!-- property-modifiers --> | |
| 166 <xsl:template match="*" mode="property-modifiers"> | |
| 167 <xsl:text>public</xsl:text> | 163 <xsl:text>public</xsl:text> |
| 168 </xsl:template> | 164 </xsl:template> |
| 169 | 165 |
| 170 <!-- property-type --> | 166 <!-- member-type --> |
| 171 <xsl:template match="*" mode="property-type"> | 167 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="member-type"> |
| 172 <xsl:apply-templates select="." mode="member-type"/> | 168 <xsl:apply-templates select=".." mode="member-type"/> |
| 173 </xsl:template> | 169 </xsl:template> |
| 174 | 170 |
| 175 <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> | 171 <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="member-type"> |
| 176 <xsl:apply-templates select=".." mode="property-type"/> | |
| 177 </xsl:template> | |
| 178 | |
| 179 <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="property-type"> | |
| 180 <cs:array> | 172 <cs:array> |
| 181 <xsl:apply-templates select=".." mode="property-type"/> | 173 <xsl:apply-templates select=".." mode="member-type"/> |
| 182 </cs:array> | 174 </cs:array> |
| 183 </xsl:template> | 175 </xsl:template> |
| 184 | 176 |
| 185 <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> | 177 <xsl:template match="m:hasA[@type]/m:thisKey" mode="member-type"> |
| 186 <xsl:variable name="otherKey"> | 178 <xsl:variable name="otherKey"> |
| 187 <xsl:call-template name="getPrimaryKey"> | 179 <xsl:call-template name="getPrimaryKey"> |
| 188 <xsl:with-param name="type" select="../@type"/> | 180 <xsl:with-param name="type" select="../@type"/> |
| 189 </xsl:call-template> | 181 </xsl:call-template> |
| 190 </xsl:variable> | 182 </xsl:variable> |
| 191 <xsl:choose> | 183 <xsl:choose> |
| 192 <xsl:when test="@optional"> | 184 <xsl:when test="@optional"> |
| 185 <cs:nullable> | |
| 186 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> | |
| 187 </cs:nullable> | |
| 193 </xsl:when> | 188 </xsl:when> |
| 194 <cs:nullable> | |
| 195 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> | |
| 196 </cs:nullable> | |
| 197 <xsl:otherwise> | 189 <xsl:otherwise> |
| 198 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> | 190 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> |
| 199 </xsl:otherwise> | 191 </xsl:otherwise> |
| 200 </xsl:choose> | 192 </xsl:choose> |
| 201 </xsl:template> | 193 </xsl:template> |
| 202 | 194 |
| 203 <!-- property-attributes --> | 195 <!-- member-attributes --> |
| 204 <xsl:template match="m:primaryKey" mode="property-attributes"> | 196 <xsl:template match="m:primaryKey" mode="member-attributes"> |
| 205 <cs:attribute> | 197 <cs:attribute> |
| 206 <cs:type name="PrimaryKey" namespace="Linq2Db" /> | 198 <cs:type name="PrimaryKey" namespace="Linq2Db" /> |
| 207 </cs:attribute> | 199 </cs:attribute> |
| 208 </xsl:template> | 200 </xsl:template> |
| 209 | 201 |
| 210 <xsl:template match="m:hasA/clr:association" mode="property-attributes"> | 202 <xsl:template match="m:hasA/clr:association" mode="member-attributes"> |
| 211 <cs:attribute> | 203 <cs:attribute> |
| 212 <cs:type name="Association" namespace="Linq2Db"/> | 204 <cs:type name="Association" namespace="Linq2Db"/> |
| 213 <cs:parameter name="thisKey"> | 205 <cs:parameter name="thisKey"> |
| 214 <cs:nameOf> | 206 <cs:nameOf> |
| 215 <xsl:call-template name="getMember"> | 207 <xsl:call-template name="getClrMemberReference"> |
| 216 <xsl:with-param name="memberName" select="../@name"/> | 208 <xsl:with-param name="memberName" select="../@name"/> |
| 217 <xsl:with-param name="explicitMemberName" select="@thisKey"/> | 209 <xsl:with-param name="type" select="../@declaringType"/> |
| 218 <xsl:with-param name="type" select="../../@name"/> | |
| 219 <xsl:with-param name="short" select="true()"/> | |
| 220 </xsl:call-template> | 210 </xsl:call-template> |
| 221 </cs:nameOf> | 211 </cs:nameOf> |
| 222 </cs:parameter> | 212 </cs:parameter> |
| 223 <cs:parameter name="otherKey"> | 213 <cs:parameter name="otherKey"> |
| 224 <cs:nameOf> | 214 <cs:nameOf> |
| 225 <xsl:call-template name="getKeyMember"> | 215 <xsl:call-template name="getClrKeyReference"> |
| 226 <xsl:with-param name="explicitMemberName" select="@thisKey"/> | |
| 227 <xsl:with-param name="type" select="../@type"/> | 216 <xsl:with-param name="type" select="../@type"/> |
| 228 </xsl:call-template> | 217 </xsl:call-template> |
| 229 </cs:nameOf> | 218 </cs:nameOf> |
| 230 </cs:parameter> | 219 </cs:parameter> |
| 231 </cs:attribute> | 220 </cs:attribute> |
| 232 </xsl:template> | 221 </xsl:template> |
| 233 | 222 |
| 234 <xsl:template match="m:hasMany/clr:association" mode="property-attributes"> | 223 <xsl:template match="m:hasMany/clr:association" mode="member-attributes"> |
| 235 <cs:attribute> | 224 <cs:attribute> |
| 236 <cs:type name="Association" namespace="Linq2Db"/> | 225 <cs:type name="Association" namespace="Linq2Db"/> |
| 237 <!-- thisKey points to own primaryKey which may be inherited, using getKeyName to address such cases --> | 226 <!-- thisKey points to own primaryKey which may be inherited, using getKeyName to address such cases --> |
| 238 <cs:parameter name="thisKey"> | 227 <cs:parameter name="thisKey"> |
| 239 <cs:nameOf> | 228 <cs:nameOf> |
| 240 <xsl:call-template name="getKeyMember"> | 229 <xsl:call-template name="getClrKeyReference"> |
| 241 <xsl:with-param name="type" select="../../@name"/> | 230 <xsl:with-param name="type" select="../../@name"/> |
| 242 <xsl:with-param name="explicitMemberName" select="@thisKey"/> | |
| 243 <xsl:with-param name="short" select="true()"/> | |
| 244 </xsl:call-template> | 231 </xsl:call-template> |
| 245 </cs:nameOf> | 232 </cs:nameOf> |
| 246 </cs:parameter> | 233 </cs:parameter> |
| 247 <cs:parameter name="otherKey"> | 234 <cs:parameter name="otherKey"> |
| 248 <cs:nameOf> | 235 <cs:nameOf> |
| 249 <xsl:call-template name="getMember"> | 236 <xsl:call-template name="getClrMemberReference"> |
| 250 <xsl:with-param name="type" select="../@type"/> | 237 <xsl:with-param name="type" select="../@type"/> |
| 251 <xsl:with-param name="memberName" select="../m:otherKey/@name"/> | 238 <xsl:with-param name="memberName" select="../m:otherKey/@name"/> |
| 252 <xsl:with-param name="explicitMemberName" select="@otherKey"/> | |
| 253 </xsl:call-template> | 239 </xsl:call-template> |
| 254 </cs:nameOf> | 240 </cs:nameOf> |
| 255 </cs:parameter> | 241 </cs:parameter> |
| 256 </cs:attribute> | 242 </cs:attribute> |
| 257 </xsl:template> | |
| 258 | |
| 259 <xsl:template match="*" mode="property-attributes"> | |
| 260 <xsl:apply-templates select="." mode="member-attributes"/> | |
| 261 </xsl:template> | |
| 262 | |
| 263 <!-- property-extension --> | |
| 264 <xsl:template match="*" mode="property-extension"> | |
| 265 <xsl:apply-templates select="." mode="member-extension"/> | |
| 266 </xsl:template> | 243 </xsl:template> |
| 267 | 244 |
| 268 <!-- property-accessors --> | 245 <!-- property-accessors --> |
| 269 <xsl:template match="*" mode="property-accessors"> | 246 <xsl:template match="*" mode="property-accessors"> |
| 270 <cs:get/> | 247 <cs:get/> |
| 296 </xsl:template> | 273 </xsl:template> |
| 297 | 274 |
| 298 <!-- fields --> | 275 <!-- fields --> |
| 299 <xsl:template match="*" mode="field"> | 276 <xsl:template match="*" mode="field"> |
| 300 <cs:field> | 277 <cs:field> |
| 301 <xsl:attribute name="name"><xsl:apply-templates select="." mode="field-name"/></xsl:attribute> | 278 <xsl:attribute name="name"><xsl:apply-templates select="." mode="member-name"/></xsl:attribute> |
| 302 <xsl:apply-templates select="." mode="field-type"/> | 279 <xsl:apply-templates select="." mode="member-type"/> |
| 303 <xsl:apply-templates select="." mode="field-initializer"/> | 280 <xsl:apply-templates select="." mode="field-initializer"/> |
| 304 </cs:field> | 281 </cs:field> |
| 305 </xsl:template> | 282 </xsl:template> |
| 306 | 283 |
| 307 <!-- field-name --> | 284 <!-- field-name --> |
| 308 <xsl:template match="m:hasA/clr:lazy" mode="field-name"> | 285 <xsl:template match="m:hasA/clr:lazy" mode="member-name"> |
| 309 <xsl:text>m_lazy</xsl:text> | 286 <xsl:text>m_lazy</xsl:text> |
| 310 <xsl:apply-templates select=".." mode="property-name"/> | 287 <xsl:apply-templates select=".." mode="member-name"/> |
| 311 </xsl:template> | 288 </xsl:template> |
| 312 | 289 |
| 313 <xsl:template match="clr:lazy[@field]" mode="field-name"> | 290 <xsl:template match="clr:lazy[@field]" mode="member-name"> |
| 314 <xsl:value-of select="@field"/> | 291 <xsl:value-of select="@field"/> |
| 315 </xsl:template> | 292 </xsl:template> |
| 316 | 293 |
| 317 <xsl:template match="*" mode="field-name"> | 294 <!-- member-type --> |
| 318 <xsl:apply-templates select="." mode="member-name"/> | 295 <xsl:template match="m:hasA[@optional='true']/clr:lazy" mode="member-type"> |
| 319 </xsl:template> | 296 <xsl:variable name="otherKey"> |
| 320 | 297 <xsl:call-template name="getPrimaryKey"> |
| 321 <!-- field-type --> | 298 <xsl:with-param name="type" select="../@type"/> |
| 322 <xsl:template match="m:hasA[@optional='true']/clr:lazy" mode="field-type"> | 299 </xsl:call-template> |
| 300 </xsl:variable> | |
| 323 <cs:type name="NullableReference" namespace="Pallada.Data"> | 301 <cs:type name="NullableReference" namespace="Pallada.Data"> |
| 324 <xsl:call-template name="getKeyType"> | 302 <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> |
| 325 <xsl:with-param name="type" select="../@type"/> | 303 <xsl:apply-templates select=".." mode="member-type"/> |
| 326 </xsl:call-template> | |
| 327 <xsl:apply-templates select=".." mode="property-type"/> | |
| 328 </cs:type> | 304 </cs:type> |
| 329 </xsl:template> | 305 </xsl:template> |
| 330 <xsl:template match="m:hasA[@optional!='true']/clr:lazy" mode="field-type"> | 306 <xsl:template match="m:hasA[@optional!='true']/clr:lazy" mode="member-type"> |
| 331 <cs:type name="Reference" namespace="Pallada.Data"> | 307 <cs:type name="Reference" namespace="Pallada.Data"> |
| 332 <xsl:apply-templates select="../m:thisKey" mode="property-type"/> | 308 <xsl:apply-templates select="../m:thisKey" mode="member-type"/> |
| 333 <xsl:apply-templates select=".." mode="property-type"/> | 309 <xsl:apply-templates select=".." mode="member-type"/> |
| 334 </cs:type> | 310 </cs:type> |
| 335 </xsl:template> | 311 </xsl:template> |
| 336 | 312 |
| 337 <xsl:template match="*" mode="field-type"> | |
| 338 <xsl:apply-templates select="." mode="member-type"/> | |
| 339 </xsl:template> | |
| 340 <!-- field-initializer --> | 313 <!-- field-initializer --> |
| 341 <xsl:template match="*|text()" mode="field-initializer"/> | 314 <xsl:template match="*|text()" mode="field-initializer"/> |
| 342 | 315 |
| 343 <xsl:template name="getClrKeyReference"> | 316 <xsl:template name="getClrKeyReference"> |
| 344 <xsl:param name="type"/> | 317 <xsl:param name="type"/> |
| 365 | 338 |
| 366 <xsl:apply-templates select="exsl:node-set($member)" mode="clr-member-reference"/> | 339 <xsl:apply-templates select="exsl:node-set($member)" mode="clr-member-reference"/> |
| 367 </xsl:template> | 340 </xsl:template> |
| 368 | 341 |
| 369 <xsl:template match="*" mode="clr-member-reference"> | 342 <xsl:template match="*" mode="clr-member-reference"> |
| 370 <xsl:param name="$type" select="@declaringType"/> | 343 <xsl:param name="type" select="@declaringType"/> |
| 371 <cs:member> | 344 <cs:member> |
| 372 <xsl:attribute name="name"> | 345 <xsl:attribute name="name"> |
| 373 <xsl:apply-templates select="." mode="member-name"/> | 346 <xsl:apply-templates select="." mode="member-name"/> |
| 374 </xsl:attribute> | 347 </xsl:attribute> |
| 375 <xsl:call-template name="getClrType"> | 348 <xsl:call-template name="getClrType"> |
| 376 <xsl:with-param name="type" select="$type"/> | 349 <xsl:with-param name="type" select="$type"/> |
| 377 </xsl:call-template> | 350 </xsl:call-template> |
| 378 </cs:member> | 351 </cs:member> |
| 379 </xsl:template> | 352 </xsl:template> |
| 380 | |
| 381 | 353 |
| 382 <!-- resolves CLR type for the given type --> | 354 <!-- resolves CLR type for the given type --> |
| 383 <xsl:template name="getClrType"> | 355 <xsl:template name="getClrType"> |
| 384 <xsl:param name="type" /> | 356 <xsl:param name="type" /> |
| 385 <xsl:param name="typeArgs" select="/.." /> | 357 <xsl:param name="typeArgs" select="/.." /> |
