Skip to content

Class KernelMethodAttribute

Namespace: DotBoxD.Abstractions
Assembly: DotBoxD.Abstractions.dll

Marks a reusable helper method whose body the DotBoxD.Kernels generator inlines into the kernel/hook IR at every call site, so plugin authors can factor shared gate/handler logic out of a Where/Select/Run lambda (or a kernel-class ShouldHandle/Handle) without leaving the sandbox. The helper can be a static method, or an instance method called on the generated server-context parameter. For example:

server.Hooks.On<MonsterAggroEvent>()
    .Where((e, ctx) => IsBullying(e.MonsterLevel, e.PlayerLevel))
    .Run((e, ctx) => ctx.Messages.Send(e.MonsterId, "calm"));

[KernelMethod]
public static bool IsBullying(int monsterLevel, int playerLevel) => monsterLevel - playerLevel >= 3;

The call lowers exactly as if the body were written inline: each parameter is replaced by its already-lowered argument IR, and any [HostBinding] calls or [Capability]-gated reads inside the body contribute their capabilities to the calling kernel’s manifest.

Static helpers may be called through ordinary static-call syntax or extension-method syntax, and named arguments plus supported optional parameter defaults are bound before lowering.

Constraints (verified at generation time; a violation fails the chain/kernel safely rather than miscompiling): the method must be static or called on the server-context parameter, have an expression body or a single return statement, and use types the kernel marshaller can represent in the current lowering surface (scalars, supported nullable scalars, enums, GUIDs, records/DTOs, lists, and maps where that surface supports them). Recursion, generic helpers, ref/out/in parameters, and params arrays are not allowed.

[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public sealed class KernelMethodAttribute : Attribute

objectAttributeKernelMethodAttribute

Attribute.Equals(object?), Attribute.GetCustomAttribute(Assembly, Type), Attribute.GetCustomAttribute(Assembly, Type, bool), Attribute.GetCustomAttribute(MemberInfo, Type), Attribute.GetCustomAttribute(MemberInfo, Type, bool), Attribute.GetCustomAttribute(Module, Type), Attribute.GetCustomAttribute(Module, Type, bool), Attribute.GetCustomAttribute(ParameterInfo, Type), Attribute.GetCustomAttribute(ParameterInfo, Type, bool), Attribute.GetCustomAttributes(Assembly), Attribute.GetCustomAttributes(Assembly, bool), Attribute.GetCustomAttributes(Assembly, Type), Attribute.GetCustomAttributes(Assembly, Type, bool), Attribute.GetCustomAttributes(MemberInfo), Attribute.GetCustomAttributes(MemberInfo, bool), Attribute.GetCustomAttributes(MemberInfo, Type), Attribute.GetCustomAttributes(MemberInfo, Type, bool), Attribute.GetCustomAttributes(Module), Attribute.GetCustomAttributes(Module, bool), Attribute.GetCustomAttributes(Module, Type), Attribute.GetCustomAttributes(Module, Type, bool), Attribute.GetCustomAttributes(ParameterInfo), Attribute.GetCustomAttributes(ParameterInfo, bool), Attribute.GetCustomAttributes(ParameterInfo, Type), Attribute.GetCustomAttributes(ParameterInfo, Type, bool), Attribute.GetHashCode(), Attribute.IsDefaultAttribute(), Attribute.IsDefined(Assembly, Type), Attribute.IsDefined(Assembly, Type, bool), Attribute.IsDefined(MemberInfo, Type), Attribute.IsDefined(MemberInfo, Type, bool), Attribute.IsDefined(Module, Type), Attribute.IsDefined(Module, Type, bool), Attribute.IsDefined(ParameterInfo, Type), Attribute.IsDefined(ParameterInfo, Type, bool), Attribute.Match(object?), Attribute.TypeId, object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()