Class MappingConverterRegistry
- Namespace
- IntentSharp.Mapping
- Assembly
- IntentSharp.dll
The converters a client's compiled mappings may call by name with Convert: your own code, for what the closed vocabulary does not express, such as a unit conversion, a check digit or a lookup in your own tables. A stored mapping holds only a converter's name, so nothing from a file or a store row is ever run as code. Register converters with WithMappingConverters(Action<MappingConverterRegistry>); each client keeps its own copy.
public sealed class MappingConverterRegistry
- Inheritance
-
objectMappingConverterRegistry
- Inherited Members
-
object.Equals(object)object.Equals(object, object)object.GetHashCode()object.GetType()object.ReferenceEquals(object, object)object.ToString()
- Extension Methods
Remarks
The registered names and versions are part of every mapping key, because a compile is told which converters exist: registering a converter, or changing a version, compiles each key once. Change a converter's version when its meaning changes, so that mappings compiled against the old meaning are not reused. Names ignore case.
A converter receives each source read as its argument type, from the input's wire form (web naming, enums as their names), and is not called when a source is null: the step writes null. Its result is written as the output reads it. An exception it throws, or a source that does not read as its argument type, fails the step with ConverterFailed, which never compiles a replacement; the failure names the converter and the exception's type, never the exception's message, which could hold a value. An OperationCanceledException is not caught: a converter is given no cancellation token, so one it throws comes from its own code and reaches the caller, as a provider's cancellation does. A converter is called once per input that reaches its step, so it must be safe to call from several threads at once.
Constructors
- MappingConverterRegistry()
Creates an empty registry.
Properties
- Registered
The registered converters, sorted by name. Each read returns a new list, so later registrations do not change it.
Methods
- Add<TArg, TResult>(string, string, Func<TArg, TResult>)
Registers a converter of one argument: a step reads one source as
TArgand writes the result.
- Add<TArg1, TArg2, TResult>(string, string, Func<TArg1, TArg2, TResult>)
Registers a converter of two arguments: a step reads two sources, in order, as
TArg1andTArg2.