Property Validation

Because you can define a property as being optional, you may want to validate the property in your template to determine whether or not the user has entered a value. For example, you might want to allow generating a class either with a namespace declaration or without, at the user's option. To do this, you would first define an appropriate optional property:

<%@ Property Name="ClassNamespace" Type="System.String" Optional="True" Category="Context" Description="The namespace that the generated class will be a member of." %>

In your template, you can check to see whether there's a value in this property at runtime. If so, you want to output the appropriate namespace declaration. If you're using C# as your template language, you'd do that like this:

<% if (ClassNamespace != null && ClassNamespace.Length > 0)
{ %>namespace <%= ClassNamespace %>{<% }
%>

If your template is using VB, the equivalent code is:

<% If Not ClassNamespace Is Nothing AndAlso ClassNamespace.Length > 0 Then %>
Namespace <%= ClassNamespace %>
<% End If %>