Links

DynamicObject

Wisej.Core.DynamicObject
Namespace: Wisej.Core
Assembly: Wisej.Framework (3.1.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.
C#
VB.NET
public class DynamicObject : IDynamicMetaObjectProvider, ICloneable, IList<Member>, ICollection<Member>, IEnumerable<Member>, IEnumerable, ISerializable, ICustomTypeDescriptor, INotifyPropertyChanged, IConvertible
Public Class DynamicObject
Inherits IDynamicMetaObjectProvider
Implements ICloneable, IList(Of Member), ICollection(Of Member), IEnumerable(Of Member), IEnumerable, ISerializable, ICustomTypeDescriptor, INotifyPropertyChanged, IConvertible

Constructors

DynamicObject()

Default constructor.

DynamicObject(capacity)

Optional constructor. Takes the initial capacity to allocate the specified number of slots in the store.
Name
Type
Description
capacity
Int32
Initial number of store entries.

DynamicObject(source)

Creates a new DynamicObject cloned from the source object.
Name
Type
Description
source
Source object to copy the fields from.

Properties

Count

Int32: Returns the number of fields.

IsEmpty

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

Item(name)

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

Methods

Clear()

Wipes out the object.

Clear(keepCapacity)

Wipes out the object but it keeps the capacity.
Parameter
Type
Description
keepCapacity
Boolean

Clone()

Clones the members of the dynamic object.
Returns: DynamicObject. The cloned instance.
This is a shallow copy. Reference members are copied by reference.

Contains(name)

Returns whether the object contains the specified field.
Parameter
Type
Description
name
String
Name of the field to check.
Returns: Boolean. True if the field name exists in the store.

CopyFrom(source)

Copies all the values from the source object.
Parameter
Type
Description
source
Object to copy members from.

Delete(name)

Deletes the field.
Parameter
Type
Description
name
String
Name of the field to remove.
Returns: DynamicObject. Itself, this call can be chained.

Diff(original)

Returns a new ComponentConfiguration object containing only the values that don't exist in the ComponentConfiguration object passed to the method.
Parameter
Type
Description
original
previous values to diff against.
Returns: Object. Returns null if there are no differences.

GetEnumerator()

Returns an enumerator that iterates through the collection.

Notify(name)

Fires the PropertyChanged event.
Parameter
Type
Description
name
String
Name of the property that has changed in the dynamic object.

Sort()

Sorts the field by their name.

ToJSON(formatted)

Serializes the object to a JSON string.
Parameter
Type
Description
formatted
Boolean
True to format the output JSON string.
Returns: String. A String representing the serialized object.

ToJSON(options)

Serializes the object to a JSON string.
Parameter
Type
Description
options
A combination of WisejSerializerOptions flags.
Returns: String. A String representing the serialized object.

TrimExcess()

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

TryGetValue(name, value)

Parameter
Type
Description
name
String
value
Object&
Returns: Boolean.