The OnInit Event

The OnInit event fires when the CodeSmith Generator engine creates an instance of your template. You can override this event to perform any necessary setup tasks for your template. For instance, suppose your template uses an additional TextWriter to send a copy of its output to a socket on a remote computer via the Internet. You could override the OnInit event to check for Internet connectivity, and warn the user that the template will not succeed if you can't find an open Internet connection when the template is instantiated.