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)

判斷是否授與指定型別執行個體的授權。

適用於

另請參閱