次の方法で共有


ProvideLanguageCodeExpansionAttribute Class

Registers language service support for code snippets.

Inheritance Hierarchy

System.Object
  System.Attribute
    Microsoft.VisualStudio.Shell.RegistrationAttribute
      Microsoft.VisualStudio.Shell.ProvideLanguageCodeExpansionAttribute

Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell.11.0 (in Microsoft.VisualStudio.Shell.11.0.dll)

Syntax

'宣言
<ComVisibleAttribute(False)> _
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class ProvideLanguageCodeExpansionAttribute _
    Inherits RegistrationAttribute
[ComVisibleAttribute(false)]
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public sealed class ProvideLanguageCodeExpansionAttribute : RegistrationAttribute

The ProvideLanguageCodeExpansionAttribute type exposes the following members.

Constructors

  Name Description
Public method ProvideLanguageCodeExpansionAttribute Initializes a new instance of the ProvideLanguageCodeExpansionAttribute class.

Top

Properties

  Name Description
Public property ForceCreateDirs Gets or sets a semicolon-delimited string containing the directory or directories that should be created.
Public property LanguageName Gets the name of the language.
Public property LanguageServiceSid Gets the GUID of the language service.
Public property SearchPaths Gets or sets a semicolon-delimited string containing the default paths to search for snippets.
Public property ShowRoots Gets or sets whether or not the roots of the code snippets should be shown.
Public property TypeId Gets the current instance of this attribute. (Inherited from RegistrationAttribute.)

Top

Methods

  Name Description
Public method Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Public method GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsDefaultAttribute When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Inherited from Attribute.)
Public method Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Public method Register Creates all of the registry keys and entries as specified by the class constructor. (Overrides RegistrationAttribute.Register(RegistrationAttribute.RegistrationContext).)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Unregister Removes all of the registry keys and entries as specified by the class constructor. (Overrides RegistrationAttribute.Unregister(RegistrationAttribute.RegistrationContext).)

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method _Attribute.GetIDsOfNames Maps a set of names to a corresponding set of dispatch identifiers. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfo Retrieves the type information for an object, which can be used to get the type information for an interface. (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.GetTypeInfoCount Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Inherited from Attribute.)
Explicit interface implemetationPrivate method _Attribute.Invoke Provides access to properties and methods exposed by an object. (Inherited from Attribute.)

Top

Remarks

This user-defined attribute (which is specific to C#) is used to provide information necessary to register a language service's support for code snippets with Visual Studio. The values specified by this attribute are stored as metadata in the assembly. This metadata is later used by a program such as regpkg.exe program (part of the VSIP SDK) to create the corresponding registry keys and entries that tell Visual Studio about the language service.

The registry entries affected by the ProvideLanguageCodeExpansionAttribute are found under the following registry key:

HKEY_LOCAL_MACHINE\
  SOFTWARE\
    Microsoft\
      VisualStudio\
        [X.Y]\
          Languages\
            CodeExpansions\
              [language name]\
                (Default)    = reg_sz: [Language Service GUID]
                DisplayName  = reg_sz: [language name resource ID]
                IndexPath    = reg_sz: [path to snippet index file]
                Package      = reg_sz: [Package GUID]
                LangStringID = reg_sz: [language identifier]
                Paths\
                  (Default)       = reg_sz:
                  [language name] = reg_sz: [paths to snippets]

Where:

  • [X.Y] is the version of Visual Studio, for example, 8.0Exp.

  • [language name] is the name of the language (as specified in the second parameter to the ProvideLanguageCodeExpansionAttribute class constructor).

  • [language name resource ID] is the resource ID of the language name that is used for display purposes and can therefore be localized.

  • [path to snippet index file] is the full path to the index file that describes the location of the snippets.

  • [language identifier] is a string used to mark all snippets and the snippets index file. This string is used to associate a set of snippets with a particular language service.

  • [paths to snippets] a semi-colon-delimited list of paths to search for snippets if the index file is not available.

The paths can contain substitution variables that point to locations such as the installed root for Visual Studio and the user's My Documents location. See Support for Code Snippets (Managed Package Framework) for details of these substitution variables.

The class constructor specifies the minimum required parameters. A user-defined attribute class also supports optional named parameters. These named parameters are specified in the constructor's parameter list after the required parameters. All of the properties on this class that support both get and set operators can be specified as a named parameter. The Example shows how named parameters are used.

The following user-defined attributes are used for language services:

Attribute

Description

ProvideLanguageServiceAttribute

Registers the language service with Visual Studio and specifies what features are supported.

ProvideLanguageExtensionAttribute

Associates a file extension with the language service.

ProvideLanguageEditorOptionPageAttribute

Specifies a property node or page for the Options dialog box specific to the language service.

ProvideLanguageCodeExpansionAttribute

Specifies location information to support code snippets in the language service.

ProvideServiceAttribute

Registers a language service as a Visual Studio service. All services supplied in managed code use this attribute.

Notes to Implementers

This attribute class cannot be inherited from so there is nothing to implement.

Notes to Callers

This attribute class is typically applied to your primary VSPackage class, although it can appear on any class. This attribute should appear only once.

Examples

This example shows how this user-defined attribute is used to register support for code snippets for a language service.

Note

Visual C# allows for a shorthand form of a user-defined attribute by dropping the "Attribute" part of the name. This shorthand form is used in this and all other examples throughout this class.

using Microsoft.VisualStudio.Shell;

namespace MyLanguagePackage
{
    internal class MyConstants
    {
        public const string languageName           = "MyLanguage";
        public const int    languageNameResourceID = 106;
        public const string languageIdentifier     = "mylanguage";
        public const string snippetsIndexFilePath   = @"%InstallRoot%\MyLanguage\SnippetsIndex.xml";
    }

    [ProvideCodeExpansion(typeof(MyLanguageService),
                            MyConstants.languageName,
                            MyConstants.languageNameResourceID,
                            MyConstants.languageIdentifier,
                            MyConstants.snippetsIndexFilePath,
        // Optional code expansion properties
        SearchPaths = @"%InstallRoot%\MyLanguage\Snippets\%LCID%\Snippets;" +
                      @"\%MyDocs%\Code Snippets\MyLanguage\My Code Snippets";
                         )]

    class MyLanguagePackage
    {
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.Shell Namespace

Other Resources

Support for Code Snippets (Managed Package Framework)