@@ -37,11 +37,6 @@ public class CommandOverload
3737 /// </summary>
3838 public Dictionary < string , CommandParameterBuilder > ParameterBuilders { get ; } = new ( ) ;
3939
40- /// <summary>
41- /// Gets the compiled method delegate.
42- /// </summary>
43- public Func < object , object [ ] , object > Method { get ; }
44-
4540 /// <summary>
4641 /// Gets the empty buffer.
4742 /// </summary>
@@ -120,8 +115,6 @@ public CommandOverload(MethodInfo target)
120115 IsEmpty = parameters ? . Length == 0 ;
121116 IsAsync = target . ReturnType == typeof ( Task ) ;
122117 IsCoroutine = target . ReturnType == typeof ( IEnumerator < float > ) ;
123-
124- Method = FastReflection . ForMethod ( Target ) ;
125118
126119 if ( target . DeclaringType != null && target . DeclaringType . InheritsType < ContinuableCommandBase > ( ) )
127120 {
@@ -143,4 +136,30 @@ public CommandOverload(MethodInfo target)
143136 if ( ! IsEmpty )
144137 Buffer = new ( new object [ ParameterCount ] , ( ) => new object [ ParameterCount ] ) ;
145138 }
139+
140+ /// <summary>
141+ /// Invokes the underlying command or method with the specified context and arguments.
142+ /// </summary>
143+ /// <param name="ctx">The command context that provides the target instance and execution environment. Cannot be null.</param>
144+ /// <param name="args">An array of arguments to pass to the command or method. The number of elements must match the expected parameter
145+ /// count. If the command takes no parameters, this can be null or an empty array.</param>
146+ /// <returns>The result returned by the invoked command or method. The type and meaning of the result depend on the specific
147+ /// command implementation.</returns>
148+ /// <exception cref="ArgumentNullException">Thrown if ctx is null, or if args is null when the command expects one or more parameters.</exception>
149+ /// <exception cref="ArgumentException">Thrown if the number of elements in args does not match the expected parameter count.</exception>
150+ public object Invoke ( CommandContext ctx , object [ ] args )
151+ {
152+ if ( ctx is null )
153+ throw new ArgumentNullException ( nameof ( ctx ) ) ;
154+
155+ if ( args is null && ! IsEmpty )
156+ throw new ArgumentNullException ( nameof ( args ) ) ;
157+
158+ args ??= Array . Empty < object > ( ) ;
159+
160+ if ( args . Length != ParameterCount )
161+ throw new ArgumentException ( $ "Expected { ParameterCount } arguments, but got { args . Length } .") ;
162+
163+ return Target . Invoke ( ctx . Instance , args ) ;
164+ }
146165}
0 commit comments