Table of Contents

Class PreconditionAttribute

Namespace
HeyBox.Interactions
Assembly
HeyBox.Net.Interactions.dll

要求模块或类在执行前满足指定的先决条件。

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public abstract class PreconditionAttribute : Attribute
Inheritance
PreconditionAttribute
Derived
Inherited Members

Properties

ErrorMessage

获取如果执行上下文未通过先决条件检查时返回的错误消息。

public virtual string? ErrorMessage { get; }

Property Value

string

Remarks

在派生类中重写时,如果先决条件未通过,将使用提供的字符串作为错误消息。 对于未重写此属性的类,设置该属性无效。

Group

获取此先决条件所属的分组。

public string? Group { get; set; }

Property Value

string

Remarks

HeyBox.Preconditions 中同一分组的先决条件只需满足其中一个即可视为成功(A || B)。 未指定 Group 或为 null 时,需全部满足(A && B)。

Methods

CheckRequirementsAsync(IInteractionContext, ICommandInfo, IServiceProvider?)

检查 commandInfo 所代表的命令是否满足先决条件。

public abstract Task<PreconditionResult> CheckRequirementsAsync(IInteractionContext context, ICommandInfo commandInfo, IServiceProvider? services)

Parameters

context IInteractionContext

命令的上下文。

commandInfo ICommandInfo

被执行的命令。

services IServiceProvider

用于依赖注入的服务集合。

Returns

Task<PreconditionResult>

See Also