RequiresProvidesDirectiveProcessor.GeneratePostInitializationCode Method
When overridden in a derived class, adds code to the initialization code for the generated transformation class. This code is added after the base class is initialized.
Namespace: Microsoft.VisualStudio.TextTemplating
Assembly: Microsoft.VisualStudio.TextTemplating.12.0 (in Microsoft.VisualStudio.TextTemplating.12.0.dll)
Syntax
'Declaration
Protected MustOverride Sub GeneratePostInitializationCode ( _
directiveName As String, _
codeBuffer As StringBuilder, _
languageProvider As CodeDomProvider, _
requiresArguments As IDictionary(Of String, String), _
providesArguments As IDictionary(Of String, String) _
)
protected abstract void GeneratePostInitializationCode(
string directiveName,
StringBuilder codeBuffer,
CodeDomProvider languageProvider,
IDictionary<string, string> requiresArguments,
IDictionary<string, string> providesArguments
)
protected:
virtual void GeneratePostInitializationCode(
String^ directiveName,
StringBuilder^ codeBuffer,
CodeDomProvider^ languageProvider,
IDictionary<String^, String^>^ requiresArguments,
IDictionary<String^, String^>^ providesArguments
) abstract
abstract GeneratePostInitializationCode :
directiveName:string *
codeBuffer:StringBuilder *
languageProvider:CodeDomProvider *
requiresArguments:IDictionary<string, string> *
providesArguments:IDictionary<string, string> -> unit
protected abstract function GeneratePostInitializationCode(
directiveName : String,
codeBuffer : StringBuilder,
languageProvider : CodeDomProvider,
requiresArguments : IDictionary<String, String>,
providesArguments : IDictionary<String, String>
)
Parameters
directiveName
Type: System.StringThe name of the directive.
codeBuffer
Type: System.Text.StringBuilderThe buffer that concatenates the code that all directive processors must run after the base class is initialized during a processing run. Any code that this directive processor must run for this directive after the base class is initialized should be concatenated to this buffer.
languageProvider
Type: System.CodeDom.Compiler.CodeDomProviderThe code generator that creates the code to add to codeBuffer.
requiresArguments
Type: System.Collections.Generic.IDictionary<String, String>The standard parameters that the directive processor requires.
providesArguments
Type: System.Collections.Generic.IDictionary<String, String>The standard parameters that the directive processor provides.
Remarks
Because GenerateTransformCode can add methods to the generated transformation class, initialization code is often required to call those methods.
This method is called once for each directive that this processor processes. Therefore, you can append the code for each directive to codeBuffer. GetPostInitializationCodeForProcessingRun returns the contents of codeBuffer after all the directives have been processed.
This method is called by ProcessDirective.
Examples
This example generates code after the base class is initialized. This example is part of a larger example for the RequiresProvidesDirectiveProcessor class.
protected override void GeneratePostInitializationCode(string directiveName, StringBuilder codeBuffer, System.CodeDom.Compiler.CodeDomProvider languageProvider, IDictionary<string, string> requiresArguments, IDictionary<string, string> providesArguments)
{
if (StringComparer.InvariantCultureIgnoreCase.Compare(directiveName, DomDirectiveTag) == 0)
{
// Resolve the file name of the specified "requires" xml file
// This allows the xml file to be a path relative to the text template that is using the directive processor.
string xmlFile = this.Host.ResolvePath(requiresArguments[XmlFileRequiredParameterName]);
if (!File.Exists(xmlFile))
{
throw new FileNotFoundException("Unable to load " + XmlFileRequiredParameterName, xmlFile);
}
string fieldName = providesArguments[DomProvidedParameterName].ToLower(CultureInfo.InvariantCulture) + "Value";
// Write code to initialize the domValue field by loading the xml file.
// The property is named "Dom" by default but the template writer may have changed the name using a custom provides clause like 'provides="Dom=AnotherName"'
codeBuffer.Append(
"this." + fieldName + " = new XmlDocument();" +
"this." + fieldName + ".Load(@\"" + xmlFile + "\");");
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
See Also
Reference
RequiresProvidesDirectiveProcessor Class