LicenseManager 类

定义

提供属性和方法,用以将许可证添加到组件和管理 LicenseProviderProvides properties and methods to add a license to a component and to manage a LicenseProvider. 无法继承此类。This class cannot be inherited.

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

示例

下面的代码示例使用 Validate 方法创建授权控件。The following code example creates a licensed control using the Validate method. 它使用由 LicFileLicenseProvider 类实现的 LicenseProviderIt uses a LicenseProvider that is implemented by the LicFileLicenseProvider class.

// 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 属性: CurrentContextUsageModeThe LicenseManager class provides the following static properties: CurrentContext and UsageMode. 类还提供以下 static 方法: CreateWithContextIsValidValidateThe class also provides the following static methods: CreateWithContext, IsValid, and Validate.

创建要许可的组件时,必须执行以下操作:When you create a component that you want to license, you must do the following:

  1. 通过使用 LicenseProviderAttribute标记组件来指定 LicenseProviderSpecify the LicenseProvider by marking the component with a LicenseProviderAttribute.

  2. 在组件的构造函数中调用 ValidateIsValidCall Validate or IsValid in the constructor of the component. Validate 在尝试创建没有有效许可证的实例时引发 LicenseExceptionValidate throws a LicenseException when it tries to create an instance without a valid license. IsValid 不会引发异常。IsValid does not throw an exception.

  3. 在释放或完成组件时授予的任何许可证上调用 DisposeCall Dispose on any license that is granted when the component is disposed or finalized.

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

属性

CurrentContext

获取或设置当前的 LicenseContext,它指定您何时可以使用已授权的对象。Gets or sets the current LicenseContext, which specifies when you can use the licensed object.

UsageMode

获取 LicenseUsageMode,它指定何时可以使用 CurrentContext 的已授权对象。Gets the LicenseUsageMode which specifies when you can use the licensed object for the CurrentContext.

方法

CreateWithContext(Type, LicenseContext)

根据可在其中使用已授权实例的上下文,创建指定类型的实例。Creates an instance of the specified type, given a context in which you can use the licensed instance.

CreateWithContext(Type, LicenseContext, Object[])

根据可在其中使用已授权实例的上下文,用指定的参数创建指定类型的实例。Creates an instance of the specified type with the specified arguments, given a context in which you can use the licensed instance.

Equals(Object)

确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

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

(继承自 Object)
IsLicensed(Type)

返回给定的类型是否具有有效许可证。Returns whether the given type has a valid license.

IsValid(Type)

确定是否可以为指定类型授予有效的许可证。Determines whether a valid license can be granted for the specified type.

IsValid(Type, Object, License)

确定是否可以为该类型的指定实例授予有效的许可证。Determines whether a valid license can be granted for the specified instance of the type. 该方法创建有效的 LicenseThis method creates a valid License.

LockContext(Object)

防止对给定对象当前的 LicenseContext 进行更改。Prevents changes being made to the current LicenseContext of the given object.

MemberwiseClone()

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

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
UnlockContext(Object)

允许对给定对象当前的 LicenseContext 进行更改。Allows changes to be made to the current LicenseContext of the given object.

Validate(Type)

确定是否可以为指定类型授予许可证。Determines whether a license can be granted for the specified type.

Validate(Type, Object)

确定是否可以为指定类型的实例授予许可证。Determines whether a license can be granted for the instance of the specified type.

适用于

另请参阅