LicenseProviderAttribute 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定要与类一起使用的 LicenseProvider。 此类不能被继承。
public ref class LicenseProviderAttribute sealed : Attribute[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class LicenseProviderAttribute : Attribute[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)>]
type LicenseProviderAttribute = class
    inherit AttributePublic NotInheritable Class LicenseProviderAttribute
Inherits Attribute- 继承
- 属性
示例
下面的代码示例使用 LicFileLicenseProvider 作为 的 MyControl许可证提供程序。
[LicenseProvider(LicFileLicenseProvider::typeid)]
ref class MyControl: public Control
{
protected:
   // Insert code here.
   ~MyControl()
   {
      /* All components must dispose of the licenses they grant. 
               * Insert code here to dispose of the license. */
   }
};
[LicenseProvider(typeof(LicFileLicenseProvider))]
public class MyControl : Control
{
    // Insert code here.
    protected override void Dispose(bool disposing)
    {
        /* All components must dispose of the licenses they grant. 
         * Insert code here to dispose of the license. */
    }
}
<LicenseProvider(GetType(LicFileLicenseProvider))> _
Public Class MyControl
    Inherits Control
    
    ' Insert code here.
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        ' All components must dispose of the licenses they grant.
        ' Insert code here to dispose of the license.
    End Sub        
End Class
下一个代码示例创建 类的 MyControl 实例。 然后,它获取 类的属性,并输出 所使用的 myNewControl许可证提供程序的名称。
int main()
{
   // Creates a new component.
   MyControl^ myNewControl = gcnew MyControl;
   // Gets the attributes for the component.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewControl );
   /* Prints the name of the license provider by retrieving the LicenseProviderAttribute 
        * from the AttributeCollection. */
   LicenseProviderAttribute^ myAttribute = dynamic_cast<LicenseProviderAttribute^>(attributes[ LicenseProviderAttribute::typeid ]);
   Console::WriteLine( "The license provider for this class is: {0}", myAttribute->LicenseProvider );
   return 0;
}
public static int Main()
{
    // Creates a new component.
    MyControl myNewControl = new();
    // Gets the attributes for the component.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl);
    /* Prints the name of the license provider by retrieving the LicenseProviderAttribute 
     * from the AttributeCollection. */
    LicenseProviderAttribute myAttribute = (LicenseProviderAttribute)attributes[typeof(LicenseProviderAttribute)];
    Console.WriteLine("The license provider for this class is: " + myAttribute.LicenseProvider.ToString());
    return 0;
}
Public Shared Function Main() As Integer
    ' Creates a new component.
    Dim myNewControl As New MyControl()
    
    ' Gets the attributes for the component.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewControl)
    
    ' Prints the name of the license provider by retrieving the LicenseProviderAttribute 
    ' from the AttributeCollection. 
    Dim myAttribute As LicenseProviderAttribute = _
        CType(attributes(GetType(LicenseProviderAttribute)), LicenseProviderAttribute)
        
    Console.WriteLine(("The license provider for this class is: " & _
        myAttribute.LicenseProvider.ToString()))
    Return 0
End Function
注解
创建想要许可的组件时,必须通过标记该组件LicenseProviderAttribute来指定 LicenseProvider 。
LicenseProvider使用 属性获取 Type 的 LicenseProvider。
有关属性的详细信息,请参阅属性。 有关许可的详细信息,请参阅 如何:许可组件和控件。
注意
HostProtectionAttribute应用于此类的属性具有以下Resources属性值:SharedState。 HostProtectionAttribute 不影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动这些应用程序)。 有关详细信息,请参阅 HostProtectionAttribute 类或 SQL Server 编程和主机保护属性。
构造函数
| LicenseProviderAttribute() | 在没有许可证提供程序的情况下,初始化 LicenseProviderAttribute 类的新实例。 | 
| LicenseProviderAttribute(String) | 使用指定的类型初始化 LicenseProviderAttribute 类的新实例。 | 
| LicenseProviderAttribute(Type) | 使用指定类型的许可证提供程序初始化 LicenseProviderAttribute 类的新实例。 | 
字段
| Default | 指定默认值,即无提供程序。 此  | 
属性
| LicenseProvider | 获取必须与该关联类一起使用的许可证提供程序。 | 
| TypeId | 指示此特性类型的唯一 ID。 | 
方法
| Equals(Object) | 指示此实例与指定对象是否相等。 | 
| GetHashCode() | 返回此实例的哈希代码。 | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| IsDefaultAttribute() | 在派生类中重写时,指示此实例的值是否是派生类的默认值。(继承自 Attribute) | 
| Match(Object) | 当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。(继承自 Attribute) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) | 
显式接口实现
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) | 将一组名称映射为对应的一组调度标识符。(继承自 Attribute) | 
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) | 检索对象的类型信息,然后可以使用该信息获取接口的类型信息。(继承自 Attribute) | 
| _Attribute.GetTypeInfoCount(UInt32) | 检索对象提供的类型信息接口的数量(0 或 1)。(继承自 Attribute) | 
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) | 提供对某一对象公开的属性和方法的访问。(继承自 Attribute) |