Assembly: OptimaJet.Workflow.Core

Class DynamicParameter

OptimaJet.Workflow.Core.Model.DynamicParameter

Represents dynamically structured process parameter data as named properties that can be accessed by string key or through dynamic member binding.

[JsonConverter(typeof(NewtonsoftDynamicParameterConverter))]
[JsonConverter(typeof(SystemTextDynamicParameterConverter))]
public sealed class DynamicParameter : DynamicObject, IDynamicMetaObjectProvider

Type Hierarchy

Attributes

  • Newtonsoft.Json.JsonConverterAttribute: Attribute of type Newtonsoft.Json.JsonConverterAttribute
  • System.Text.Json.Serialization.JsonConverterAttribute: Attribute of type System.Text.Json.Serialization.JsonConverterAttribute

Constructors

public DynamicParameter() #
Initializes an empty DynamicParameter with case-sensitive property-name comparisons.
public DynamicParameter(Dictionary<string, object> properties) #
Initializes a DynamicParameter that uses the supplied properties as its backing storage.

Parameters

Name
Type
Description
properties
Dictionary<String, Object>
The properties to store directly. The key comparer of the supplied Dictionary<TKey, TValue> controls property-name comparisons. Use null to create an empty instance with case-sensitive comparisons.

Properties

public IReadOnlyDictionary<string, object> Dictionary { get; } #
Gets a read-only view of the stored properties.
public object this[string propertyName] { get; set; } #
Gets or sets the value at a specified property path.

Exceptions

Type
Description
Exception
When setting a value, an intermediate path segment exists but cannot be represented as a DynamicParameter.

Methods

public override bool TryGetMember(GetMemberBinder binder, out object result) #
Gets a dynamic member value through DynamicParameter.GetProperty(string).

Parameters

Name
Type
Description
binder
GetMemberBinder
The GetMemberBinder that provides the member name.
result
Object
When this method returns, contains the stored value, or null if the property does not exist.

Returns

Type
Description
Boolean
true because the dynamic get operation is always handled.
public override bool TrySetMember(SetMemberBinder binder, object value) #
Sets a dynamic member value through DynamicParameter.SetProperty(string, object).

Parameters

Name
Type
Description
binder
SetMemberBinder
The SetMemberBinder that provides the member name.
value
Object
The value to store.

Returns

Type
Description
Boolean
true because the dynamic set operation is always handled.
public object GetProperty(string propertyName) #
Gets the value at a specified property path.

Parameters

Name
Type
Description
propertyName
String
The property name or period-delimited path.

Returns

Type
Description
Object
The stored value, or null if the path does not exist or cannot be traversed.

Example

After calling parameter.SetProperty("Order.Customer.Name", "Alice"), parameter.GetProperty("Order.Customer.Name") returns "Alice", while parameter.GetProperty("Order.Customer.Id") returns null.
public void SetProperty(string propertyName, object value) #
Sets the value at a specified property path, creating missing nested DynamicParameter instances.

Parameters

Name
Type
Description
propertyName
String
The property name or period-delimited path.
value
Object
The value to store.

Exceptions

Type
Description
Exception
An intermediate path segment exists but cannot be represented as a DynamicParameter.

Example

parameter.SetProperty("Order.Customer.Name", "Alice") creates the missing Order and Customer objects and stores "Alice" at the specified path. A subsequent call to parameter.GetProperty("Order.Customer.Name") returns "Alice".
public bool HasProperty(string propertyName, bool ifNullThenNotExists = false) #
Determines whether a specified property path exists.

Parameters

Name
Type
Description
propertyName
String
The property name or period-delimited path.
ifNullThenNotExists
Boolean
true to treat a property whose value is null as missing; otherwise, false.

Returns

Type
Description
Boolean
true if the path exists and satisfies the ifNullThenNotExists condition; otherwise, false.
public DynamicParameter DeepClone() #
Creates an independent copy of this DynamicParameter through JSON serialization.

Returns

Type
Description
DynamicParameter
A new DynamicParameter containing the serialized property values.
public string SerializeToJson() #
Serializes the stored properties to JSON.

Returns

Type
Description
String
The JSON representation of the stored properties.
public static object ParseJson(string json) #
Parses JSON text into the runtime representation used by DynamicParameter.

Parameters

Name
Type
Description
json
String
The JSON text to parse.

Returns

Type
Description
Object
A scalar or collection value for a corresponding JSON value; a DynamicParameter for a JSON object; null for empty input or a JSON null value; or the original text if it is not valid JSON.
public static object ParseJson(JToken jToken) #
Converts a JToken into the runtime representation used by DynamicParameter.

Parameters

Name
Type
Description
jToken
JToken
The JSON token to convert.

Returns

Type
Description
Object
A scalar or collection value for a corresponding JSON value; a DynamicParameter for a JSON object; or null if jToken is null or represents a JSON null value.
public static dynamic New() #
Creates an empty DynamicParameter exposed through dynamic binding.

Returns

Type
Description
dynamic
A new empty DynamicParameter returned as dynamic.
public static object ConvertFrom(object value) #
Converts an object graph to the representation used by DynamicParameter.

Parameters

Name
Type
Description
value
Object
The value to convert.

Returns

Type
Description
Object
The converted scalar, collection, or DynamicParameter value; or null when value is null.

Exceptions

Type
Description
Exception
The object graph cannot be converted or exceeds the supported conversion depth.

Remarks

A value that implements IDynamicParameterCompatible supplies its properties through IDynamicParameterCompatible.GetPropertiesAsDictionary().
public T ConvertTo<T>() where T : IDynamicParameterCompatible, new() #
Creates and populates an IDynamicParameterCompatible object from the stored properties.

Returns

Type
Description
{T}
A new T populated from the stored properties.
public T Restore<T>() #
Restores the stored properties as T.

Returns

Type
Description
{T}
The restored T value.

Exceptions

Type
Description
Exception
T implements IDynamicParameterCompatible, but an instance cannot be created or populated.

Remarks

This overload delegates to DynamicParameter.Restore(Type).
public object Restore(Type originalType) #
Restores the stored properties as an object of a specified type.

Parameters

Name
Type
Description
originalType
Type
The target Type.

Returns

Type
Description
Object
The restored value.

Exceptions

Type
Description
Exception
originalType implements IDynamicParameterCompatible, but an instance cannot be created or populated.

Remarks

A DynamicParameter target returns this instance. A target type that implements IDictionary<string, object> returns a serializable property dictionary. A target type that implements IDynamicParameterCompatible is instantiated and populated through IDynamicParameterCompatible.SetPropertiesFromDictionary(IDictionary<string, object>); all other target types are restored through JSON deserialization.

Remarks