Skip to main content
Version: 3.5

DynamicObject

Namespace: Wisej.Core

Assembly: Wisej.Framework (3.5.0.0)

Custom fast implementation of a dynamic object that can handle the JSON serialization and deserialization. This class implements IDynamicMetaObjectProvider allowing the DLR to compile the dynamic member access on the fly. We could have derived from System.Dynamic.Dynamic but the implementation in the .NET framework uses exceptions to manage custom properties.

public class DynamicObject : IDynamicMetaObjectProvider, ICloneable, IList<Member>, ICollection<Member>, IEnumerable<Member>, IEnumerable, ISerializable, ICustomTypeDescriptor, INotifyPropertyChanged, IConvertible

Constructors

Instance memberDynamicObject()

Default constructor.

Instance memberDynamicObject(capacity)

Optional constructor. Takes the initial capacity to allocate the specified number of slots in the store.

NameTypeDescription
capacityInt32Initial number of store entries.

Instance memberDynamicObject(source)

Creates a new DynamicObject cloned from the source object.

NameTypeDescription
sourceDynamicObjectSource object to copy the fields from.

Properties

Instance memberCount

Int32: Returns the number of fields.

Instance memberIsEmpty

Boolean: Returns true if the dynamic doesn't object contains any field.

Instance memberItem(name)

Object: Returns or sets the value of the specified member.

Methods

Instance memberClear()

Wipes out the object.

Instance memberClear(keepCapacity)

Wipes out the object but it keeps the capacity.

ParameterTypeDescription
keepCapacityBoolean

Instance memberClone()

Clones the members of the dynamic object.

Returns: DynamicObject. The cloned instance.

This is a shallow copy. Reference members are copied by reference.

Instance memberContains(name)

Returns whether the object contains the specified field.

ParameterTypeDescription
nameStringName of the field to check.

Returns: Boolean. True if the field name exists in the store.

Instance memberCopyFrom(source)

Copies all the values from the source object.

ParameterTypeDescription
sourceDynamicObjectObject to copy members from.

Instance memberDelete(name)

Deletes the field.

ParameterTypeDescription
nameStringName of the field to remove.

Returns: DynamicObject. Itself, this call can be chained.

Instance memberDiff(original)

Returns a new ComponentConfiguration object containing only the values that don't exist in the ComponentConfiguration object passed to the method.

ParameterTypeDescription
originalDynamicObjectprevious values to diff against.

Returns: Object. Returns null if there are no differences.

Instance memberGetEnumerator()

Returns an enumerator that iterates through the collection.

Returns: IEnumerator<Member>. A IEnumerator

Instance memberNotify(name)

Fires the PropertyChanged event.

ParameterTypeDescription
nameStringName of the property that has changed in the dynamic object.

Instance memberSort()

Sorts the field by their name.

Instance memberToJSON(formatted)

Serializes the object to a JSON string.

ParameterTypeDescription
formatted optionalBooleanTrue to format the output JSON string.

Returns: String. A String representing the serialized object.

Instance memberToJSON(options)

Serializes the object to a JSON string.

ParameterTypeDescription
optionsWisejSerializerOptionsA combination of WisejSerializerOptions flags.

Returns: String. A String representing the serialized object.

Instance memberTrimExcess()

Removes the excess entries in the inner array and in all child fields, recursively.

Instance memberTryGetValue(name, value)

Tries to retrieve the value for the specified member.

ParameterTypeDescription
nameStringName of the field to retrieve.
value by referenceObjectWill receive the value of the name field.

Returns: Boolean. True if the member was found, otherwise false.