Extract
Pulls a nested property or field out of a Memory object into its own Memory slot. Uses reflection to find the first public instance property or field of type TOut on the TIn object.
Signatures
Extract<TIn, TOut>()
Retrieves TIn from Memory, then extracts a TOut property/field from it.
protected Monad<TInput, TReturn> Extract<TIn, TOut>()Extract<TIn, TOut>(TIn input)
Extracts a TOut property/field from the provided TIn object.
protected Monad<TInput, TReturn> Extract<TIn, TOut>(TIn input)These are the train's own methods, which start a chain in Junctions(). Later in a chain, after a Chain or ShortCircuit, the call is MonadTask<TInput, TReturn>'s method of the same name, which takes the same arguments and returns MonadTask<TInput, TReturn>.
Type Parameters
| Type Parameter | Description |
|---|---|
TIn | The source type to extract from. Must have a public instance property or field of type TOut. |
TOut | The target type to extract and store in Memory. |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
input | TIn | No | The source object (second overload only). If omitted, TIn is retrieved from Memory. |
Returns
The chain, for fluent chaining: Monad<TInput, TReturn> from the train's method, MonadTask<TInput, TReturn> from a later link.
Example
public record OrderInput(string CustomerId, OrderDetails Details);
public record OrderDetails(string ItemId, int Quantity);
protected override Task<Either<Exception, OrderResult>> Junctions() =>
Extract<OrderInput, OrderDetails>() // Pulls OrderDetails out of OrderInput
.Chain<ProcessOrder>().Resolve(); // ProcessOrder receives OrderDetails from MemoryBehavior
- Looks for the first public instance property of type
TOutonTIn. Static properties and indexers are skipped: a static value is not this object's, and an indexer cannot be read without an argument. - If not found, looks for the first public instance field of type
TOut. - If found, stores the value in Memory under
typeof(TOut). - If not found or null, sets the exception:
"Could not find non-null value of type: ({TOut}) in properties or fields for ({TIn}). Is it public?"
Remarks
- Only the first matching property/field is extracted. If
TInhas multiple properties of typeTOut, only the first one found is used. - Properties and fields must be public and belong to the instance to be discoverable.
- If
TInis not found in Memory (parameterless overload), sets the exception, naming the step, the train and the missing type:"Extract<OrderInput, OrderDetails> (train 'ProcessOrderTrain') found no 'OrderInput' in Memory. Chain a junction that outputs 'OrderInput' before the Extract.". That holds for a value type too.