Share via


LicenseManager Kelas

Definisi

Menyediakan properti dan metode untuk menambahkan lisensi ke komponen dan untuk mengelola LicenseProvider. Kelas ini tidak dapat diwariskan.

public ref class LicenseManager sealed
public sealed class LicenseManager
type LicenseManager = class
Public NotInheritable Class LicenseManager
Warisan
LicenseManager

Contoh

Contoh kode berikut membuat kontrol berlisensi menggunakan Validate metode . Ini menggunakan LicenseProvider yang diimplementasikan oleh LicFileLicenseProvider kelas .

// 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

Keterangan

Kelas ini LicenseManager menyediakan properti berikut static : CurrentContext dan UsageMode. Kelas ini juga menyediakan metode berikut static : CreateWithContext, , IsValiddan Validate.

Saat membuat komponen yang ingin Anda lisensikan, Anda harus melakukan hal berikut:

  1. LicenseProvider Tentukan dengan menandai komponen dengan LicenseProviderAttribute.

  2. Panggil Validate atau IsValid di konstruktor komponen. Validate melempar saat mencoba membuat instans LicenseException tanpa lisensi yang valid. IsValid tidak melemparkan pengecualian.

  3. Panggil Dispose lisensi apa pun yang diberikan saat komponen dibuang atau diselesaikan.

Untuk informasi selengkapnya tentang lisensi, lihat Cara: Komponen dan Kontrol Lisensi.

Properti

CurrentContext

Mendapatkan atau mengatur saat ini LicenseContext, yang menentukan kapan Anda dapat menggunakan objek berlisensi.

UsageMode

Mendapatkan yang menentukan kapan Anda dapat menggunakan objek berlisensi LicenseUsageMode untuk CurrentContext.

Metode

CreateWithContext(Type, LicenseContext)

Membuat instans dari jenis yang ditentukan, dengan konteks di mana Anda dapat menggunakan instans berlisensi.

CreateWithContext(Type, LicenseContext, Object[])

Membuat instans dari jenis yang ditentukan dengan argumen yang ditentukan, mengingat konteks di mana Anda dapat menggunakan instans berlisensi.

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan instans Type saat ini.

(Diperoleh dari Object)
IsLicensed(Type)

Mengembalikan apakah jenis yang diberikan memiliki lisensi yang valid.

IsValid(Type)

Menentukan apakah lisensi yang valid dapat diberikan untuk jenis yang ditentukan.

IsValid(Type, Object, License)

Menentukan apakah lisensi yang valid dapat diberikan untuk instans jenis yang ditentukan. Metode ini membuat License.

LockContext(Object)

Mencegah perubahan yang dilakukan pada objek yang diberikan saat ini LicenseContext .

MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)
UnlockContext(Object)

Memungkinkan perubahan dilakukan pada objek yang diberikan saat ini LicenseContext .

Validate(Type)

Menentukan apakah lisensi dapat diberikan untuk jenis yang ditentukan.

Validate(Type, Object)

Menentukan apakah lisensi dapat diberikan untuk instans jenis yang ditentukan.

Berlaku untuk

Lihat juga