LicenseManager 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供属性和方法,用于将许可证添加到组件和管理 LicenseProvider。 无法继承此类。
public ref class LicenseManager sealed
public sealed class LicenseManager
type LicenseManager = class
Public NotInheritable Class LicenseManager
- 继承
-
LicenseManager
示例
下面的代码示例使用 Validate 该方法创建许可的控件。 它使用由类实现的LicFileLicenseProvider一个LicenseProvider。
// 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.ComponentModel;
using System.Windows.Forms;
// Adds the LicenseProviderAttribute to the control.
[LicenseProvider(typeof(LicFileLicenseProvider))]
public class MyControl : Control
{
// Creates a new, null license.
License license;
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
注解
该 LicenseManager 类提供以下 static 属性: CurrentContext 和 UsageMode。 该类还提供以下static方法:CreateWithContext和IsValidValidate。
创建想要许可的组件时,必须执行以下操作:
使用 LicenseProvider .. 标记组件 LicenseProviderAttribute来指定
调用 Validate 或 IsValid 调用组件的构造函数。 Validate LicenseException在尝试创建没有有效许可证的实例时引发 a。 IsValid 不会引发异常。
调用 Dispose 释放或终结组件时授予的任何许可证。
属性
| 名称 | 说明 |
|---|---|
| CurrentContext |
获取或设置当前 LicenseContext值,它指定何时可以使用许可对象。 |
| UsageMode |
获取指定LicenseUsageMode何时可以使用许可对象。CurrentContext |
方法
| 名称 | 说明 |
|---|---|
| CreateWithContext(Type, LicenseContext, Object[]) |
使用指定参数创建指定类型的实例,给定一个上下文,可在该上下文中使用许可实例。 |
| CreateWithContext(Type, LicenseContext) |
创建指定类型的实例,给定一个上下文,可在该上下文中使用许可实例。 |
| Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| IsLicensed(Type) |
返回给定类型是否具有有效的许可证。 |
| IsValid(Type, Object, License) |
确定是否可以为类型的指定实例授予有效的许可证。 此方法创建有效的 License。 |
| IsValid(Type) |
确定是否可以为指定类型授予有效的许可证。 |
| LockContext(Object) |
防止对给定对象的当前 LicenseContext 对象进行更改。 |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |
| UnlockContext(Object) |
允许对给定对象的当前 LicenseContext 对象进行更改。 |
| Validate(Type, Object) |
确定是否可以为指定类型的实例授予许可证。 |
| Validate(Type) |
确定是否可以为指定类型授予许可证。 |