Export (0) Print
Expand All
Expand Minimize

LanguageService.GetLanguagePreferences Method

Returns a LanguagePreferences object for this language service.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)

public abstract LanguagePreferences GetLanguagePreferences()

Return Value

Type: Microsoft.VisualStudio.Package.LanguagePreferences
If successful, returns a LanguagePreferences object; otherwise, returns a null value.

This method must be implemented in a class derived from LanguageService. It is expected that you will have a single preferences object shared with all instances of your language service. If you do not need any custom preferences beyond those supplied by the LanguagePreferences class, you can just return an instance of the LanguagePreferences class.

This example shows an implementation of this method. Note how the matching braces option is temporarily enabled here (typically, this is set using the ProvideLanguageServiceAttribute user attribute when the language service is installed but for debugging purposes, it is often convenient to set or clear the various preference flags temporarily).

using Microsoft.VisualStudio.Package;

namespace MyLanguage
{
    class MyLanguageService : LanguageService
    {
        private LanguagePreferences preferences;

        public override LanguagePreferences GetLanguagePreferences()
        {
            if (this.preferences == null)
            {
                this.preferences = new LanguagePreferences(this.Site,
                                                            typeof(MyLanguageService).GUID,
                                                            this.Name);
                if (this.preferences != null)
                {
                    this.preferences.Init();  // Must do this first!

                    // Temporarily enable the following properties.
                    this.preferences.EnableMatchBraces = true;
                }
            }
            return this.preferences;

        } 
    }
}

Show:
© 2014 Microsoft