共用方式為


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