Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Remove Extra Lines using TextTemplateAction
 

Remove Extra Lines using TextTemplateAction

Hello everyone,

I am using the TextTemplateAction to generate some code. However, I am getting these extra line spaces because of if statements. Specially, when the if condition is false.

Template Code

Code Block

#Region "Methods"

<# foreach(Field lField in CurrentEntity.Fields) { #>

Public Overridable Function <#= lField.Name #>() As ValidationCheckCol Implements I<#= CurrentEntity.CodeName #>Validator.<#= lField.Name #>

Dim lReturn As New ValidationCheckCol

<# if (!lField.Nullable) {#>

lReturn.Add(ValidationFactory.NullValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>"))

<# } #>

<# if (lField.ConstrainLength) {#>

lReturn.Add(ValidationFactory.LengthValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>", <#= lField.Length #>))

<# } #>

<# if (lField.RefData.Name.Length > 0) {#>

lReturn.Add(ValidationFactory.LookupValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>", <#= lField.RefData.Name #>, "<#= lField.RefData.ValueProperty #>"))

<# } #>

<# if (lField.Name == "BeginEffectiveDate" ) {#>

lReturn.Add(ValidationFactory.DateComparisonValidation("Begin Effective Date", Entity, "BeginEffectiveDate", "EndEffectiveDate", "Value of {0} is more than the End Effective Date {1}"))

<# } #>

<# if (lField.Name == "EndEffectiveDate" ) {#>

lReturn.Add(ValidationFactory.DateComparisonValidation("End Effective Date", Entity, "BeginEffectiveDate", "EndEffectiveDate", "Value of {1} is less than the Begin Effective Date {0}"))

<# } #>

<# if (lField.Type == "DateTime" ) {#>

lReturn.Add(ValidationFactory.DateRangeValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>"))

<# } #>

Return lReturn

End Function

<# } #>

#End Region

Output from the Template

Code Block

Public Overridable Function LastUpdatedByUser() As ValidationCheckCol Implements IKDOTJurisdictionValidator.LastUpdatedByUser

Dim lReturn As New ValidationCheckCol

'Extra Line

lReturn.Add(ValidationFactory.NullValidation("LastUpdatedByUser", Entity, "LastUpdatedByUser"))

'Extra Line

lReturn.Add(ValidationFactory.LengthValidation("LastUpdatedByUser", Entity, "LastUpdatedByUser", 30))

'Extra Line

'Extra Line

'Extra Line

'Extra Line

'Extra Line

'Extra Line

Return lReturn

End Function




Syed
Sy _  Saturday, October 06, 2007 7:34 AM

Hi Sy

that's why you have a CR after or before each IF sentence. Everything that's not enclosed between <# brackets will be proceced. Try use the following:

<# if (lField.Type == "DateTime" ) {#> lReturn.Add(ValidationFactory.DateRangeValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>")) <# } #>

all in the same line.

Jose Escrich  Monday, October 08, 2007 9:52 PM

Sy _  Saturday, October 06, 2007 7:34 AM

Hi Sy

that's why you have a CR after or before each IF sentence. Everything that's not enclosed between <# brackets will be proceced. Try use the following:

<# if (lField.Type == "DateTime" ) {#> lReturn.Add(ValidationFactory.DateRangeValidation("<#= lField.DisplayName #>", Entity, "<#= lField.Name #>")) <# } #>

all in the same line.

Jose Escrich  Monday, October 08, 2007 9:52 PM

Thanks for your reply. I get it now.
Sy _  Thursday, October 18, 2007 4:02 AM

You can use google to search for other answers

Custom Search

More Threads

• Converting IDTWizard to GAT project and solution templates.
• Share arguments between recipes
• Exception thrown on Register SCSF
• Nested Project Templates
• CreateProjectAction doesn't replace parameters regardless of ReplaceParameters value in vstemplate
• A Bug in DteHelper?
• Changes to the ProjectName from a Wizard is ignored
• Can't register guidance packages with Feb '07 GAX and GAT
• Web Client Software Factory - controller class navigation tree
• Error Installing to RTM Version of VS2005