Extensions for input management
More...
|
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...
|
|
Extensions for input management
◆ 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
-
inputType | Input type. |
cls | Class to bind to |
forwarder | Action to invoke on a forwarder call. Can be null |
scope | The scope to be bound |
25 Type type = cls.GetType();
27 foreach(var method
in type.GetAllMethods(x => Attribute.IsDefined(x, typeof(InputAttribute))))
29 InputBindDelegate rawInvoker = (InputBindDelegate)Delegate.CreateDelegate(typeof(InputBindDelegate), cls, method);
31 var inputAttrs = method.GetCustomAttributes(typeof(InputAttribute),
true).OfType<InputAttribute>();
32 foreach(var attrEnumerator
in inputAttrs)
34 if (attrEnumerator.HasScope(scope))
36 var attr = attrEnumerator;
39 if (attr.Forward && forwarder != null)
40 dlg = () => forwarder(method);
42 dlg = () => rawInvoker();
44 if (attr.DefaultKey.HasValue)
46 inputType.Bind(attr.Name ?? method.Name, attr.DefaultKey.Value, attr.Direction, dlg);
49 if (attr.DefaultMouseButton.HasValue)
51 inputType.Bind(attr.Name ?? method.Name, attr.DefaultMouseButton.Value, attr.Direction, dlg);
◆ 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
-
manager | Manager. |
cls | Cls. |
forwarder | Method call to forward a forwarded input. Can be null |
scope | The scope to be bound |
72 var binding = manager.GetBinding(cls.GetType());
73 InputExtensions.BindInputMethods(binding, cls, forwarder, scope);
The documentation for this class was generated from the following file: