/// <summary> /// Performs deserialization of SerializationInfo from CompositeCustomData bag /// </summary> protected virtual SerializationInfo DeserializeSerializationInfo(Type objType, CompositeCustomData data, StreamingContext context) { var info = new SerializationInfo(objType, new FormatterConverter()); foreach (var pair in data.CustomData) { var name = pair.Key; var type = ResolveType(data.Document.GetMetaTypeFromIndex(pair.Value.TypeIndex)); var obj = data.Document.PortableDataToNativeData(this, pair.Value.Data); info.AddValue(name, obj, type); } return(info); }
public virtual void DeserializeObjectFromCompositeCustomData(object instance, CompositeCustomData data) { var t = instance.GetType(); //1 check for attribute --------------- var attr = (PortableObjectDocumentDeserializationTransform)t .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false) .FirstOrDefault(); if (attr != null) { if (attr.DeserializeFromCompositeCustomData(instance, data)) { return; } } if (instance is ISerializable) { var scontext = new StreamingContext(); var iser = (ISerializable)instance; //rebuild ISerializationInfo object var info = DeserializeSerializationInfo(t, data, scontext); //Get ctor and invoke var ctor = t.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null); if (ctor == null) { throw new PODDeserializationException(StringConsts.POD_ISERIALIZABLE_MISSING_CTOR_ERROR + t.FullName); } ctor.Invoke(iser, new object[] { info, scontext }); } else { throw new PODDeserializationException(StringConsts.POD_DONT_KNOW_HOWTO_DESERIALIZE_FROM_CUSTOM_DATA.Args(t.FullName)); } }
/// <summary> /// Handles the deserialization of the object instance from CompoisteCustomData bag. Returns true to indicate that /// deserialization was handled completely here and default framework implementation should not be called /// </summary> public abstract bool DeserializeFromCompositeCustomData(object instance, CompositeCustomData data);
/// <summary> /// Handles the deserialization of the object instance from CompoisteCustomData bag. Returns true to indicate that /// deserialization was handled completely here and default framework implementation should not be called /// </summary> public abstract bool DeserializeFromCompositeCustomData(object instance, CompositeCustomData data);
/// <summary> /// Performs deserialization of SerializationInfo from CompositeCustomData bag /// </summary> protected virtual SerializationInfo DeserializeSerializationInfo(Type objType, CompositeCustomData data, StreamingContext context) { var info = new SerializationInfo(objType, new FormatterConverter()); foreach(var pair in data.CustomData) { var name = pair.Key; var type = ResolveType( data.Document.GetMetaTypeFromIndex( pair.Value.TypeIndex ) ); var obj = data.Document.PortableDataToNativeData(this, pair.Value.Data); info.AddValue(name, obj, type); } return info; }
public virtual void DeserializeObjectFromCompositeCustomData(object instance, CompositeCustomData data) { var t = instance.GetType(); //1 check for attribute --------------- var attr = (PortableObjectDocumentDeserializationTransform)t .GetCustomAttributes(typeof(PortableObjectDocumentDeserializationTransform), false) .FirstOrDefault(); if (attr!=null) if (attr.DeserializeFromCompositeCustomData(instance, data)) return; if (instance is ISerializable) { var scontext = new StreamingContext(); var iser = (ISerializable)instance; //rebuild ISerializationInfo object var info = DeserializeSerializationInfo(t, data, scontext); //Get ctor and invoke var ctor = t.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext)}, null); if (ctor==null) throw new PODDeserializationException(StringConsts.POD_ISERIALIZABLE_MISSING_CTOR_ERROR + t.FullName); ctor.Invoke(iser, new object[]{ info, scontext} ); } else throw new PODDeserializationException(StringConsts.POD_DONT_KNOW_HOWTO_DESERIALIZE_FROM_CUSTOM_DATA.Args( t.FullName )); }