Sdílet prostřednictvím


RequiresProvidesDirectiveProcessor.GeneratePostInitializationCode – metoda

Při přepsání v odvozené třídě přidá kód kódem inicializace třídy vygenerované transformace. Tento kód je přidán po inicializaci základní třídy.

Obor názvů:  Microsoft.VisualStudio.TextTemplating
Sestavení:  Microsoft.VisualStudio.TextTemplating.10.0 (v Microsoft.VisualStudio.TextTemplating.10.0.dll)

Syntaxe

'Deklarace
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>
)

Parametry

  • codeBuffer
    Typ: System.Text.StringBuilder
    Během zpracování spuštění je inicializován vyrovnávací paměti, který spojuje kód, který všechny procesory směrnice musí spustit po základní třídy.Jakýkoli kód, který spuštěním této směrnice procesor po inicializaci základní třídy pro tuto směrnici by zřetězit do této vyrovnávací paměti.

Poznámky

Protože GenerateTransformCode metody můžete přidat třídy vygenerované transformace kódem inicializace často potřebné k vytočení těchto metod.

Tato metoda je volána jednou pro tento procesor zpracovává směrnice. Proto můžete přidat kód podle směrnice codeBuffer. GetPostInitializationCodeForProcessingRunVrátí obsah codeBuffer Po zpracování všech směrnic.

Tato metoda se nazývá ProcessDirective.

Příklady

Tento příklad vytvoří kód po inicializaci základní třídy. V tomto příkladu je součástí větší například RequiresProvidesDirectiveProcessor Třída

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 + "\");");
}
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

RequiresProvidesDirectiveProcessor Třída

Microsoft.VisualStudio.TextTemplating – obor názvů

GeneratePreInitializationCode

GenerateTransformCode

ProcessDirective

GetPostInitializationCodeForProcessingRun