예제 #1
0
        /// <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);
        }
예제 #2
0
 /// <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);
예제 #3
0
        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));
            }
        }