The good thing about the code generation is that you can easily modify it to suite your needs. Today I will show you how to modify the code generation template so that it generates string properties that HtmlEncode and HtmlDecode the values in their respective setter and getter. The desired outcome will look like :
You can achieve this in a couple of steps.
First we need to locate the T4 templates that OpenAccess uses. The C# templates are usually located under C:\Program Files (x86)\Telerik\OpenAccess ORM\dsl\CodeGenerationTemplates\CSharp. Note that it would be better to copy this folder and not modify the default templates. You can specify which template the code generation is using through the model settings dialog.
What we need to modify is the Specific.ttinclude file. Then you should locate the InitializeDefaultUsings() method and add the System.Web using to the default usings. Your code should look like :
Then you have to find the code for adding a property. It should look like this prior to any changes :
In order to make it generate code that encodes and decodes these properties you should change it to look like this :
In two easy steps we have created a custom template that web developers could find very handy. Just imagine the possibilities . One can easily implement interfaces such as the INotifyPropertyChanged for example or add data annotations attributes.
We would really like to hear from you. Please share any neat ideas you might have about custom code generation that you would like to see in the product.
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required