LicenseProviderAttribute 类

定义

指定要与类一起使用的 LicenseProviderSpecifies the LicenseProvider to use with a class. 此类不能被继承。This class cannot be inherited.

public ref class LicenseProviderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class LicenseProviderAttribute : Attribute
type LicenseProviderAttribute = class
    inherit Attribute
Public NotInheritable Class LicenseProviderAttribute
Inherits Attribute
继承
LicenseProviderAttribute
属性

示例

下面的代码示例使用LicFileLicenseProvider作为的许可证MyControl提供程序。The following code example uses the LicFileLicenseProvider as the license provider for 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类的一个实例。The next code example creates an instance of the MyControl class. 然后, 它获取类的属性, 并输出使用myNewControl的许可证提供程序的名称。Then, it gets the attributes for the class, and prints the name of the license provider used by 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 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;
 }
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

注解

创建要许可的组件时, 必须LicenseProvider通过LicenseProviderAttribute使用标记组件来指定。When you create a component that you want to license, you must specify the LicenseProvider by marking the component with a LicenseProviderAttribute.

使用属性可Type获取的LicenseProviderLicenseProviderUse the LicenseProvider property to get the Type of the LicenseProvider.

有关属性的详细信息,请参阅属性For more information about attributes, see Attributes. 有关授权的详细信息, 请参阅如何:许可证组件和控件For more information about licensing, see How to: License Components and Controls.

备注

应用于此类的Resources SharedState特性具有以下属性值:。 HostProtectionAttributeThe HostProtectionAttribute attribute applied to this class has the following Resources property value: SharedState. HostProtectionAttribute 不影响桌面应用程序(通常通过双击图标、键入命令或在浏览器中输入 URL 来启动这些应用程序)。The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). 有关详细信息, 请参阅HostProtectionAttribute类或SQL Server 编程和宿主保护特性For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

构造函数

LicenseProviderAttribute()

在没有许可证提供程序的情况下,初始化 LicenseProviderAttribute 类的新实例。Initializes a new instance of the LicenseProviderAttribute class without a license provider.

LicenseProviderAttribute(String)

使用指定的类型初始化 LicenseProviderAttribute 类的新实例。Initializes a new instance of the LicenseProviderAttribute class with the specified type.

LicenseProviderAttribute(Type)

使用指定类型的许可证提供程序初始化 LicenseProviderAttribute 类的新实例。Initializes a new instance of the LicenseProviderAttribute class with the specified type of license provider.

字段

Default

指定默认值,即无提供程序。Specifies the default value, which is no provider. static 字段是只读的。This static field is read-only.

属性

LicenseProvider

获取必须与该关联类一起使用的许可证提供程序。Gets the license provider that must be used with the associated class.

TypeId

指示此特性类型的唯一 ID。Indicates a unique ID for this attribute type.

方法

Equals(Object)

指示此实例与指定对象是否相等。Indicates whether this instance and a specified object are equal.

GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

在派生类中重写时,指示此实例的值是否是派生类的默认值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(继承自 Attribute)
Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅