/// <summary> /// Deserializes PortableObjectDocument into original graph of arbitrary CLR objects trying to preserve/convert as much data as possible /// using optionally supplied strategy /// </summary> public object ToOriginalObject(ReadingStrategy strategy = null) { if (strategy == null) { strategy = ReadingStrategy.Default; } if (m_Root == null) { return(null); } m_StreamingContext = new StreamingContext(); try { var result = PortableDataToNativeData(strategy, m_Root); if (m_CompositeData != null) { foreach (var cd in m_CompositeData) { var obj = cd.__CLRObject; if (obj == null) { continue; } //invoke all IDeserializationCallback-implementors if (obj is IDeserializationCallback) { ((IDeserializationCallback)obj).OnDeserialization(this); } //invoke all OnDeserialized List <MethodInfo> methodsOnDeserialized = SerializationUtils.FindSerializationAttributedMethods(obj.GetType(), typeof(OnDeserializedAttribute)); if (methodsOnDeserialized != null) { SerializationUtils.InvokeSerializationAttributedMethods(methodsOnDeserialized, obj, m_StreamingContext); } } } return(result); } finally { purgeCaches(); //drop all temp objects } }
/// <summary> /// Transforms a portable data value, such as object, primitive, struct etc.. into a CLR /// </summary> public object PortableDataToNativeData(ReadingStrategy strategy, object data) { if (data == null) { return(null); } if (!(data is CompositeData)) { return(data); } var cd = (CompositeData)data; return(strategy.CompositeToNative(cd)); }
/// <summary> /// Handles the assignemnt from ReflectedData into CLR fieldInfo. Override to make conversions, i.e. string to bool, int to string etc... /// Return true to indicate that default framework implementation should not be called /// </summary> public abstract bool SetFieldValue(ReadingStrategy readingStrategy, object instance, FieldInfo fieldInfo, CompositeReflectedData data, MetaComplexType.MetaField mfield);
/// <summary> /// Desirializes a graph of arbitrary CLR objects that was serialized before /// </summary> /// <param name="stream">Source data stream in Slim binary format</param> /// <param name="readingStrategy">Optional reading strategy</param> /// <returns>CLR object graph which is deserialized from possibly transformed PortableObjectDocument container</returns> public object Deserialize(Stream stream, ReadingStrategy readingStrategy = null) { var document = DeserializeDocument(stream); return document.ToOriginalObject(readingStrategy); }
/// <summary> /// Transforms a portable data value, such as object, primitive, struct etc.. into a CLR /// </summary> public object PortableDataToNativeData(ReadingStrategy strategy, object data) { if (data==null) return null; if (! (data is CompositeData)) return data; var cd = (CompositeData)data; return strategy.CompositeToNative(cd); }
/// <summary> /// Deserializes PortableObjectDocument into original graph of arbitrary CLR objects trying to preserve/convert as much data as possible /// using optionally supplied strategy /// </summary> public object ToOriginalObject(ReadingStrategy strategy = null) { if (strategy==null) strategy = ReadingStrategy.Default; if (m_Root==null) return null; m_StreamingContext = new StreamingContext(); try { var result = PortableDataToNativeData(strategy, m_Root); if (m_CompositeData!=null) { foreach(var cd in m_CompositeData) { var obj = cd.__CLRObject; if (obj==null) continue; //invoke all IDeserializationCallback-implementors if (obj is IDeserializationCallback) ((IDeserializationCallback)obj).OnDeserialization(this); //invoke all OnDeserialized List<MethodInfo> methodsOnDeserialized = SerializationUtils.FindSerializationAttributedMethods( obj.GetType(), typeof(OnDeserializedAttribute)); if (methodsOnDeserialized!=null) SerializationUtils.InvokeSerializationAttributedMethods(methodsOnDeserialized, obj, m_StreamingContext); } } return result; } finally { purgeCaches();//drop all temp objects } }