Defining Your Own Merge Strategy

Merge strategies are carried out by classes that implement the CodeSmith.Engine.IMergeStrategy interface. You can find the details of this interface in the CodeSmith Generator API help file.

After defining your own merge strategy, there are two ways that you can use it. First, you can specify a fully-qualified assembly name when calling the merge strategy from the command line:

/merge:MyMergeAssembly.MyMergeStragegy="MergeParameters=Sample Merge Parameters;Language=C#;"

To register your merge strategy you will need to add a registry key to the HKEY_CURRENT_USER\Software\CodeSmith\v5.3\MergeStrategyAlias.  Here is an registry export of the default InsertRegion Merge Strategy registry entry:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\CodeSmith\v5.3\MergeStrategyAlias\0]
"Name"="InsertRegion"
"TypeName"="CodeSmith.Engine.InsertRegionMergeStrategy,CodeSmith.Engine"

Adding your merge strategy to the alias list allows you to call it by name when you use the /merge switch.

This feature is only available in the Professional Edition of CodeSmith.