Show / Hide Table of Contents

Interface IStructurePatchingHelper

Iterate over a complex data structure. Unroll arrays and dictionaries; recurse class members. Only look at public Properties that can read/write, and public instance fields. Used for Carrier data patching in WebApi.

Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public interface IStructurePatchingHelper
Remarks

Implementations cache per-Type reflection metadata and compiled accessors, so the cost of visiting a given Carrier type is paid only once per process.
This is a somewhat-specialized case of the Visitor pattern, with the implementation iterating over a data structure and dispatching based on element type.

Methods

ApplyActions(object, Attribute[], string, Dictionary<Type, TypeAction>, Action<object>)

Continuation entry point used when the caller already holds element-level metadata (decorations + name) from an outer walk and needs to re-enter the visitor for a sub-element. Equivalent to the top-level overload, but forwards the supplied decorations and name into the type-action callbacks for this element.

Declaration
void ApplyActions(object element, Attribute[] decorations, string name, Dictionary<Type, TypeAction> actions, Action<object> overwriteValue)
Parameters
Type Name Description
object element

The element to descend into - typically a Carrier object; but can be an array, a simple type, or anything

Attribute[] decorations

Custom attributes belonging to the element, as collected by the outer walk

string name

Name of the element, as collected by the outer walk - mostly useful for debugging

Dictionary<Type, TypeAction> actions

Types that should trigger actions, mapped to a function that takes a value object + decorations and returns an amended value

Action<object> overwriteValue

Client-supplied method that performs the actual overwrite of the original value, with a patched value

Remarks

Implementations cache per-Type reflection metadata and compiled accessors, so the cost of visiting a given Carrier type is paid only once per process.
This is a somewhat-specialized case of the Visitor pattern, with the implementation iterating over a data structure and dispatching based on element type.

ApplyActions(object, Dictionary<Type, TypeAction>, Action<object>)

Top-level entry point. Iterate over a complex data structure starting from root; unroll arrays and dictionaries, recurse class members. The root carries no outer decorations and no element name - use the other overload when re-entering the visitor from inside a containing walk that has already collected those.

Declaration
void ApplyActions(object root, Dictionary<Type, TypeAction> actions, Action<object> overwriteValue)
Parameters
Type Name Description
object root

The root element, typically a Carrier object; but can be an array, a simple type, or anything

Dictionary<Type, TypeAction> actions

Types that should trigger actions, mapped to a function that takes a value object + decorations and returns an amended value. The trigger types should be simple types - not sequences or classes as these are the things that are traversed

Action<object> overwriteValue

Client-supplied method that performs the actual overwrite of the original value, with a patched value

Remarks

Implementations cache per-Type reflection metadata and compiled accessors, so the cost of visiting a given Carrier type is paid only once per process.
This is a somewhat-specialized case of the Visitor pattern, with the implementation iterating over a data structure and dispatching based on element type.

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top