ITextTemplatingEngineHost.LoadIncludeText メソッド
部分テキスト テンプレート ファイルを含める要求に対応するテキストを取得します。
名前空間: Microsoft.VisualStudio.TextTemplating
アセンブリ: Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 (Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll 内)
構文
'宣言
Function LoadIncludeText ( _
requestFileName As String, _
<OutAttribute> ByRef content As String, _
<OutAttribute> ByRef location As String _
) As Boolean
bool LoadIncludeText(
string requestFileName,
out string content,
out string location
)
bool LoadIncludeText(
String^ requestFileName,
[OutAttribute] String^% content,
[OutAttribute] String^% location
)
abstract LoadIncludeText :
requestFileName:string *
content:string byref *
location:string byref -> bool
function LoadIncludeText(
requestFileName : String,
content : String,
location : String
) : boolean
パラメーター
- requestFileName
型: System.String
取得する部分テキスト テンプレート ファイルの名前。
- content
型: System.String%
取得されたテキストが格納されている String。ファイルが見つからなかった場合は Empty。
- location
型: System.String%
取得されたテキストの位置を表す String。ホストがインクルード ファイルの場所をレジストリで検索する場合、またはホストが既定で複数の場所を検索する場合、ホストは最後に見つかったインクルード ファイルのパスをこのパラメーターに返します。ファイルが見つからなかった場合、またはホストがファイル システム ベースでない場合、ホストは location を Empty に設定します。
戻り値
型: System.Boolean
ホストがテキストを取得できた場合は true。それ以外の場合は false。
解説
ユーザーがオプションの include ディレクティブをテキスト テンプレートで指定した場合、エンジンはこのメソッドを呼び出します。 このメソッドは、変換ごとに 0 回、1 回、または複数回呼び出すことができます。 詳細については、「T4 テキスト テンプレートのディレクティブ」を参照してください。
このメソッドは、カスタム ディレクティブ プロセッサからも呼び出すことができます。
例
カスタム ホストを実装するコード例を次に示します。 ここに示すコード例は、より長い例の一部です。 コード例全体については、「チュートリアル: カスタム テキスト テンプレート ホストの作成」を参照してください。
public bool LoadIncludeText(string requestFileName, out string content, out string location)
{
content = System.String.Empty;
location = System.String.Empty;
//If the argument is the fully qualified path of an existing file,
//then we are done.
//----------------------------------------------------------------
if (File.Exists(requestFileName))
{
content = File.ReadAllText(requestFileName);
return true;
}
//This can be customized to search specific paths for the file.
//This can be customized to accept paths to search as command line
//arguments.
//----------------------------------------------------------------
else
{
return false;
}
}
Public Function LoadIncludeText(ByVal requestFileName As String, ByRef content As String, ByRef location As String) As Boolean Implements ITextTemplatingEngineHost.LoadIncludeText
content = System.String.Empty
location = System.String.Empty
'If the argument is the fully qualified path of an existing file,
'then we are done.
'----------------------------------------------------------------
If File.Exists(requestFileName) Then
content = File.ReadAllText(requestFileName)
Return True
'This can be customized to search specific paths for the file.
'This can be customized to accept paths to search as command line
'arguments.
'----------------------------------------------------------------
Else
Return False
End If
End Function
.NET Framework セキュリティ
- 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。
参照
参照
ITextTemplatingEngineHost インターフェイス
Microsoft.VisualStudio.TextTemplating 名前空間