LicenseProviderAttribute 类

指定要与类一起使用的 LicenseProvider。无法继承此类。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False, Inherited:=False)> _
Public NotInheritable Class LicenseProviderAttribute
    Inherits Attribute
用法
Dim instance As LicenseProviderAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=false)] 
public sealed class LicenseProviderAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=false, Inherited=false)] 
public ref class LicenseProviderAttribute sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=false) */ 
public final class LicenseProviderAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false, Inherited=false) 
public final class LicenseProviderAttribute extends Attribute

备注

当创建要授权的某组件时,必须通过用 LicenseProviderAttribute 标记该组件来指定 LicenseProvider

使用 LicenseProvider 属性获取 LicenseProviderType

有关属性的更多信息,请参见 属性 (Attribute) 概述利用属性扩展元数据。有关授权的更多信息,请参见 如何:授予组件和控件许可权限

提示

应用于此类的 HostProtectionAttribute 属性 (Attribute) 具有以下 Resources 属性 (Property) 值:SharedStateHostProtectionAttribute 不影响桌面应用程序(桌面应用程序一般通过双击图标,键入命令或在浏览器中输入 URL 启动)。有关更多信息,请参见 HostProtectionAttribute 类或 SQL Server 编程和宿主保护属性

示例

下面的代码示例将 LicFileLicenseProvider 用作 MyControl 的许可证提供程序。

<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
[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(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. */
   }
};
/** @attribute LicenseProvider(LicFileLicenseProvider.class)
 */
public class MyControl extends Control
{
    // Insert code here.
    protected void Dispose(boolean disposing)
    {
        /* All components must dispose of the licenses they grant.
           Insert code here to dispose of the license.
         */
    } //Dispose
} //MyControl
public LicenseProvider(LicFileLicenseProvider)
class MyControl extends Control{
    
    // Insert code here.
    function Dispose(){
        // All components must dispose of the licenses they grant.
        // Insert code here to dispose of the license.
    } //Dispose 
} //MyControl

下一个代码示例创建 MyControl 类的实例。然后,它获取该类的属性,并输出 myNewControl 所用许可证提供程序的名称。

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
public static int Main() {
    // Creates a new component.
    MyControl myNewControl = new 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 = (LicenseProviderAttribute)attributes[typeof(LicenseProviderAttribute)];
    Console.WriteLine("The license provider for this class is: " + myAttribute.LicenseProvider.ToString());
 
    return 0;
 }
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 void main(String[] args)
{
    // Creates a new component.
    Class1 lObjClass1 = new Class1();
    MyControl myNewControl = lObjClass1.new 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 = ((LicenseProviderAttribute)
        (attributes.get_Item(LicenseProviderAttribute.class.ToType())));

    Console.WriteLine(("The license provider for this class is: "
        + myAttribute.get_LicenseProvider().ToString()));
} //main
// Creates a new component.
var myNewControl : MyControl = new MyControl()

// Gets the attributes for the component.
var attributes : AttributeCollection = TypeDescriptor.GetAttributes(myNewControl)

// Prints the name of the license provider by retrieving the LicenseProviderAttribute 
// from the AttributeCollection. 
var myAttribute : LicenseProviderAttribute = LicenseProviderAttribute(attributes(LicenseProviderAttribute))
Console.WriteLine("The license provider for this class is: " + myAttribute.LicenseProvider.ToString())

继承层次结构

System.Object
   System.Attribute
    System.ComponentModel.LicenseProviderAttribute

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

LicenseProviderAttribute 成员
System.ComponentModel 命名空间
License 类
LicenseContext 类
LicenseException 类
LicenseManager 类
LicenseProvider 类
LicFileLicenseProvider
LicenseUsageMode