LicenseManager 类

定义

提供属性和方法,用以将许可证添加到组件和管理 LicenseProvider。 此类不能被继承。

public ref class LicenseManager sealed
public sealed class LicenseManager
type LicenseManager = class
Public NotInheritable Class LicenseManager
继承
LicenseManager

示例

下面的代码示例使用 Validate 方法创建许可控件。 它使用 LicenseProvider 由 类实现的 LicFileLicenseProvider

// Adds the LicenseProviderAttribute to the control.

[LicenseProvider(LicFileLicenseProvider::typeid)]
public ref class MyControl: public Control
{
   // Creates a new, null license.
private:
   License^ license;

public:
   MyControl()
   {
      
      // Adds Validate to the control's constructor.
      license = LicenseManager::Validate( MyControl::typeid, this );

      // Insert code to perform other instance creation tasks here.
   }

public:
   ~MyControl()
   {
      if ( license != nullptr )
      {
         delete license;
         license = nullptr;
      }
   }
};
using System;
using System.ComponentModel;
using System.Windows.Forms;

// Adds the LicenseProviderAttribute to the control.
[LicenseProvider(typeof(LicFileLicenseProvider))]
public class MyControl : Control 
{
 
   // Creates a new, null license.
   private License license = null;
 
   public MyControl () 
   {
 
      // Adds Validate to the control's constructor.
      license = LicenseManager.Validate(typeof(MyControl), this);
 
      // Insert code to perform other instance creation tasks here.
   }
 
   protected override void Dispose(bool disposing) 
   {
      if(disposing)
      {
         if (license != null) 
         {
            license.Dispose();
            license = null;
         }
      }
   }
}
Imports System.ComponentModel
Imports System.Windows.Forms

' Adds the LicenseProviderAttribute to the control.
<LicenseProvider(GetType(LicFileLicenseProvider))> _
Public Class MyControl
    Inherits Control
    
    ' Creates a new, null license.
    Private license As License = Nothing    
    
    Public Sub New()        
    
        ' Adds Validate to the control's constructor.
        license = LicenseManager.Validate(GetType(MyControl), Me)

        ' Insert code to perform other instance creation tasks here.
        
    End Sub
    
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        If disposing Then
            If (license IsNot Nothing) Then
                license.Dispose()
                license = Nothing
            End If
        End If

    End Sub    
    
End Class

注解

LicenseManager 提供以下 static 属性: CurrentContextUsageMode。 类还提供以下 static 方法: CreateWithContextIsValidValidate

创建要许可的组件时,必须执行以下操作:

  1. LicenseProvider通过使用 标记组件LicenseProviderAttribute来指定 。

  2. 在组件的构造函数中调用 ValidateIsValidValidateLicenseException尝试在没有有效许可证的情况下创建实例时引发 。 IsValid 不会引发异常。

  3. 调用 Dispose 在释放或完成组件时授予的任何许可证。

有关许可的详细信息,请参阅 如何:许可组件和控制

属性

CurrentContext

获取或设置当前的 LicenseContext,它指定您何时可以使用已授权的对象。

UsageMode

获取 LicenseUsageMode,它指定何时可以使用 CurrentContext 的已授权对象。

方法

CreateWithContext(Type, LicenseContext)

根据可在其中使用已授权实例的上下文,创建指定类型的实例。

CreateWithContext(Type, LicenseContext, Object[])

根据可在其中使用已授权实例的上下文,用指定的参数创建指定类型的实例。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IsLicensed(Type)

返回给定的类型是否具有有效许可证。

IsValid(Type)

确定是否可以为指定类型授予有效的许可证。

IsValid(Type, Object, License)

确定是否可以为该类型的指定实例授予有效的许可证。 该方法创建有效的 License

LockContext(Object)

防止对给定对象当前的 LicenseContext 进行更改。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)
UnlockContext(Object)

允许对给定对象当前的 LicenseContext 进行更改。

Validate(Type)

确定是否可以为指定类型授予许可证。

Validate(Type, Object)

确定是否可以为指定类型的实例授予许可证。

适用于

另请参阅