Udostępnij za pośrednictwem


Metoda Colorizer.ColorizeLine —

Służy do uzyskiwania informacji o atrybut kolorów i czcionek dla każdego znaku w określonym wierszu tekstu.

Przestrzeń nazw:  Microsoft.VisualStudio.Package
Zestawy:   Microsoft.VisualStudio.Package.LanguageService.11.0 (w Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (w Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (w Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.9.0 (w Microsoft.VisualStudio.Package.LanguageService.9.0.dll)

Składnia

'Deklaracja
Public Overridable Function ColorizeLine ( _
    line As Integer, _
    length As Integer, _
    ptr As IntPtr, _
    state As Integer, _
    attrs As UInteger() _
) As Integer
public virtual int ColorizeLine(
    int line,
    int length,
    IntPtr ptr,
    int state,
    uint[] attrs
)

Parametry

  • line
    Typ: System.Int32
    [w] Numer wiersza, z którego wiersz tekstu pochodzi od.
  • length
    Typ: System.Int32
    [w] Liczba znaków w danym tekście.
  • ptr
    Typ: System.IntPtr
    [w] Wycofana wskaźnika do linii tekstu.
  • state
    Typ: System.Int32
    [w] Bieżący stan utrzymane przez parser.

Wartość zwracana

Typ: System.Int32
Zwraca wartość uaktualnione.

Implementuje

IVsColorizer.ColorizeLine(Int32, Int32, IntPtr, Int32, array<UInt32[])

Uwagi

Metoda ta analizuje wiersz i dostaw dla każdego znaku indeks do ColorableItem wykaz przewidzianych przez usługę języka (poprzez GetColorableItem).Zazwyczaj ta metoda wywołuje IScanner obiekt, aby przeanalizować linii w tokenach i zwraca indeks elementu colorable dla każdego tokenu.

Ta metoda jest implementacją ColorizeLine.

Metody podstawowej przetwarza token jeden cały wiersz w czasie, wywołując skanera ScanTokenAndProvideInfoAboutIt metody do czasu wyczerpania i wypełnia wiersza attrs tablicy dla każdej tokenu za pomocą zwrócony TokenInfo strukturę informacje o kolorach.

Przykłady

Oto jak pakiet zarządzanych wersji RAM Colorizer klasy implementuje tej metody.Uwaga Proces przekazywania międzyprocesowego tekstu na ciąg.

namespace Microsoft.VisualStudio.Package
{
    public class Colorizer : IVsColorizer
{
        IScanner scanner;

        public virtual int ColorizeLine(int line,
                                        int length,
                                        IntPtr ptr,
                                        int state,
                                        uint[] attrs)
        {
            int linepos = 0;
            if (this.scanner != null) {
                try
                {
                    string text = Marshal.PtrToStringUni(ptr, length);

                    this.scanner.SetSource(text, 0);

                    TokenInfo tokenInfo = new TokenInfo();

                    tokenInfo.EndIndex = -1;

                    while (this.scanner.ScanTokenAndProvideInfoAboutIt(tokenInfo, ref state))
                    {
                        if (attrs != null)
                        {
                            for (; linepos < tokenInfo.StartIndex; linepos++)
                                attrs[linepos] = (uint)TokenColor.Text;

                            for (; linepos <= tokenInfo.EndIndex; linepos++)
                                attrs[linepos] = (uint)tokenInfo.Color;
                        }
                    }
                }
                catch (Exception)
                {
                    // Ignore exceptions
                }
            }
            if (attrs != null)
            {
                // Must initialize the colors in all cases, otherwise you get 
                // random color junk on the screen.
                for (; linepos < length; linepos++)
                    attrs[linepos] = (uint)TokenColor.Text;
            }
            return state;
        }
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

Colorizer Klasa

Przestrzeń nazw Microsoft.VisualStudio.Package