Sdílet prostřednictvím


ITextTemplatingEngineHost.ResolvePath – metoda

Umožňuje hostiteli poskytnout úplnou cestu, název souboru nebo relativní cestu.

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

Syntaxe

'Deklarace
Function ResolvePath ( _
    path As String _
) As String
string ResolvePath(
    string path
)
String^ ResolvePath(
    String^ path
)
abstract ResolvePath : 
        path:string -> string 
function ResolvePath(
    path : String
) : String

Parametry

Vrácená hodnota

Typ: System.String
A String , která obsahuje absolutní cestou

Poznámky

Tuto metodu lze volat směrnice procesoru Pokud název souboru neobsahuje cestu. Hostitel může pokusit poskytnout informace o cestě k vyhledávání konkrétní cesty souboru a vrácení souboru a cesty, pokud nalezené

Tuto metodu lze volat 0, 1 nebo více než jednou pro každou šablonu transformace textu. Další informace naleznete v tématu Text šablona směrnic.

Hostitele lze hledat sestavení na různých místech v pořadí upřednostňuje nebo přidat cestu výběru na začátek odkazu na sestavení.

Příklady

Tuto metodu lze volat z textu šablony. Musíte nastavit hostspecific="true".

<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<#@ import namespace="System.IO" #>
<#
 // Find a path within the same project as the text template:
 string myFile = File.ReadAllText(this.Host.ResolvePath("MyFile.txt"));
#>
Content of myFile is:
<#= myFile #>

Následující příklad kódu ukazuje možné provedení vlastního hostitele. Příklad kódu je součástí větší příklad. Pro plný příklad, viz Walkthrough: Vytváření Uživatelský text šablona hostitel.

public string ResolvePath(string fileName)
{
  if (fileName == null)
  {
    throw new ArgumentNullException("the file name cannot be null");
  }
  //If the argument is the fully qualified path of an existing file,
  //then we are done
  if (File.Exists(fileName))
  {
    return fileName;
  }
  //Maybe the file is in the same folder as the text template that 
  //called the directive.
  string candidate = Path.Combine(Path.GetDirectoryName(this.TemplateFile), fileName);
  if (File.Exists(candidate))
  {
    return candidate;
  }
  //Look more places.
  //More code can go here...
  //If we cannot do better, return the original file name.
  return fileName;
}

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

ITextTemplatingEngineHost Rozhraní

Microsoft.VisualStudio.TextTemplating – obor názvů