LicenseProviderAttribute Klass

Definition

Anger vilken som LicenseProvider ska användas med en klass. Det går inte att ärva den här klassen.

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
Arv
LicenseProviderAttribute
Attribut

Exempel

I följande kodexempel används LicFileLicenseProvider som licensprovider för 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

I nästa kodexempel skapas en instans av MyControl klassen. Sedan hämtar den attributen för klassen och skriver ut namnet på den licensprovider som används av 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();

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

Kommentarer

När du skapar en komponent som du vill licensiera måste du ange LicenseProvider genom att markera komponenten med en LicenseProviderAttribute.

Använd egenskapen LicenseProvider för att hämta Type .LicenseProvider

Mer information om attribut finns i Attribut. Mer information om licensiering finns i Så här: Licenskomponenter och kontroller.

Note

Attributet HostProtectionAttribute som tillämpas på den här klassen har följande Resources egenskapsvärde: SharedState. Påverkar HostProtectionAttribute inte skrivbordsprogram (som vanligtvis startas genom att dubbelklicka på en ikon, skriva ett kommando eller ange en URL i en webbläsare). Mer information finns i klassen HostProtectionAttribute eller SQL Server Programming and Host Protection Attributes.

Konstruktorer

Name Description
LicenseProviderAttribute()

Initierar en ny instans av LicenseProviderAttribute klassen utan en licensprovider.

LicenseProviderAttribute(String)

Initierar en ny instans av LicenseProviderAttribute klassen med den angivna typen.

LicenseProviderAttribute(Type)

Initierar en ny instans av LicenseProviderAttribute klassen med den angivna typen av licensprovider.

Fält

Name Description
Default

Anger standardvärdet, som inte är någon provider. Det här static fältet är skrivskyddat.

Egenskaper

Name Description
LicenseProvider

Hämtar den licensprovider som måste användas med den associerade klassen.

TypeId

Anger ett unikt ID för den här attributtypen.

Metoder

Name Description
Equals(Object)

Anger om den här instansen och ett angivet objekt är lika.

GetHashCode()

Returnerar hash-koden för den här instansen.

GetType()

Hämtar den aktuella instansen Type .

(Ärvd från Object)
IsDefaultAttribute()

När den åsidosättas i en härledd klass anger du om värdet för den här instansen är standardvärdet för den härledda klassen.

(Ärvd från Attribute)
Match(Object)

När den åsidosätts i en härledd klass returneras ett värde som anger om den här instansen är lika med ett angivet objekt.

(Ärvd från Attribute)
MemberwiseClone()

Skapar en ytlig kopia av den aktuella Object.

(Ärvd från Object)
ToString()

Returnerar en sträng som representerar det aktuella objektet.

(Ärvd från Object)

Explicita gränssnittsimplementeringar

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

Mappar en uppsättning namn till en motsvarande uppsättning av sändningsidentifierare.

(Ärvd från Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Hämtar typinformationen för ett objekt, som kan användas för att hämta typinformationen för ett gränssnitt.

(Ärvd från Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Hämtar antalet typinformationsgränssnitt som ett objekt tillhandahåller (antingen 0 eller 1).

(Ärvd från Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Ger åtkomst till egenskaper och metoder som exponeras av ett objekt.

(Ärvd från Attribute)

Gäller för

Se även