Show / Hide Table of Contents

Class StructurePatchingHelper

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

Inheritance
object
StructurePatchingHelper
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Util
Assembly: SoCore.dll
Syntax
public static class StructurePatchingHelper
Remarks

This class will visit every element in the data structure it is given. Such a structure can be a simple value type, a string, a class, an array or a dictionary of elements. Every element will be evaluated to see if its type matches one of those that are to be patched; if so, the supplied action method is called and the value returned from that method is substituted into the original element.
This is a somewhat-specialized case of the Visitor pattern, with this class implementing the iterator over a data structure and the dispatching based on element type.
If required, it can be extended to deal with other kinds of sub-elements - but note that the overwriteValue action argument needs to be tailored to the replacement semantics of each kind of element. Replacing an element of an array is very different from setting a property of a class.

Methods

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

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

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

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

Attribute[] decorations

Custom attributes belonging to the element

string name
Dictionary<Type, StructurePatchingHelper.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

See unit tests and the SoCarrierDataPatching class for illustrations of usage

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

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

Declaration
public static void ApplyActions(object root, Dictionary<Type, StructurePatchingHelper.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, StructurePatchingHelper.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

See unit tests and the SoCarrierDataPatching class for illustrations of usage

© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top