スマート タグに関する情報を格納します。
名前空間: Microsoft.Office.Tools.Word
アセンブリ: Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll 内)
構文
'宣言
Sub PersistTag ( _
startIndex As Integer, _
length As Integer, _
propertyBag As ISmartTagProperties _
)
void PersistTag(
int startIndex,
int length,
ISmartTagProperties propertyBag
)
パラメーター
- startIndex
型: System.Int32
段落内でのスマート タグの開始位置。
- length
型: System.Int32
スマート タグの長さ。
- propertyBag
型: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
トークンのキーと値の組み合わせを格納しているプロパティ バッグ。nullnull 参照 (Visual Basic では Nothing) の場合があります。
例外
例外 | 条件 |
---|---|
InvalidOperationException | PersistTag が、Recognize メソッドから呼び出されませんでした。 |
解説
スマート タグがテキスト内で見つかったことを示すには、PersistTag を Recognize メソッドの実装から呼び出します。 スマート タグ用の任意のカスタム プロパティをコミットするには、propertyBag パラメーターを使用します。 これらのプロパティを使用すると、スマート タグのショートカット メニューで項目の 1 つを選択した場合のアクションをカスタマイズできます。
例
Recognize メソッドの実装から PersistTagを呼び出す方法を次のコード例に示します。 この実装では、各スマート タグ項目と段落の内容とを比較します。 このコードでは、段落内でスマート タグ項目が見つかると、カスタム スマート タグ プロパティを追加し、PersistTag メソッドを使用してスマート タグを認識します。 この例では、[参照の追加] ダイアログ ボックスの [.NET] タブで、Microsoft.Office.Interop.SmartTag への参照が追加してあると仮定しています。 このコード例は ISmartTagExtension インターフェイスのトピックで取り上げているコード例の一部分です。
Private Sub Recognize(ByVal text As String,
ByVal site As ISmartTagRecognizerSite,
ByVal tokenList As ISmartTagTokenList,
ByVal context As SmartTagRecognizeContext) Implements ISmartTagExtension.Recognize
For Each term As String In smartTagDemo.Terms
' Search the text for the current smart tag term.
Dim index As Integer = text.IndexOf(term, 0)
While (index >= 0)
' Create a smart tag token and a property bag for the recognized term.
Dim propertyBag As ISmartTagProperties = site.GetNewPropertyBag()
' Write a new property value.
Dim key As String = "Key1"
propertyBag.Write(key, DateTime.Now.ToString())
' Attach the smart tag to the term in the document
context.PersistTag(index, term.Length, propertyBag)
' Increment the index and then find the next instance of the smart tag term.
index += term.Length
index = text.IndexOf(term, index)
End While
Next
End Sub
void ISmartTagExtension.Recognize(string text, ISmartTagRecognizerSite site, ISmartTagTokenList tokenList,
SmartTagRecognizeContext context)
{
foreach (string term in smartTagDemo.Terms)
{
// Search the text for the current smart tag term.
int index = text.IndexOf(term, 0);
while (index >= 0)
{
// Create a smart tag token and a property bag for the recognized term.
ISmartTagProperties propertyBag = site.GetNewPropertyBag();
// Write a new property value.
string key = "Key1";
propertyBag.Write(key, DateTime.Now.ToString());
// Attach the smart tag to the term in the document
context.PersistTag(index, term.Length, propertyBag);
// Increment the index and then find the next instance of the smart tag term.
index += term.Length;
index = text.IndexOf(term, index);
}
}
}
.NET Framework セキュリティ
- 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。