FieldDefinitionRegistry

This static class performs an important function in the creation of the data entry form - given the name and type of a property, it returns an instance of a BaseFieldDefinition-descendant class. What makes the class particularly powerful is the ability to register new property names, types and field definition types, including using wildcards for property names. Before getting to the methods of this class, lets look at how this is used.

Registering New Properties

Lets look at how to register simple data types. The register() method takes two type parameters, one of the property type and the second is the field definition type AutoForm should use:

FieldDefinitionRegistry.Default.Register<int, IntegerSliderFieldDefinition>();

(This is juts a random example that register all integer fields to use the IntegerSliderFieldDefinition)

Using wildcards, you can register field definition types for similar property names. Here's an example which configures all string properties whose names end in "Filename" to use a file picker field:

FieldDefinitionRegistry.Default.Register<String, FilePickerFieldDefinition>("*Filename");

Or make sure all properties beginning with "Description" produce a multi-line text box:

FieldDefinitionRegistry.Default.Register<String, MemoFieldDefinition>("Description*");

Note that the asterisk can only appear at the beginning or end of the field name parameter, not within the name.

Methods

public object Definition<T>();
Returns an instance of the registered field definition class for the property type T. If no suitable definition is registered the method returns null.

public object Definition<T>(String s);
Returns an instance of the registered field definition class for properties of type T and whose name is s. If no suitable definition is registered the method returns the default for properties of type T, and if there is no default then the method returns null.

public void Register<T, F>();
Registers properties of type T to use field definition type F.

public void Register<T, F>(s);
Registers properties of type T to use field definition type F, but only where the property name matches the string s. S can begin or end with an asterisk for matching wild cards.

Last edited Oct 21, 2014 at 2:43 PM by DevKnightlie, version 5