Thanks to visit codestin.com
Credit goes to github.com

Skip to content

peter-tomaselli/Dispatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dispatch

Callable

An instance of Callable wraps a function with a specific number of arguments. There are several Callables for different function 'arities':

  • class Callable<R> : ICallable<R>
  • class Callable<T1, R> : ICallable<R>
  • class Callable<T1, T2, R> : ICallable<R>
  • ...

ICallable

All arities of Callable implement the same 'arity' of ICallable, which is an interface with one method:

  • R InvokeWithArgs(params object[] args)
  • This provides one level of indirection: the programmer can attempt to call a function of an arbitrary number of arguments using an arbitrary number of arguments
    • If you get it wrong this will fail tho

CallableTable

CallableTable provides a second level of indirection by mapping ICallables to two levels of string keys (a 'domain' and a 'name')

  • In sum, this provides a 'dispatch table' where functions are 'namespaced' (called here 'domain'), can be 'resolved', and subsequently invoked with an arbitrary number of parameters at runtime

CallableTable Example

public void RuntimeWingIt()
{
  ICallableTable<MyResult> myTable = /* configure the table */
  
  MyResult result = myTable.GetCallable(
    "someRuntimeDomainKey", 
    "someRuntimeFunctionName")
  .InvokeWithArgs("some", "number", "of", "runtime", "args");
}

About

Map strings to methods without reflection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages