/// <summary> /// De-serialise the stored data so that it can be used /// </summary> public void OnAfterDeserialize() { DataType = Type.GetType(typeString, false); IsValid = GenericSerialisation.CanProcess(DataType); Value = (IsValid ? GenericSerialisation.Parse(data, DataType) : null ); }
/// <summary> /// Maintain the serialised data so that it is able to be reproduced /// </summary> public void OnBeforeSerialize() { if (IsValid && DataType != null) { typeString = GenericSerialisation.MinifyTypeAssemblyName(DataType); data = GenericSerialisation.Serialise(Value, DataType); } else { typeString = string.Empty; data = string.Empty; } }
/// <summary> /// Assign a new value to this generic data collection /// </summary> /// <param name="value">The value data that is to be kept in this object</param> /// <param name="type">The type of the object that is to be stored</param> /// <returns>Returns true if the value will be serialised for storage/display</returns> public bool SetValue(object value, Type type) { // Set the valid flag based on the received values if (!GenericSerialisation.CanProcess(type)) { IsValid = false; } else if (object.Equals(value, null)) { IsValid = !type.IsValueType; } else { IsValid = type.IsAssignableFrom(value.GetType()); } // Save the values for use DataType = type; Value = value; return(IsValid); }