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
- Inheritance
-
KernelMethodAttribute
- Inherited Members