class ManagedSerializableDictionary

Inherits: IReflectable

Allows access to an underlying managed dictionary, or a cached version of that dictionary that can be serialized/deserialized.

You can transfer an object in linked state to serialized state by calling serialize(). If an object is in serialized state you can call deserialize() to populated a managed object from the cached data.

Public

Constructors

ManagedSerializableDictionary

ManagedSerializableDictionary(const ConstructPrivately &dummy, const SPtr<ManagedTypeInfoDictionary> &typeInfo, MonoObject *managedInstance)

ManagedSerializableDictionary

ManagedSerializableDictionary(const ConstructPrivately &dummy)

Methods

~ManagedSerializableDictionary

~ManagedSerializableDictionary() noexcept

GetManagedInstance

MonoObject *GetManagedInstance() const

Returns the internal managed instance of the dictionary.

This will return null if the object is in serialized mode.

GetTypeInfo

SPtr<ManagedTypeInfoDictionary> GetTypeInfo() const

Returns the type information for the internal dictionary.

GetFieldData

SPtr<ManagedSerializableFieldData> GetFieldData(const SPtr<ManagedSerializableFieldData> &key)

Returns the dictionary value at the specified key.

If the key doesn't exist the default value for the type is returned. Operates on managed object if in linked state, or on cached data otherwise.

key
Wrapper around the key data at which to retrieve the value.

Returns: A wrapper around the value in the dictionary at the specified key.

SetFieldData

void SetFieldData(const SPtr<ManagedSerializableFieldData> &key, const SPtr<ManagedSerializableFieldData> &val)

Sets the dictionary value at the specified key.

Operates on managed object if in linked state, or on cached data otherwise.

key
Wrapper around the key data at which to set the value.
val
Wrapper around the value to set at the specified key.

RemoveFieldData

void RemoveFieldData(const SPtr<ManagedSerializableFieldData> &key)

Deletes the key/value pair at the specified key.

If the key doesn't exist this operation does nothing. Operates on managed object if in linked state, or on cached data otherwise.

key
Wrapper around the key data at which to delete the value.

Contains

bool Contains(const SPtr<ManagedSerializableFieldData> &key) const

Checks if the dictionary contains the specified key.

Operates on managed object if in linked state, or on cached data otherwise.

key
Wrapper around the key data which to check.

GetEnumerator

Enumerator GetEnumerator() const

Returns an enumerator object that allows you to iterate over all key/value pairs in the dictionary.

Serialize

void Serialize()

Serializes the internal managed object into a set of cached data that can be saved in memory/disk and can be deserialized later.

The internal managed object will be freed (if no other references to it). Calling serialize() again will have no result.

Deserialize

MonoObject *Deserialize()

Deserializes a set of cached data into a managed object.

This action may fail in case the cached data contains a type that no longer exists in which case null is returned.

Returns: Newly created object initialized with the cached data.

staticCreateFromExisting

static SPtr<ManagedSerializableDictionary> CreateFromExisting(MonoObject *managedInstance, const SPtr<ManagedTypeInfoDictionary> &typeInfo)

Creates a managed serializable dictionary that references an existing managed dictionary.

Created object will be in linked mode.

managedInstance
Constructed managed instance of the dictionary to link with. Its type must correspond with the provided type info.
typeInfo
Type information for the dictionary and its key/value pair.

staticCreateNew

static SPtr<ManagedSerializableDictionary> CreateNew(const SPtr<ManagedTypeInfoDictionary> &typeInfo)

Creates a managed serializable dictionary that creates and references a brand new managed dictionary instance.

typeInfo
Type of the dictionary to create.

staticCreateManagedInstance

static MonoObject *CreateManagedInstance(const SPtr<ManagedTypeInfoDictionary> &typeInfo)

Creates a managed dictionary instance.

typeInfo
Type of the dictionary to create.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const

Returns an interface you can use to access class' Run Time Type Information.

Protected

Methods

InitMonoObjects

void InitMonoObjects(MonoClass *dictionaryClass)

Retrieves needed Mono types and methods.

Should be called before performing any operations with the managed object.

SetFieldData

void SetFieldData(MonoObject *obj, const SPtr<ManagedSerializableFieldData> &key, const SPtr<ManagedSerializableFieldData> &val)

Sets the dictionary value at the specified key.

Operates on the provided managed object.

obj
Managed object to which to assign the data.
key
Wrapper around the key data at which to set the value.
val
Wrapper around the value to set at the specified key.

staticCreateEmpty

static SPtr<ManagedSerializableDictionary> CreateEmpty()

Creates an empty and uninitialized object used for serialization purposes.

Fields

mGCHandle

uint32_t mGCHandle

mAddMethod

MonoMethod * mAddMethod

mRemoveMethod

MonoMethod * mRemoveMethod

mTryGetValueMethod

MonoMethod * mTryGetValueMethod

mContainsKeyMethod

MonoMethod * mContainsKeyMethod

mCountProp

MonoProperty * mCountProp

mKeysProp

MonoProperty * mKeysProp

mKeysCopyTo

MonoMethod * mKeysCopyTo

mValuesProp

MonoProperty * mValuesProp

mValuesCopyTo

MonoMethod * mValuesCopyTo

mDictionaryTypeInfo

SPtr<ManagedTypeInfoDictionary> mDictionaryTypeInfo

mCachedEntries

CachedEntriesMap mCachedEntries