ProvideLanguageCodeExpansionAttribute 类    
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注册对代码片段的语言服务支持。
public ref class ProvideLanguageCodeExpansionAttribute sealed : Microsoft::VisualStudio::Shell::RegistrationAttributepublic ref class ProvideLanguageCodeExpansionAttribute sealed : Microsoft::VisualStudio::Shell::RegistrationAttribute[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)]
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class ProvideLanguageCodeExpansionAttribute : Microsoft.VisualStudio.Shell.RegistrationAttribute[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=true, Inherited=true)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
type ProvideLanguageCodeExpansionAttribute = class
    inherit RegistrationAttributePublic NotInheritable Class ProvideLanguageCodeExpansionAttribute
Inherits RegistrationAttribute- 继承
- 属性
示例
此示例演示如何使用此用户定义属性来注册对语言服务代码片段的支持。
注意
Visual C# 通过删除名称的“Attribute”部分,允许用户定义属性的速记形式。 此速记形式用于本类和所有其他示例中。
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  
    {  
    }  
}  
注解
此用户定义的属性 (特定于 C#) ,用于提供向 Visual Studio 注册语言服务对代码片段的支持所需的信息。 此属性指定的值作为元数据存储在程序集中。 regpkg.exe 程序 (VSIP SDK) ) 等程序使用此元数据来创建相应的注册表项和条目,以告知 Visual Studio 语言服务。
受 影响的 ProvideLanguageCodeExpansionAttribute 注册表项位于以下注册表项下:
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]  
其中:
- [X.Y] 是 Visual Studio 的版本,例如 8.0Exp。 
- [language name] 是类构造函数) 的第二个参数 ProvideLanguageCodeExpansionAttribute 中指定的语言 (的名称。 
- [语言名称资源 ID] 是用于显示目的的语言名称的资源 ID,因此可以本地化。 
- [代码段索引文件的路径] 是描述代码段位置的索引文件的完整路径。 
- [语言标识符] 是用于标记所有代码段和代码段索引文件的字符串。 此字符串用于将一组代码片段与特定语言服务相关联。 
- [代码段的路径] 一个以分号分隔的路径列表,用于搜索代码段(如果索引文件不可用)。 
路径可以包含指向位置的替换变量,例如 Visual Studio 的已安装根目录和用户的“我的文档”位置。 有关这些替换变量的详细信息 ,请参阅支持旧语言服务中的代码片段 。
类构造函数指定所需的最小参数。 用户定义的属性类还支持可选的命名参数。 这些命名参数在构造函数的参数列表中指定为所需参数。 此类上支持 get 和 set 运算符的所有属性都可以指定为命名参数。 此示例演示如何使用命名参数。
以下用户定义的属性用于语言服务:
| Attribute | 说明 | 
|---|---|
| ProvideLanguageServiceAttribute | 将语言服务注册到 Visual Studio 并指定支持的功能。 | 
| ProvideLanguageExtensionAttribute | 将文件扩展名与语言服务相关联。 | 
| ProvideLanguageEditorOptionPageAttribute | 指定特定于语言服务的“选项”对话框的属性节点或页面。 | 
| ProvideLanguageCodeExpansionAttribute | 指定位置信息以支持语言服务中的代码片段。 | 
| ProvideServiceAttribute | 将语言服务注册为 Visual Studio 服务。 托管代码中提供的所有服务都使用此属性。 | 
继承者说明
此属性类无法继承自,因此无需实现任何内容。
调用方说明
此属性类通常应用于主 VSPackage 类,尽管它可以出现在任何类上。 此属性应仅出现一次。
构造函数
| ProvideLanguageCodeExpansionAttribute(Object, String, Int32, String, String) | 初始化 ProvideLanguageCodeExpansionAttribute 类的新实例。 | 
属性
| ForceCreateDirs | 获取或设置一个分号分隔的字符串,其中包含应创建的一个或多个目录。 | 
| LanguageName | 获取语言的名称。 | 
| LanguageServiceSid | 获取语言服务的 GUID。 | 
| SearchPaths | 获取或设置一个分号分隔的字符串,其中包含用于搜索代码段的默认路径。 | 
| ShowRoots | 获取或设置是否应显示代码片段的根。 | 
| TypeId | 重写 TypeID 属性,使 RegistrationAttribute 派生类能够与 System.ComponentModel.TypeDescriptor.GetAttributes 一起使用 (...) 。仅当派生自此属性的属性需要对可应用于类的实例使用更好的控件时,它才必须重写此属性。(继承自 RegistrationAttribute) | 
方法
| GetPackageRegKeyPath(Guid) | 获取相对于 VSPackage 的应用程序) 注册表根目录 (注册表路径。(继承自 RegistrationAttribute) | 
| Register(RegistrationAttribute+RegistrationContext) | 创建类构造函数指定的所有注册表项和条目。 | 
| Unregister(RegistrationAttribute+RegistrationContext) | 删除类构造函数指定的所有注册表项和条目。 |