Example: GeneralEntityValidatorFactory template. *

Posts   
 
    
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 01-Dec-2006 11:45:13   

Yesterday I read trough the LLBLGen SDK/Template studio documentation. At the end of the day I come up with my first customized template sunglasses

After learning some of the inside workings of LLBLGen code generation, and the built-in customization capabilities, I can only think things like: *) WOW sunglasses *) ...this is COOL! sunglasses *) Ehi! It's extremely flexible! simple_smile *)...

Now let's back to the business simple_smile

My first template simply create a GeneralEntityFalidatorFactory. So I have a shared method that create an entity validator from the EntityType.

I use this method in the commonBaseClass (from the 3rd party CommonBaseClass template).

The purpose is to have a flexible way of instantiate the right Validator for each entity. This is flexible because if I need to create specialized version of a particular EntityValidator, I can easily extend the generated GeneralEntityValidatorFactory to return the extender validator. And using the extended GeneralEntityValidatorFactory instead of the standard one, will do the job when I will need to develop the personalization we are thinking about simple_smile

Maybe that a GeneralEntityValidator Template is a useful addition to LLBLGen Pro; if this is the case, here is the code of my template (It’s only VB, I’m unsing it with LLBLGen 2.0/Adapter).


' ///////////////////////////////////////////////////////////////
' // This is generated code. 
' //////////////////////////////////////////////////////////////
' // Code is generated using LLBLGen Pro version: <[LLBLGenVersion]>
' // Code is generated on: <[Time]>
' // Code is generated using templates: <[TemplateName]>
' // Templates vendor: ____________
' // Templates version: <[TemplateVersion]>
' //////////////////////////////////////////////////////////////
Imports System

Imports <[RootNamespace]>.EntityClasses
Imports <[RootNamespace]>.HelperClasses

Imports SD.LLBLGen.Pro.ORMSupportClasses
<[ UserCodeRegion "AdditionalNamespaces" ]>
' __LLBLGENPRO_USER_CODE_REGION_START AdditionalNamespaces
' __LLBLGENPRO_USER_CODE_REGION_END
<[ EndUserCodeRegion ]>
Namespace <[RootNamespace]>.FactoryClasses

<[If HasEntity]>

    <Serializable()> _
    Public Class GeneralEntityValidatorFactory
        Public Shared Function Create(validatorEntityTypeToCreate As EntityType) As IValidator 

            Select Case validatorEntityTypeToCreate
<[Foreach Entity CrLf]>             Case <[RootNamespace]>.EntityType.<[CurrentEntityName]>Entity
                    Return New <[RootNamespace]>.ValidatorClasses.<[CurrentEntityName]>Validator()<[NextForeach]>
    
        
                Case Else
                    Throw New ArgumentException("Unexpected entity type! validatorEntityTypeToCreate=" & validatorEntityTypeToCreate.ToString,"validatorEntityTypeToCreate")
            End Select
            
        End Function        
    End Class
<[EndIf]>
End Namespace

Bye, Max

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 01-Dec-2006 12:27:00   

Thanks Max! simple_smile

I've updated the title of the thread, if you agree.

Frans Bouma | Lead developer LLBLGen Pro
Max avatar
Max
User
Posts: 221
Joined: 14-Jul-2006
# Posted on: 01-Dec-2006 12:52:15   

Otis wrote:

Thanks Max! simple_smile

I've updated the title of the thread, if you agree.

No problem simple_smile