Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to define a generator parameter
xomega
#1 Posted : Sunday, November 4, 2012 6:43:36 PM(UTC)
xomega



One of the ways to control the output of a custom-built generator is to define one or more parameters for the generator, the value(s) for which could be supplied by editing the generator's properties. Generally, this makes sense when the parameter has a simple value, is not shared with other generators and also is not tied to any of the model elements. Otherwise, you may want to consider extending the model with additional configurations, which you can make an arbitrary complex structure, tie it to any specific element of the model, or make it part of the global model configuration.

Xomega provides an easy way to define an additional parameter for you generator. The following steps detail this process.
  1. Declare a new parameter at the top of the XSL script for you generator as follows.
    Code:
    <xsl:param name="KeepTableNames"/>

  2. Reference that parameter value in the generator's script using the standard XSLT syntax, e.g. $KeepTableNames.
  3. Edit the project file for the model project. To do that you can right-click on the model project in Visual Studio and select the Unload Project context menu option. After that you can right-click again and select the menu option to edit the project file.
  4. Find a XomGenerator tag in the project file that corresponds to your generator.
  5. Add an element inside the XomGenerator tag for you generator, with a name that is the parameter name concatenated with the word "-param", e.g. KeepTableNames-param. Set the value of the element to the default value of the parameter.
  6. If the parameter type is not a string, then add an element with a name being the parameter name followed by "-type", e.g. KeepTableNames-type, and set the value of the element to be the fully qualified .Net type. The type should be accessible to Visual Studio and should have a default editor associated with it.
  7. Add an element with a name being the parameter name followed by "-desc", and set the value to be the description of the parameter, which would help developers to set the value.
  8. Optionally, add an element with a name being the parameter name followed by "-category", and set the value to be the category name of the parameter, which would help group parameters in the generator's properties tab.
  9. Save and close the project file, and then right-click on the project and select the Reload Project context menu option.
  10. Go to the properties tab of the generator by clicking F4, and make sure that your parameter is present there.
  11. Edit the value of the parameter and run the generator. Validate that the new value took effect when running the generator.

The following snippet demonstrates a setup of the KeepTableNames parameter in the project file.
Code:
<KeepTableNames-param>True</KeepTableNames-param>
<KeepTableNames-type>System.Boolean</KeepTableNames-type>
<KeepTableNames-desc>Specify whether to preserve table names in generated objects.</KeepTableNames-desc>
<KeepTableNames-category>Additional Flags</KeepTableNames-category>
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.