コード例 #1
0
ファイル: ReadingStrategy.cs プロジェクト: zhabis/nfx
        /// <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
ファイル: ReadingStrategy.cs プロジェクト: zhabis/nfx
        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));
            }
        }
コード例 #3
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);
コード例 #4
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);
コード例 #5
0
ファイル: ReadingStrategy.cs プロジェクト: itadapter/nfx
        /// <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;
        }
コード例 #6
0
ファイル: ReadingStrategy.cs プロジェクト: itadapter/nfx
        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 ));
        }