I am working with the templates provided by Devart in their Entity Developer product. I'm really not sure if these are pure T4 templates , but they certainly appear to be close. What I am trying to do is have the partial classes created for my entities implement IDataErrorInfo
and stub out the basic routines required for their implementation. The template is set to produce code in VB.NET
An example of the type of output that I would like to see in the implementation sections for the IDataErrorInfo
interface is here:
Default Public ReadOnly Property Item(columnName As String) As String Implements IDataErrorInfo.Item
Get
Select Case columnName
Case "CustomerId"
Return If(CustomerId is Nothing, "A Customer Must Be associated with the Order.", Nothing)
Case "InvoiceAddressId"
Return if(InvoiceAddressId Is Nothing, "An invoice address is required.", Nothing)
Case "OrderDate"
Return If(OrderDate Is Nothing Or OrderDate > Today, "A Valid order date that is not in the future is required.", Nothing)
End Select
End Get
End Property
Public ReadOnly Property [Error] As String Implements IDataErrorInfo.Error
Get
Return If(Me("CustomerId") IsNot Nothing OrElse Me("InvoiceAddressId") IsNot Nothing OrElse Me("OrderDate") IsNot Nothing, "Correct values", Nothing)
End Get
End Property
And I currently have the following in my template:
#Region "IDataErrorInfo Implementation"
Default Public ReadOnly Property Item(columnName As String) As String Implements IDataErrorInfo.Item
Get
Select Case columnName
<#
For Each prop As EntityProperty In cls.Properties #>
Case $"{<#= prop.Name #>}"
<# if Property.GetType() Is TypeOf(String) Then #>
Return If(<#= prop.Name #> Is Nothing,"Add Message here.",Nothing)
<# Else #>
Return If(<#= prop.Name #> = Nothing,"Add Message here.",Nothing)
<#End if
Next
#>
End Select
End Get
End Property
Public ReadOnly Property [Error] As String Implements IDataErrorInfo.Error
Get
End Get
End Property
#End Region
In the definition for the Item
property if I remove the "if" condition which is supposed to be determining the type of the current property being referred to in the list, then I end up with a fully stubbed out select case statement, but whenever the property being referred to is not a string then when it comes to building the project the code fails because 'is' is not a good comparative statement where the property currently in the loop happens to be a integer or double for example.
Can anyone spot any obvious error that I have made in the template.