class ManagedSerializableObject

Inherits: IReflectable

Allows access to an underlying managed object, or a cached version of that object 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

ManagedSerializableObject

ManagedSerializableObject(const ConstructPrivately &dummy, SPtr<ManagedObjectInfo> objInfo, MonoObject *managedInstance)

ManagedSerializableObject

ManagedSerializableObject(const ConstructPrivately &dummy)

Methods

~ManagedSerializableObject

~ManagedSerializableObject() noexcept

GetManagedInstance

MonoObject *GetManagedInstance() const

Returns the internal managed instance of the object.

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

GetObjectInfo

SPtr<ManagedObjectInfo> GetObjectInfo() const

Returns the type information for the internal object.

SetFieldData

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

Sets a new value of the specified field.

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

fieldInfo
Object describing the field to which to set the value. This field must belong to the type this object is initialized with.
val
Wrapper around the value to store in the field.

GetFieldData

SPtr<ManagedSerializableFieldData> GetFieldData(const SPtr<ManagedMemberInfo> &fieldInfo) const

Returns the value of the specified field.

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

fieldInfo
Object describing the field to which to set the value. This field must belong to the type this object is initialized with.

Returns: A wrapper around the value of the field.

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.

Deserialize

void Deserialize(MonoObject *instance, const SPtr<ManagedObjectInfo> &objInfo)

Deserializes a set of cached data into an existing managed object.

Caller must ensure the provided object is of proper type.

instance
Existing managed instance of the same type this serializable object represents.
objInfo
Serializable object info for the managed object type.

Equals

bool Equals(ManagedSerializableObject &other, RTTIOperationContext *context = nullptr)

Checks if this object has the same contents as the provided object.

staticCreateFromExisting

static SPtr<ManagedSerializableObject> CreateFromExisting(MonoObject *managedInstance)

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

Created object will be in linked mode.

managedInstance
Constructed managed instance of the object to link with.

staticCreateNew

static SPtr<ManagedSerializableObject> CreateNew(const SPtr<ManagedTypeInfoObject> &type)

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

type
Type of the object to create.

staticCreateManagedInstance

static MonoObject *CreateManagedInstance(const SPtr<ManagedTypeInfoObject> &type)

Creates a managed object instance.

type
Type of the object to create.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

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

Protected

Methods

staticCreateEmpty

static SPtr<ManagedSerializableObject> CreateEmpty()

Creates an empty and uninitialized object used for serialization purposes.

Fields

mGCHandle

uint32_t mGCHandle

mObjInfo

SPtr<ManagedObjectInfo> mObjInfo

mCachedData

UnorderedMap<ManagedSerializableFieldKey, SPtr<ManagedSerializableFieldData>, Hash, struct Equals> mCachedData