Class ProgramInvocation
One call of a procedure of a composed program, by name, with its arguments; and, in the same run, the calls that make the values it needs (Calls), the guards that may answer for it (Guards), the factory that makes the object it runs on (Factory), the hooks of that object (BeforeProcedure, OnError), and the calls that turn its value into the invocation's (ResultCalls).
public sealed record ProgramInvocation : IEquatable<ProgramInvocation>
- Inheritance
-
ProgramInvocation
- Implements
- Inherited Members
Remarks
A machine matches each argument to the parameter of that name as RD-VBA compares names (case-insensitively), whatever the comparer of Arguments, and converts its value to the parameter's declared type. Each of these ends the invocation with a run-time error (RuntimeError) before the procedure runs, as MS-VBAL §5.3.1.11 maps named arguments:
- an argument that names no parameter, or two that name the same one (in different cases, or one in Arguments and one in ProcedureArguments), is error 448 (Named argument not found);
- a parameter with no argument that is not
Optionalis error 449 (Argument not optional); - a value that does not convert is error 13 (Type mismatch).
A procedure of a class whose VB_PredeclaredId is True runs on the class's default instance (MS-VBAL §5.2.4.1.2), the
program's own: the first reference to it, from the program or from an invocation, makes it, and its Class_Initialize runs then. It keeps its
state from one invocation to the next, and no invocation terminates it. A Set of it to Nothing lets go of it, and so does
ResetAsync(CancellationToken); the next reference makes another.
A procedure of any other class module runs on a new object of the class, made for the invocation as New makes one
(MS-VBAL §5.6.8). Its Class_Initialize runs before the procedure, and its Class_Terminate once the run has its value,
before the invocation ends (MS-VBAL §5.3.1.10). An error that the procedure leaves unhandled, or an End, ends the run, and the
run's end lets go of the object.
An error that Class_Initialize leaves unhandled ends the invocation with that run-time error, and the procedure does not run. An argument named
Me names no parameter. A document module is not invoked: its object is its host's document.
The whole invocation is one run, in this order: the Calls, the Guards, the Factory,
BeforeProcedure, the procedure, OnError when the procedure leaves an error unhandled, and the ResultCalls. A
guard or BeforeProcedure that answers for the procedure skips the rest, up to the ResultCalls. An error that any of them
leaves unhandled, other than the procedure's error that OnError answers for, or an End in any of them, ends the run, and nothing
after it runs.
The procedure's object is the object of a class module it runs on: the factory's object, the default instance, or the new object. A procedure of a standard module has none, and its invocation runs no hook.
Constructors
ProgramInvocation(string, string, IReadOnlyDictionary<string, JsonNode?>)
One call of a procedure of a composed program, by name, with its arguments; and, in the same run, the calls that make the values it needs (Calls), the guards that may answer for it (Guards), the factory that makes the object it runs on (Factory), the hooks of that object (BeforeProcedure, OnError), and the calls that turn its value into the invocation's (ResultCalls).
public ProgramInvocation(string Module, string Procedure, IReadOnlyDictionary<string, JsonNode?> Arguments)
Parameters
ModulestringThe name of the module that declares the procedure, as RD-VBA names it: a standard module, or a class module of the program (not one of a library). With a Factory, the class whose default instance runs it.
ProcedurestringThe name of a
PublicSub,FunctionorProperty Getof that module; with a Factory, of the class of the object the factory returns.ArgumentsIReadOnlyDictionary<string, JsonNode>The arguments, by the names of the parameters they are passed to; an
Optionalparameter may have none.
Remarks
A machine matches each argument to the parameter of that name as RD-VBA compares names (case-insensitively), whatever the comparer of Arguments, and converts its value to the parameter's declared type. Each of these ends the invocation with a run-time error (RuntimeError) before the procedure runs, as MS-VBAL §5.3.1.11 maps named arguments:
- an argument that names no parameter, or two that name the same one (in different cases, or one in Arguments and one in ProcedureArguments), is error 448 (Named argument not found);
- a parameter with no argument that is not
Optionalis error 449 (Argument not optional); - a value that does not convert is error 13 (Type mismatch).
A procedure of a class whose VB_PredeclaredId is True runs on the class's default instance (MS-VBAL §5.2.4.1.2), the
program's own: the first reference to it, from the program or from an invocation, makes it, and its Class_Initialize runs then. It keeps its
state from one invocation to the next, and no invocation terminates it. A Set of it to Nothing lets go of it, and so does
ResetAsync(CancellationToken); the next reference makes another.
A procedure of any other class module runs on a new object of the class, made for the invocation as New makes one
(MS-VBAL §5.6.8). Its Class_Initialize runs before the procedure, and its Class_Terminate once the run has its value,
before the invocation ends (MS-VBAL §5.3.1.10). An error that the procedure leaves unhandled, or an End, ends the run, and the
run's end lets go of the object.
An error that Class_Initialize leaves unhandled ends the invocation with that run-time error, and the procedure does not run. An argument named
Me names no parameter. A document module is not invoked: its object is its host's document.
The whole invocation is one run, in this order: the Calls, the Guards, the Factory,
BeforeProcedure, the procedure, OnError when the procedure leaves an error unhandled, and the ResultCalls. A
guard or BeforeProcedure that answers for the procedure skips the rest, up to the ResultCalls. An error that any of them
leaves unhandled, other than the procedure's error that OnError answers for, or an End in any of them, ends the run, and nothing
after it runs.
The procedure's object is the object of a class module it runs on: the factory's object, the default instance, or the new object. A procedure of a standard module has none, and its invocation runs no hook.
Properties
Arguments
The arguments, by the names of the parameters they are passed to; an Optional parameter may have none.
public IReadOnlyDictionary<string, JsonNode?> Arguments { get; init; }
Property Value
BeforeProcedure
The hook called before the procedure, when the procedure's object implements the hook's interface. Its value is taken as a guard's is: an object
answers for the procedure, which does not run; Nothing lets the procedure run; any other value is error 13 (Type mismatch).
null when there is none.
public ProgramHookCall? BeforeProcedure { get; init; }
Property Value
Calls
The calls made first, in this order, each a call whose value is an object. Each value is kept under its call's Name for the rest of the run, and a ProgramCallArgument passes it to a parameter of a later call, a guard, the factory, a hook, a result call or the procedure.
public IReadOnlyList<ProgramCall> Calls { get; init; }
Property Value
Remarks
The run's end lets go of the value of each call that is not MachineHeld, in the reverse of the order the calls were made,
once the invocation's value is taken: an object that nothing else holds runs its Class_Terminate then (MS-VBAL §5.3.1.10).
An invocation refused at its arguments, or at the factory's value, lets go of them the same way.
A call that names a module or a procedure the program does not have, as ProgramCall describes them, ends the invocation as NotFound before anything runs. A call whose value is not an object is error 13 (Type mismatch).
Factory
The factory that makes the object the procedure runs on, after the Guards: a Public Function or Property Get of
the class that Module names, whose VB_PredeclaredId is True. null when the procedure runs on its
module.
public ProgramFactoryCall? Factory { get; init; }
Property Value
Remarks
The factory runs on the class's default instance (MS-VBAL §5.2.4.1.2), which keeps its state as it does for any procedure of the class. The procedure then runs on the object it returns, as a member of that object's class: the run's end lets go of the object, as it lets go of the values of the calls, before them.
A factory that returns Nothing is error 91 (Object variable not set), and one that returns a value that is not an object, error 13 (Type
mismatch). An object that is not of a class of the program, or whose class has no Public Sub, Function or Property Get
named Procedure, is error 438 (Object doesn't support this property or method). The procedure does not run in any of them. A class
that is not predeclared, or a factory that is not a Public Function or Property Get of it, ends the invocation as
NotFound before anything runs.
Guards
The guards, called after the Calls in this order, each a function whose value is an object or Nothing. A guard that returns
Nothing lets the run go on; a guard that returns an object answers for the procedure: the object is the run's value, and the run goes on at
the ResultCalls. A guard whose value is not an object is error 13 (Type mismatch).
public IReadOnlyList<ProgramCall> Guards { get; init; }
Property Value
Remarks
A guard has a Procedure and is not MachineHeld. No ProgramCallArgument passes its value. The run's end lets go of the object a guard answers with, after the invocation's value is taken.
Module
The name of the module that declares the procedure, as RD-VBA names it: a standard module, or a class module of the program (not one of a library). With a Factory, the class whose default instance runs it.
public string Module { get; init; }
Property Value
OnError
The hook called when the procedure leaves a run-time error unhandled, when the procedure's object implements the hook's interface. A ProgramErrorArgument passes the error's number or description to it. null when there is none.
public ProgramHookCall? OnError { get; init; }
Property Value
Remarks
The run handles the error as the error handler of a caller does: the procedure's object and the values of the Calls are kept, and the
hook runs. A hook that returns an object answers for the procedure: the object is the run's value, the error is cleared as leaving an error handler
clears it (MS-VBAL §6.1.3.2.1.1), and the run goes on at the ResultCalls. A hook that returns Nothing, or a
value that is not an object, leaves the procedure's error unhandled: it ends the run, as it does with no hook.
An error that the hook leaves unhandled ends the run with that error. The hook does not run for an End, an interruption, an internal error,
or an error raised before the procedure runs.
Procedure
The name of a Public Sub, Function or Property Get of that module; with a Factory, of the class of the object
the factory returns.
public string Procedure { get; init; }
Property Value
ProcedureArguments
The arguments of the procedure that Arguments cannot give: a ProgramCallArgument passes the value of one of the Calls; a ProgramValueArgument passes a JSON value, as Arguments does. A ProgramErrorArgument or a ProgramResultArgument is not one of them.
public IReadOnlyList<ProgramArgument> ProcedureArguments { get; init; }
Property Value
ResultCalls
The calls made once the run has its value, in this order: the procedure's value (Empty for a Sub), or the object of the guard or the
hook that answered for it. A ProgramResultArgument passes the run's value to a parameter of each, and each call's value becomes the
run's value: the last one's is the invocation's value.
public IReadOnlyList<ProgramCall> ResultCalls { get; init; }
Property Value
Remarks
A result call has a Procedure and is not MachineHeld. Its value may be of any type, and no ProgramCallArgument passes it. The run's end lets go of each one's value after the invocation's value is taken.
Methods
Validate()
Checks the shape of the invocation, before anything runs: what a host got wrong, whatever the program the invocation is meant for.
public void Validate()
Remarks
A machine calls this first, so that every IProgramMachine refuses the same invocations with the same messages. It looks only at the invocation, never at a program: a module or a procedure the program does not have is not found here.
The invocation is refused when:
- two of its calls (the Calls, Guards and ResultCalls) have the same Name (compared ordinally);
- an argument is a ProgramCallArgument that names a call that is not one of the Calls made before it: a call of Calls may name only the ones before it, and every other call or hook, any of them;
- a guard or a result call has no Procedure, or is MachineHeld;
- a call that makes a new object (no Procedure) is given arguments;
- an argument passes the error (ProgramErrorArgument) anywhere but to OnError, or the run's value (ProgramResultArgument) anywhere but to a result call.
Exceptions
- ArgumentException
The invocation breaks one of the rules. The message names the call or the parameter, in the current UI language, and ParamName is
invocation.