private bool Read_Object <T>(ref T ioObject) where T : ISerializedObject { string typeName = null; bool typeSuccess = DoRead(TYPE_KEY, ref typeName, null, FieldOptions.PreferAttribute, Read_String_Cached ?? (Read_String_Cached = Read_String)); if (!typeSuccess) { AddErrorMessage("Unable to read object type info"); } Type objectType = typeof(T); if (!string.IsNullOrEmpty(typeName)) { objectType = TypeUtility.NameToType(typeName); } if (ioObject == null || ioObject.GetType().TypeHandle.Value != objectType.TypeHandle.Value) { ioObject = (T)TypeUtility.Instantiate(objectType, this); } ushort version = 1; bool versionSuccess = DoRead(VERSION_KEY, ref version, (ushort)1, FieldOptions.PreferAttribute, Read_UInt16_Cached ?? (Read_UInt16_Cached = Read_UInt16)); if (!versionSuccess) { AddErrorMessage("Unable to read object version info"); } ushort prevVersion = ObjectVersion; ObjectVersion = version; ISerializedCallbacks callback = ioObject as ISerializedCallbacks; if (callback != null) { PreSerialize(callback); } int prevErrorLength = m_ErrorString.Length; ISerializedObject obj = ioObject; obj.Serialize(this); ioObject = (T)obj; ObjectVersion = prevVersion; return(typeSuccess && versionSuccess && (m_ErrorString.Length == prevErrorLength)); }
private void Write_Object <T>(ref T inObject) where T : ISerializedObject { // Make sure to write out the subclass name if we need to if (typeof(T).TypeHandle.Value != inObject.GetType().TypeHandle.Value) { string typeName = TypeUtility.TypeToName(inObject.GetType()); DoWrite(TYPE_KEY, ref typeName, FieldOptions.PreferAttribute, Write_String_Cached ?? (Write_String_Cached = Write_String)); } else if (RequiresExplicitNull()) { WriteNull(TYPE_KEY); } ushort version = 1; if (inObject is ISerializedVersion) { version = ((ISerializedVersion)inObject).Version; } if (version != 1) { DoWrite(VERSION_KEY, ref version, FieldOptions.PreferAttribute, Write_UInt16_Cached ?? (Write_UInt16_Cached = Write_UInt16)); } else if (RequiresExplicitNull()) { WriteNull(VERSION_KEY); } ushort prevVersion = ObjectVersion; ObjectVersion = version; ISerializedCallbacks callback = inObject as ISerializedCallbacks; if (callback != null) { PreSerialize(callback); } inObject.Serialize(this); ObjectVersion = prevVersion; }
private void PreSerialize(ISerializedCallbacks inCallback) { m_CallbackHandlers.Add(inCallback); }