LicenseProviderAttribute 類別

定義

指定要與類別一起使用的 LicenseProviderSpecifies the LicenseProvider to use with a class. 這個類別無法被繼承。This class cannot be inherited.

public ref class LicenseProviderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class LicenseProviderAttribute : Attribute
type LicenseProviderAttribute = class
    inherit Attribute
Public NotInheritable Class LicenseProviderAttribute
Inherits Attribute
繼承
LicenseProviderAttribute
屬性

範例

下列程式碼範例會使用LicFileLicenseProvider做為的授權MyControl提供者。The following code example uses the LicFileLicenseProvider as the license provider for 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

下一個程式碼範例會建立MyControl類別的實例。The next code example creates an instance of the MyControl class. 然後, 它會取得類別的屬性, 並列印所使用myNewControl的授權提供者名稱。Then, it gets the attributes for the class, and prints the name of the license provider used by 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

備註

當您建立要授權的元件時, 您必須LicenseProvider LicenseProviderAttribute使用來標記元件來指定。When you create a component that you want to license, you must specify the LicenseProvider by marking the component with a LicenseProviderAttribute.

使用屬性, 即可Type取得LicenseProvider的。 LicenseProviderUse the LicenseProvider property to get the Type of the LicenseProvider.

如需屬性的詳細資訊,請參閱屬性For more information about attributes, see Attributes. 如需有關授權的詳細資訊, 請參閱如何:授權元件和控制項For more information about licensing, see How to: License Components and Controls.

注意

套用HostProtectionAttribute至這個類別的屬性具有下列Resources屬性值: SharedStateThe HostProtectionAttribute attribute applied to this class has the following Resources property value: SharedState. HostProtectionAttribute 不會影響桌面應用程式 (這些應用程式的啟動方式一般都是按兩下圖示、輸入命令或在瀏覽器輸入 URL)。The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). 如需詳細資訊, 請HostProtectionAttribute參閱類別或SQL Server 程式設計和主機保護屬性For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

建構函式

LicenseProviderAttribute()

不使用授權提供者來初始化 LicenseProviderAttribute 類別的新執行個體。Initializes a new instance of the LicenseProviderAttribute class without a license provider.

LicenseProviderAttribute(String)

使用指定的型別來初始化 LicenseProviderAttribute 類別的新執行個體。Initializes a new instance of the LicenseProviderAttribute class with the specified type.

LicenseProviderAttribute(Type)

使用授權提供者的指定型別來初始化 LicenseProviderAttribute 類別的新執行個體。Initializes a new instance of the LicenseProviderAttribute class with the specified type of license provider.

欄位

Default

指定預設值,也就是沒有提供者。Specifies the default value, which is no provider. 這個 static 欄位是唯讀的。This static field is read-only.

屬性

LicenseProvider

取得必須與關聯類別一起使用的授權提供者。Gets the license provider that must be used with the associated class.

TypeId

表示此屬性型別的唯一 ID。Indicates a unique ID for this attribute type.

方法

Equals(Object)

指示這個執行個體和指定的物件是否相等。Indicates whether this instance and a specified object are equal.

GetHashCode()

傳回這個執行個體的雜湊碼。Returns the hash code for this instance.

GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(繼承來源 Attribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。Retrieves the type information for an object, which can be used to get the type information for an interface.

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(繼承來源 Attribute)

適用於

另請參閱