SmartTagRecognizeContext.PersistTag (Método)

Almacena información sobre la etiqueta inteligente.

Espacio de nombres:  Microsoft.Office.Tools.Word
Ensamblado:  Microsoft.Office.Tools.Word (en Microsoft.Office.Tools.Word.dll)

Sintaxis

'Declaración
Sub PersistTag ( _
    startIndex As Integer, _
    length As Integer, _
    propertyBag As ISmartTagProperties _
)
void PersistTag(
    int startIndex,
    int length,
    ISmartTagProperties propertyBag
)

Parámetros

  • startIndex
    Tipo: System.Int32
    Posición del párrafo donde comienza la etiqueta inteligente.
  • length
    Tipo: System.Int32
    Longitud de la etiqueta inteligente.
  • propertyBag
    Tipo: Microsoft.Office.Interop.SmartTag.ISmartTagProperties
    Bolsa de propiedades que contiene pares de clave y valor para el símbolo (token).Puede ser nullreferencia null (Nothing en Visual Basic).

Excepciones

Excepción Condición
InvalidOperationException

No se llamó a PersistTag desde el método Recognize.

Comentarios

Llame a PersistTag desde una implementación del método Recognize para indicar que la etiqueta inteligente se encontró en el texto. Utilice el parámetro propertyBag para confirmar cualquier propiedad personalizada para la etiqueta inteligente. Puede utilizar estas propiedades para personalizar la acción tomada cuando un elemento del menú contextual de la etiqueta inteligente está seleccionado.

Ejemplos

En el ejemplo de código siguiente se muestra cómo llamar a PersistTag desde una implementación del método Recognize. Esta implementación compara cada término de la etiqueta inteligente con el contenido del párrafo. Para cada término de etiqueta inteligente del párrafo, el código agrega una propiedad de etiqueta inteligente personalizada y, a continuación, utiliza el método PersistTag para reconocer la etiqueta inteligente. En este ejemplo se supone que se ha agregado una referencia a Microsoft.Office.Interop.SmartTag desde la pestaña .NET del cuadro de diálogo Agregar referencia. Este ejemplo de código forma parte de un ejemplo más extenso relativo a la interfaz 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);
        }
    }
}

Seguridad de .NET Framework

Vea también

Referencia

SmartTagRecognizeContext Interfaz

Microsoft.Office.Tools.Word (Espacio de nombres)