Mercurial > pub > ModelGenerator
diff 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 |
line wrap: on
line diff
--- a/xslt/generator.csharp.xsl Fri Mar 02 18:34:19 2018 +0300 +++ b/xslt/generator.csharp.xsl Mon Mar 05 10:37:47 2018 +0300 @@ -28,7 +28,7 @@ <xsl:template match="m:entity" mode="entity"> <!-- select all members --> <xsl:variable name="members"> - <xsl:apply-templates mode="fiter-members"/> + <xsl:apply-templates mode="filter-members"/> </xsl:variable> <cs:class modifiers="partial"> @@ -138,51 +138,43 @@ <xsl:template match="*" mode="property"> <cs:property modifiers="public"> - <xsl:attribute name="name"><xsl:apply-templates select="." mode="property-name"/></xsl:attribute> - <xsl:attribute name="modifiers"><xsl:apply-templates select="." mode="property-modifiers"/></xsl:attribute> - <xsl:apply-templates select="." mode="property-type"/> - <xsl:apply-templates select="." mode="property-attributes"/> - <xsl:apply-templates select="." mode="property-extension" /> + <xsl:attribute name="name"><xsl:apply-templates select="." mode="member-name"/></xsl:attribute> + <xsl:attribute name="modifiers"><xsl:apply-templates select="." mode="member-modifiers"/></xsl:attribute> + <xsl:apply-templates select="." mode="member-type"/> + <xsl:apply-templates select="." mode="member-attributes"/> + <xsl:apply-templates select="." mode="member-extension" /> <xsl:apply-templates select="." mode="property-accessors"/> </cs:property> </xsl:template> - <!-- property-name --> - <xsl:template match="m:hasA/clr:association[not(@name|@clr:name)]" mode="property-name"> + <!-- member-name --> + <xsl:template match="m:hasA/clr:association[not(@name|@clr:name)]" mode="member-name"> <!-- if the association doesn't define a name, use it from the parent node --> - <xsl:apply-templates select=".." mode="property-name"/> + <xsl:apply-templates select=".." mode="member-name"/> </xsl:template> - <xsl:template match="m:hasMany/clr:association[not(@name|@clr:name)]" mode="property-name"> + <xsl:template match="m:hasMany/clr:association[not(@name|@clr:name)]" mode="member-name"> <!-- if the association doesn't define a name, use it from the parent node --> - <xsl:apply-templates select=".." mode="property-name"/> + <xsl:apply-templates select=".." mode="member-name"/> </xsl:template> - <xsl:template match="*" mode="property-name"> - <xsl:apply-templates select="." mode="member-name"/> - </xsl:template> - - <!-- property-modifiers --> - <xsl:template match="*" mode="property-modifiers"> + <!-- member-modifiers --> + <xsl:template match="*" mode="member-modifiers"> <xsl:text>public</xsl:text> </xsl:template> - <!-- property-type --> - <xsl:template match="*" mode="property-type"> - <xsl:apply-templates select="." mode="member-type"/> + <!-- member-type --> + <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="member-type"> + <xsl:apply-templates select=".." mode="member-type"/> </xsl:template> - <xsl:template match="m:hasA[@type]/clr:association[not(clr:type)]" mode="property-type"> - <xsl:apply-templates select=".." mode="property-type"/> - </xsl:template> - - <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="property-type"> + <xsl:template match="m:hasMany[@type]/clr:association[not(clr:type)]" mode="member-type"> <cs:array> - <xsl:apply-templates select=".." mode="property-type"/> + <xsl:apply-templates select=".." mode="member-type"/> </cs:array> </xsl:template> - <xsl:template match="m:hasA[@type]/m:thisKey" mode="property-type"> + <xsl:template match="m:hasA[@type]/m:thisKey" mode="member-type"> <xsl:variable name="otherKey"> <xsl:call-template name="getPrimaryKey"> <xsl:with-param name="type" select="../@type"/> @@ -190,40 +182,37 @@ </xsl:variable> <xsl:choose> <xsl:when test="@optional"> + <cs:nullable> + <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> + </cs:nullable> </xsl:when> - <cs:nullable> - <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> - </cs:nullable> <xsl:otherwise> - <xsl:apply-templates select="exsl:node-set($otherKey)" mode="property-type"/> + <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> </xsl:otherwise> </xsl:choose> </xsl:template> - <!-- property-attributes --> - <xsl:template match="m:primaryKey" mode="property-attributes"> + <!-- member-attributes --> + <xsl:template match="m:primaryKey" mode="member-attributes"> <cs:attribute> <cs:type name="PrimaryKey" namespace="Linq2Db" /> </cs:attribute> </xsl:template> - <xsl:template match="m:hasA/clr:association" mode="property-attributes"> + <xsl:template match="m:hasA/clr:association" mode="member-attributes"> <cs:attribute> <cs:type name="Association" namespace="Linq2Db"/> <cs:parameter name="thisKey"> <cs:nameOf> - <xsl:call-template name="getMember"> + <xsl:call-template name="getClrMemberReference"> <xsl:with-param name="memberName" select="../@name"/> - <xsl:with-param name="explicitMemberName" select="@thisKey"/> - <xsl:with-param name="type" select="../../@name"/> - <xsl:with-param name="short" select="true()"/> + <xsl:with-param name="type" select="../@declaringType"/> </xsl:call-template> </cs:nameOf> </cs:parameter> <cs:parameter name="otherKey"> <cs:nameOf> - <xsl:call-template name="getKeyMember"> - <xsl:with-param name="explicitMemberName" select="@thisKey"/> + <xsl:call-template name="getClrKeyReference"> <xsl:with-param name="type" select="../@type"/> </xsl:call-template> </cs:nameOf> @@ -231,40 +220,28 @@ </cs:attribute> </xsl:template> - <xsl:template match="m:hasMany/clr:association" mode="property-attributes"> + <xsl:template match="m:hasMany/clr:association" mode="member-attributes"> <cs:attribute> <cs:type name="Association" namespace="Linq2Db"/> <!-- thisKey points to own primaryKey which may be inherited, using getKeyName to address such cases --> <cs:parameter name="thisKey"> <cs:nameOf> - <xsl:call-template name="getKeyMember"> + <xsl:call-template name="getClrKeyReference"> <xsl:with-param name="type" select="../../@name"/> - <xsl:with-param name="explicitMemberName" select="@thisKey"/> - <xsl:with-param name="short" select="true()"/> </xsl:call-template> </cs:nameOf> </cs:parameter> <cs:parameter name="otherKey"> <cs:nameOf> - <xsl:call-template name="getMember"> + <xsl:call-template name="getClrMemberReference"> <xsl:with-param name="type" select="../@type"/> <xsl:with-param name="memberName" select="../m:otherKey/@name"/> - <xsl:with-param name="explicitMemberName" select="@otherKey"/> </xsl:call-template> </cs:nameOf> </cs:parameter> </cs:attribute> </xsl:template> - <xsl:template match="*" mode="property-attributes"> - <xsl:apply-templates select="." mode="member-attributes"/> - </xsl:template> - - <!-- property-extension --> - <xsl:template match="*" mode="property-extension"> - <xsl:apply-templates select="." mode="member-extension"/> - </xsl:template> - <!-- property-accessors --> <xsl:template match="*" mode="property-accessors"> <cs:get/> @@ -298,45 +275,41 @@ <!-- fields --> <xsl:template match="*" mode="field"> <cs:field> - <xsl:attribute name="name"><xsl:apply-templates select="." mode="field-name"/></xsl:attribute> - <xsl:apply-templates select="." mode="field-type"/> + <xsl:attribute name="name"><xsl:apply-templates select="." mode="member-name"/></xsl:attribute> + <xsl:apply-templates select="." mode="member-type"/> <xsl:apply-templates select="." mode="field-initializer"/> </cs:field> </xsl:template> <!-- field-name --> - <xsl:template match="m:hasA/clr:lazy" mode="field-name"> + <xsl:template match="m:hasA/clr:lazy" mode="member-name"> <xsl:text>m_lazy</xsl:text> - <xsl:apply-templates select=".." mode="property-name"/> + <xsl:apply-templates select=".." mode="member-name"/> </xsl:template> - <xsl:template match="clr:lazy[@field]" mode="field-name"> + <xsl:template match="clr:lazy[@field]" mode="member-name"> <xsl:value-of select="@field"/> </xsl:template> - <xsl:template match="*" mode="field-name"> - <xsl:apply-templates select="." mode="member-name"/> - </xsl:template> - - <!-- field-type --> - <xsl:template match="m:hasA[@optional='true']/clr:lazy" mode="field-type"> - <cs:type name="NullableReference" namespace="Pallada.Data"> - <xsl:call-template name="getKeyType"> + <!-- member-type --> + <xsl:template match="m:hasA[@optional='true']/clr:lazy" mode="member-type"> + <xsl:variable name="otherKey"> + <xsl:call-template name="getPrimaryKey"> <xsl:with-param name="type" select="../@type"/> </xsl:call-template> - <xsl:apply-templates select=".." mode="property-type"/> + </xsl:variable> + <cs:type name="NullableReference" namespace="Pallada.Data"> + <xsl:apply-templates select="exsl:node-set($otherKey)" mode="member-type"/> + <xsl:apply-templates select=".." mode="member-type"/> </cs:type> </xsl:template> - <xsl:template match="m:hasA[@optional!='true']/clr:lazy" mode="field-type"> + <xsl:template match="m:hasA[@optional!='true']/clr:lazy" mode="member-type"> <cs:type name="Reference" namespace="Pallada.Data"> - <xsl:apply-templates select="../m:thisKey" mode="property-type"/> - <xsl:apply-templates select=".." mode="property-type"/> + <xsl:apply-templates select="../m:thisKey" mode="member-type"/> + <xsl:apply-templates select=".." mode="member-type"/> </cs:type> </xsl:template> - <xsl:template match="*" mode="field-type"> - <xsl:apply-templates select="." mode="member-type"/> - </xsl:template> <!-- field-initializer --> <xsl:template match="*|text()" mode="field-initializer"/> @@ -367,7 +340,7 @@ </xsl:template> <xsl:template match="*" mode="clr-member-reference"> - <xsl:param name="$type" select="@declaringType"/> + <xsl:param name="type" select="@declaringType"/> <cs:member> <xsl:attribute name="name"> <xsl:apply-templates select="." mode="member-name"/> @@ -378,7 +351,6 @@ </cs:member> </xsl:template> - <!-- resolves CLR type for the given type --> <xsl:template name="getClrType"> <xsl:param name="type" />