Empeld
Empeld plugin documentation.
pluginbase.Objects.Input.InputExtensions Class Reference

Extensions for input management More...

Static Public Member Functions

static int BindInputMethods (this IInputBinding inputType, object cls, Action< MethodInfo > forwarder=null, Enum scope=null)
 Search for, and bind, all methods with the /// More...
 
static IBoundInput BindInputMethods (this IInputManager manager, object cls, Action< MethodInfo > forwarder=null, Enum scope=null)
 Search for, and bind, all methids with the /// More...
 

Detailed Description

Extensions for input management

Member Function Documentation

◆ BindInputMethods() [1/2]

static int pluginbase.Objects.Input.InputExtensions.BindInputMethods ( this IInputBinding  inputType,
object  cls,
Action< MethodInfo >  forwarder = null,
Enum  scope = null 
)
static

Search for, and bind, all methods with the ///

Attribute: Input

attribute

Parameters
inputTypeInput type.
clsClass to bind to
forwarderAction to invoke on a forwarder call. Can be null
scopeThe scope to be bound
23  {
24  int total = 0;
25  Type type = cls.GetType();
26 
27  foreach(var method in type.GetAllMethods(x => Attribute.IsDefined(x, typeof(InputAttribute))))
28  {
29  InputBindDelegate rawInvoker = (InputBindDelegate)Delegate.CreateDelegate(typeof(InputBindDelegate), cls, method);
30 
31  var inputAttrs = method.GetCustomAttributes(typeof(InputAttribute), true).OfType<InputAttribute>();
32  foreach(var attrEnumerator in inputAttrs)
33  {
34  if (attrEnumerator.HasScope(scope))
35  {
36  var attr = attrEnumerator; //need closure var
37 
38  Action dlg = null;
39  if (attr.Forward && forwarder != null)
40  dlg = () => forwarder(method);
41  else
42  dlg = () => rawInvoker();
43 
44  if (attr.DefaultKey.HasValue)
45  {
46  inputType.Bind(attr.Name ?? method.Name, attr.DefaultKey.Value, attr.Direction, dlg);
47  }
48 
49  if (attr.DefaultMouseButton.HasValue)
50  {
51  inputType.Bind(attr.Name ?? method.Name, attr.DefaultMouseButton.Value, attr.Direction, dlg);
52  }
53  total++;
54  }
55  }
56  }
57 
58  return total;
59  }

◆ BindInputMethods() [2/2]

static IBoundInput pluginbase.Objects.Input.InputExtensions.BindInputMethods ( this IInputManager  manager,
object  cls,
Action< MethodInfo >  forwarder = null,
Enum  scope = null 
)
static

Search for, and bind, all methids with the ///

Attribute: Input

attribute Remember to StartListening() on the result and keep the result around otherwise it will be unbound

Returns
The input methods.
Parameters
managerManager.
clsCls.
forwarderMethod call to forward a forwarded input. Can be null
scopeThe scope to be bound
71  {
72  var binding = manager.GetBinding(cls.GetType());
73  InputExtensions.BindInputMethods(binding, cls, forwarder, scope);
74  return binding;
75  }

The documentation for this class was generated from the following file: