LicenseProviderAttribute Kelas

Definisi

LicenseProvider Menentukan untuk digunakan dengan kelas . Kelas ini tidak dapat diwariskan.

public ref class LicenseProviderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class LicenseProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)>]
type LicenseProviderAttribute = class
    inherit Attribute
Public NotInheritable Class LicenseProviderAttribute
Inherits Attribute
Warisan
LicenseProviderAttribute
Atribut

Contoh

Contoh kode berikut menggunakan LicFileLicenseProvider sebagai penyedia lisensi untuk 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

Contoh kode berikutnya membuat instans MyControl kelas . Kemudian, ia mendapatkan atribut untuk kelas , dan mencetak nama penyedia lisensi yang digunakan oleh 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

Keterangan

Saat membuat komponen yang ingin Anda lisensikan, Anda harus menentukan LicenseProvider dengan menandai komponen dengan LicenseProviderAttribute.

LicenseProvider Gunakan properti untuk mendapatkan Type dari LicenseProvider.

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

Catatan

Atribut HostProtectionAttribute yang diterapkan ke kelas ini memiliki nilai properti berikut Resources : SharedState. HostProtectionAttribute tidak memengaruhi aplikasi desktop (yang biasanya dimulai dengan mengklik dua kali ikon, mengetik perintah, atau memasukkan URL di browser). Untuk informasi selengkapnya, lihat HostProtectionAttribute kelas atau SQL Server Atribut Pemrograman dan Perlindungan Host.

Konstruktor

LicenseProviderAttribute()

Menginisialisasi instans LicenseProviderAttribute baru kelas tanpa penyedia lisensi.

LicenseProviderAttribute(String)

Menginisialisasi instans LicenseProviderAttribute baru kelas dengan jenis yang ditentukan.

LicenseProviderAttribute(Type)

Menginisialisasi instans LicenseProviderAttribute baru kelas dengan jenis penyedia lisensi yang ditentukan.

Bidang

Default

Menentukan nilai default, yang bukan penyedia. Bidang ini static bersifat baca-saja.

Properti

LicenseProvider

Mendapatkan penyedia lisensi yang harus digunakan dengan kelas terkait.

TypeId

Menunjukkan ID unik untuk jenis atribut ini.

Metode

Equals(Object)

Menunjukkan apakah instans ini dan objek tertentu sama.

GetHashCode()

Mengembalikan kode hash untuk instans ini.

GetType()

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
IsDefaultAttribute()

Ketika ditimpa di kelas turunan, menunjukkan apakah nilai instans ini adalah nilai default untuk kelas turunan.

(Diperoleh dari Attribute)
Match(Object)

Saat ditimpa di kelas turunan, mengembalikan nilai yang menunjukkan apakah instans ini sama dengan objek tertentu.

(Diperoleh dari Attribute)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Implementasi Antarmuka Eksplisit

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

Memetakan sekumpulan nama ke sekumpulan pengidentifikasi pengiriman yang sesuai.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Mengambil informasi jenis untuk objek, yang dapat digunakan untuk mendapatkan informasi jenis untuk antarmuka.

(Diperoleh dari Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Mengambil jumlah antarmuka informasi jenis yang disediakan objek (baik 0 atau 1).

(Diperoleh dari Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Menyediakan akses ke properti dan metode yang diekspos oleh objek.

(Diperoleh dari Attribute)

Berlaku untuk

Lihat juga