Adding OpCodes Handlers From User Code.
CursedLand opened this issue · 2 comments
CursedLand commented
Make External Implemention ICilOpCodeHandler
In User Code To Add His Own OpCode Support. :)
Washi1337 commented
This is already possible, by configuring the CilDispatcher
of the CilVirtualMachine
.
Below an example on how to override the behaviour of the add
opcode.
public class MyOpCodeHandler : ICilOpCodeHandler
{
public IReadOnlyCollection<CilCode> SupportedOpCodes => new[] { CilCode.Add };
public DispatchResult Execute(CilExecutionContext context, CilInstruction instruction)
{
// ...
}
}
var dispatcher = new CilDispatcher();
dispatcher.DispatcherTable[CilCode.Add] = new MyOpCodeHandler();
vm.Dispatcher = dispatcher;
CursedLand commented
Nice, Thanks.