Difference between revisions of "Parameter Processors"
Line 1: | Line 1: | ||
+ | [[Category:Parameters| ]] | ||
In order to use custom types as parameters in Reflex Commands, the system uses a <code>ParameterProcessor</code> system to: | In order to use custom types as parameters in Reflex Commands, the system uses a <code>ParameterProcessor</code> system to: | ||
* Convert string inputs into object instances / references | * Convert string inputs into object instances / references |
Revision as of 06:56, 23 September 2017
In order to use custom types as parameters in Reflex Commands, the system uses a ParameterProcessor
system to:
- Convert string inputs into object instances / references
- Provide meaningful suggestions to the console.
Some types are supported by default (see Supported Parameter Types). Additional support can be added for any type, include your own types, by creating a custom ParameterProcessor
Contents
Implementing a ParameterProcessor
All ParameterProcessors are derived from the ParameterProcessor
class and marked with the ParameterProcessorAttribute
, which specifies the type of parameter that is handled by the processor. Both of these are found in the ReflexCLI.Paramters
namespace.
Declaring a Foo
Processor
The following creates and registers a processor for the type Foo
using namespace ReflexCLI.Parameters; [ParameterProcessor(typeof(Foo))] public class FooProcessor : ParameterProcessor {}
Handling Text Input
To handle text input and create a concrete instance of type Foo from a user input string, then you will need to override the ConvertString()
method of ParamterProcessor
.
public class FooProcessor : ParameterProcessor { public override object ConvertString(Type type, string inString) { return new Foo(inString); } }
The following assumes that you wish to create a new Foo
object, and that a Foo.Foo(string)
constructor exists. The string to type conversion will be highly dependent on your type.