Difference between revisions of "Parameter Processors"

From ReflexCLI
Jump to: navigation, search
(Created page with "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 / ref...")
 
 
(2 intermediate revisions by the same user not shown)
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
 
* Provide meaningful suggestions to the console.
 
* Provide meaningful suggestions to the console.
  
Some types are supported by default (see [[Supported Types]]). Additional support can be added for any type, include your own types, by creating a custom <code>ParameterProcessor</code>
+
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 <code>ParameterProcessor</code>
  
 
==Implementing a <code>ParameterProcessor</code>==
 
==Implementing a <code>ParameterProcessor</code>==
Line 33: Line 34:
  
 
The following assumes that you wish to create a new <code>Foo</code> object, and that a <code>Foo.Foo(string)</code> constructor exists. The string to type conversion will be highly dependent on your type.
 
The following assumes that you wish to create a new <code>Foo</code> object, and that a <code>Foo.Foo(string)</code> constructor exists. The string to type conversion will be highly dependent on your type.
 
===Allowing for Named Values===
 

Latest revision as of 14:27, 3 January 2018

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.