Parameter Processors

From ReflexCLI
Revision as of 14:27, 3 January 2018 by Rtm223 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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

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.