RequiresProvidesDirectiveProcessor.GeneratePostInitializationCode 方法

在派生类中重写时,向已生成转换类的初始化代码中添加代码。 此代码将在初始化基类之后添加。

命名空间:  Microsoft.VisualStudio.TextTemplating
程序集:  Microsoft.VisualStudio.TextTemplating.11.0(在 Microsoft.VisualStudio.TextTemplating.11.0.dll 中)

语法

声明
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>
)

参数

  • codeBuffer
    类型:System.Text.StringBuilder
    串联代码的缓冲区。处理运行期间,在初始化基类之后,所有指令处理器都必须运行这些代码。在初始化基类之后,此指令处理器必须为此指令运行的所有代码都应串联到此缓冲区。

备注

因为 GenerateTransformCode 可将方法添加至生成的转换类,因此初始化代码通常需要调用这些方法。

对于此处理器处理的每个指令调用此方法一次。 因此,您可以将每个指令的代码追加到 codeBuffer。 GetPostInitializationCodeForProcessingRun 在处理完所有指令之后返回 codeBuffer 的内容。

此方法由 ProcessDirective 调用。

示例

本示例在初始化基类后生成代码。 此示例摘自为 RequiresProvidesDirectiveProcessor 类提供的一个更大的示例。

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 安全性

请参见

参考

RequiresProvidesDirectiveProcessor 类

Microsoft.VisualStudio.TextTemplating 命名空间

GeneratePreInitializationCode

GenerateTransformCode

ProcessDirective

GetPostInitializationCodeForProcessingRun