通过


LicenseProviderAttribute 类

定义

指定要用于类的 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 Attribute
Public NotInheritable Class LicenseProviderAttribute
Inherits Attribute
继承
LicenseProviderAttribute
属性

示例

下面的代码示例使用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

有关属性的详细信息,请参阅 “属性”。 有关许可的详细信息,请参阅 How to: License Components and Controls

注释

HostProtectionAttribute应用于此类的属性具有以下Resources属性值: SharedStateHostProtectionAttribute 不会影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动)。 有关详细信息,请参阅 HostProtectionAttribute 类或 SQL Server 编程和主机保护属性

构造函数

名称 说明
LicenseProviderAttribute()

初始化没有许可证提供程序的 LicenseProviderAttribute 类的新实例。

LicenseProviderAttribute(String)

使用指定类型初始化类的新实例 LicenseProviderAttribute

LicenseProviderAttribute(Type)

使用指定类型的许可证提供程序初始化类的新实例 LicenseProviderAttribute

字段

名称 说明
Default

指定默认值,该值不为提供程序。 此 static 字段为只读。

属性

名称 说明
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)

适用于

另请参阅