LicenseProviderAttribute 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定要與類別搭配使用的 LicenseProvider。 無法繼承這個類別。
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
- 繼承
- 屬性
範例
以下程式碼範例使用 作為LicFileLicenseProvider授權提供者。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 類別的實例。 接著,它取得類別的屬性,並列印出所 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
備註
當你建立想要授權的元件時,必須用 . 來指定LicenseProvider元件。LicenseProviderAttribute
利用該LicenseProvider性質取得 Type 。LicenseProvider
如需屬性的詳細資訊,請參閱 屬性。 欲了解更多授權資訊,請參閱 如何授權元件與控制項。
備註
HostProtectionAttribute套用於此類別的屬性具有以下Resources屬性值: SharedState。 這 HostProtectionAttribute 不會影響桌面應用程式(通常透過雙擊圖示、輸入指令或在瀏覽器輸入網址來啟動)。 欲了解更多資訊,請參閱 HostProtectionAttribute 類別或 SQL Server 程式設計與主機保護屬性。
建構函式
| 名稱 | Description |
|---|---|
| LicenseProviderAttribute() |
初始化該類別的新實例 LicenseProviderAttribute ,且不使用授權提供者。 |
| LicenseProviderAttribute(String) |
初始化一個以指定型別的新 LicenseProviderAttribute 類別實例。 |
| LicenseProviderAttribute(Type) |
初始化該類別的新實例 LicenseProviderAttribute ,並使用指定類型的授權提供者。 |
欄位
| 名稱 | Description |
|---|---|
| Default |
指定預設值,即無提供者。 此 |
屬性
| 名稱 | Description |
|---|---|
| LicenseProvider |
取得必須與相關類別一起使用的授權提供者。 |
| TypeId |
表示此屬性類型的唯一 ID。 |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
指出這個實例和指定的物件是否相等。 |
| GetHashCode() |
傳回這個實例的哈希碼。 |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| IsDefaultAttribute() |
在衍生類別中覆寫時,指出這個實例的值是否為衍生類別的預設值。 (繼承來源 Attribute) |
| Match(Object) |
在衍生類別中覆寫時,傳回值,指出這個實例是否等於指定的物件。 (繼承來源 Attribute) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |
明確介面實作
| 名稱 | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
擷取 物件的型別資訊,可用來取得介面的類型資訊。 (繼承來源 Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
擷取物件提供的類型資訊介面數目 (0 或 1)。 (繼承來源 Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
提供物件所公開屬性和方法的存取權。 (繼承來源 Attribute) |