// used by the server when an exception is thrown
        // by the called function
        internal ServerFault CreateServerFault(Exception e)
        {
            // it's really strange here
            // a ServerFault object has a private System.Exception member called *exception*
            // (have a look at a MS Soap message when an exception occurs on the server)
            // but there is not public .ctor with an Exception as parameter...????....
            // (maybe an internal one). So I searched another way...
            ServerFault sf = (ServerFault)FormatterServices.GetUninitializedObject(typeof(ServerFault));

            MemberInfo[] mi = FormatterServices.GetSerializableMembers(typeof(ServerFault), new StreamingContext(StreamingContextStates.All));

            FieldInfo fi;

            object[] mv = new object[mi.Length];
            for (int i = 0; i < mi.Length; i++)
            {
                fi = mi[i] as FieldInfo;
                if (fi != null && fi.FieldType == typeof(Exception))
                {
                    mv[i] = e;
                }
            }
            sf = (ServerFault)FormatterServices.PopulateObjectMembers(sf, mi, mv);

            return(sf);
        }
        /// <summary>
        /// Shallow copy |instance| to |copy|. Use with care.
        ///
        /// (This covers the case where we want to shallow copy into an existing object,
        ///  which is not handled by Object.MemberwiseCopy).
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="copy"></param>
        /// <param name="instance"></param>
        /// <returns></returns>
        public static void Copy <T>(T copy, T instance)
        {
            var type   = instance.GetType();
            var fields = new List <MemberInfo>();

            if (type.GetCustomAttributes(typeof(SerializableAttribute), false).Length == 0)
            {
                var t = type;
                while (t != typeof(Object))
                {
                    Debug.Assert(t != null, "t != null");
                    fields.AddRange(
                        t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |
                                    BindingFlags.DeclaredOnly));
                    t = t.BaseType;
                }
            }
            else
            {
                fields.AddRange(FormatterServices.GetSerializableMembers(instance.GetType()));
            }
            var values = FormatterServices.GetObjectData(instance, fields.ToArray());

            FormatterServices.PopulateObjectMembers(copy, fields.ToArray(), values);
        }
Example #3
0
        static void Run()
        {
            // Create an instance of a Book class
            // with a title and author.
            Book Book1 = new Book("Book Title 1",
                                  "Masato Kawai");

            // Store data about the serializable members in a
            // MemberInfo array. The MemberInfo type holds
            // only type data, not instance data.
            MemberInfo[] members =
                FormatterServices.GetSerializableMembers
                    (typeof(Book));

            // Copy the data from the first book into an
            // array of objects.
            object[] data =
                FormatterServices.GetObjectData(Book1, members);

            // Create an uninitialized instance of the Book class.
            Book Book1Copy =
                (Book)FormatterServices.GetSafeUninitializedObject
                    (typeof(Book));

            // Call the PopuluateObjectMembers to copy the
            // data into the new Book instance.
            FormatterServices.PopulateObjectMembers
                (Book1Copy, members, data);

            // Print the data from the copy.
            Console.WriteLine("Title: {0}", Book1Copy.Title);
            Console.WriteLine("Author: {0}", Book1Copy.Author);
        }
 internal void PopulateObjectMembers(object obj, object[] memberData)
 {
     if (!this.isSi && (memberData != null))
     {
         FormatterServices.PopulateObjectMembers(obj, this.cache.memberInfos, memberData);
     }
 }
    private void WorkOnInstanceAndLocal_2()
    {
        MemberInfo[] ms = FormatterServices.GetSerializableMembers(typeof(int), new StreamingContext(StreamingContextStates.All));
        foreach (MemberInfo m in ms)
        {
            if (!m.DeclaringType.Equals(typeof(Int32)))
            {
                throw new Exception("Err_23947tsg! error");
            }
        }
        int i = 5;

        Object[] os = FormatterServices.GetObjectData(i, ms);
        if ((int)os[0] != 5)
        {
            throw new Exception("Err_32497g! error");
        }
        Object o  = FormatterServices.GetUninitializedObject(typeof(int));
        Object o1 = FormatterServices.PopulateObjectMembers(o, ms, os);

        if ((Int32)o1 != 5)
        {
            throw new Exception("Err_23947tsg! 2347sg");
        }
        Int32[] iS = { 1, 2, 3 };
        if (Buffer.ByteLength(iS) != 12)
        {
            throw new Exception("Err_10974! wrong result");
        }
        if (Buffer.GetByte(iS, 4) != 2)
        {
            throw new Exception("Err_23408! wrong result");
        }
    }
Example #6
0
        private SerializationStatus DeserializeSerializable(SerializationInstance instance, Type t, SerializationInfo info, StreamingContext context)
        {
            object obj = FormatterServices.GetUninitializedObject(t);

            InvokeOnSerialize(obj, context, false, false);

            if (typeof(ISerializable).IsAssignableFrom(t) && TryDeserializeISerializable(obj, info, context))
            {
                InvokeOnSerialize(obj, context, false, true);
                return(SerializationStatus.Deserialized(obj));
            }

            Dictionary <string, MemberInfo> map = FormatterServices.GetSerializableMembers(t, context).ToDictionary(m => m.Name);

            List <MemberInfo> found  = new List <MemberInfo>();
            List <object>     values = new List <object>();

            foreach (SerializationEntry entry in info)
            {
                if (!map.TryGetValue(entry.Name, out MemberInfo mi))
                {
                    continue;
                }

                found.Add(mi);
                values.Add(info.GetValue(entry.Name, GetMemberType(mi)));
            }

            obj = FormatterServices.PopulateObjectMembers(obj, found.ToArray(), values.ToArray());

            InvokeOnSerialize(obj, context, false, true);
            return(SerializationStatus.Deserialized(obj));
        }
Example #7
0
        private void DeserializeProxyMembers()
        {
            var proxyType = proxy.GetType();
            var members   = FormatterServices.GetSerializableMembers(proxyType);

            var deserializedMembers = new List <MemberInfo>();
            var deserializedValues  = new List <object>();

            for (var i = 0; i < members.Length; i++)
            {
                var member = members[i] as FieldInfo;
                // we get some inherited members...
                if (member.DeclaringType != proxyType)
                {
                    continue;
                }

                Debug.Assert(member != null);
                var value = info.GetValue(member.Name, member.FieldType);
                deserializedMembers.Add(member);
                deserializedValues.Add(value);
            }
            FormatterServices.PopulateObjectMembers(
                proxy,
                deserializedMembers.ToArray(),
                deserializedValues.ToArray()
                );
        }
Example #8
0
 // Fills in the values for an object
 internal void PopulateObjectMembers(object obj, object[] memberData)
 {
     if (!_isSi && memberData != null)
     {
         FormatterServices.PopulateObjectMembers(obj, _cache._memberInfos, memberData);
     }
 }
Example #9
0
    public object Deserialize(Stream serializationStream)
    {
        IList list;

        using (var sr = new StreamReader(serializationStream))
        {
            // Optional if reading headers! Example: UserId, FirstName, Title
            if (_firstLineIsHeaders)
            {
                string[] headers = GetHeader(sr);
            }
            var listType            = typeof(List <>);
            var constructedListType = listType.MakeGenericType(typeof(T));
            list = (IList)Activator.CreateInstance(constructedListType);
            while (sr.Peek() >= 0)
            {
                var      line      = sr.ReadLine();
                var      fieldData = line.Split(_delimiter);
                var      obj       = FormatterServices.GetUninitializedObject(typeof(T));
                var      members   = FormatterServices.GetSerializableMembers(obj.GetType(), Context);
                object[] data      = new object[members.Length];
                for (int i = 0; i < members.Length; ++i)
                {
                    FieldInfo fi = ((FieldInfo)members[i]);
                    data[i] = Convert.ChangeType(fieldData.ElementAt(i), fi.FieldType, CultureInfo.InvariantCulture);
                }
                list.Add((T)FormatterServices.PopulateObjectMembers(obj, members, data));
            }
        }
        return(list);
    }
Example #10
0
        public void TestClass1()
        {
            DerivedClass1 derived = new DerivedClass1();

            derived.anotherInt = 69;
            MemberInfo [] members = FormatterServices.GetSerializableMembers(derived.GetType());
            Assert.IsTrue(members != null, "#01");
            Assert.AreEqual(3, members.Length, "#02");

            object [] data = FormatterServices.GetObjectData(derived, members);
            Assert.IsTrue(data != null, "#03");
            Assert.AreEqual(3, data.Length, "#04");

            DerivedClass1 o = (DerivedClass1)FormatterServices.GetUninitializedObject(derived.GetType());

            Assert.IsTrue(o != null, "#05");

            o = (DerivedClass1)FormatterServices.PopulateObjectMembers(o, members, data);
            Assert.IsTrue(o != null, "#06");
            Assert.AreEqual("hola", o.Hello, "#07");
            Assert.AreEqual(21, o.IntBase, "#08");
            Assert.AreEqual(1, o.IntDerived, "#09");
            Assert.AreEqual(69, o.anotherInt, "#10");
            Assert.AreEqual("hey", DerivedClass1.hey, "#11");
        }
Example #11
0
        public TObject CopyObject <TObject>(TObject originalObject)
        {
            object copy;
            Type   type = originalObject.GetType();

            // If type is implementing IClonable then return its Clone implementation
            if (originalObject is ICloneable)
            {
                return((TObject)((ICloneable)originalObject).Clone());
            }

            List <MemberInfo> fields = new List <MemberInfo>();

            if (type.GetCustomAttributes(typeof(SerializableAttribute), false).Length == 0)
            {
                Type t = type;
                while (t != typeof(object))
                {
                    fields.AddRange(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
                    t = t.BaseType;
                }
            }
            else
            {
                fields.AddRange(FormatterServices.GetSerializableMembers(originalObject.GetType()));
            }

            copy = FormatterServices.GetUninitializedObject(originalObject.GetType());
            object[] values = FormatterServices.GetObjectData(originalObject, fields.ToArray());
            FormatterServices.PopulateObjectMembers(copy, fields.ToArray(), values);

            return((TObject)copy);
        }
        int ReadObject(BinaryReader reader, Type type, ref object obj, SerializeAsAttribute attr)
        {
            int size = 0;

            if (type.BaseType != _TypeOfObject)
            {
                size += ReadObject(reader, type.BaseType, ref obj, attr);
            }

            MemberInfo[] membersInfo = FormatterServices.GetSerializableMembers(type, _Contex);
            object[]     membersData = new object[membersInfo.Length];

            for (int i = 0; i < membersInfo.Length; i++)
            {
                MemberInfo memberInfo = membersInfo[i];
                Debug.Assert(memberInfo is FieldInfo);

                SerializeAsAttribute memberAttr = GetSerializeAsAttribute(type, obj, memberInfo);

                object memberData;
                Type   memberType = memberAttr.FieldType == null ? ((FieldInfo)memberInfo).FieldType : memberAttr.FieldType;

                size          += ReadMember(reader, memberType, out memberData, memberAttr);
                membersData[i] = memberData;

                obj = FormatterServices.PopulateObjectMembers(obj, membersInfo, membersData);
            }

            return(size);
        }
Example #13
0
        // X:\jsc.svn\core\ScriptCoreLib\JavaScript\BCLImplementation\System\Runtime\Serialization\FormatterServices.cs

        /// <summary>
        /// This is a javascript application.
        /// </summary>
        /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param>
        public Application(IApp page)
        {
            var o = new xFoo();

            Console.WriteLine(new { o });

            //var x = typeof(o);
            var x = o.GetType();

            Console.WriteLine("GetUninitializedObject");

            // sometime later
            var oo = FormatterServices.GetUninitializedObject(x);

            //var isFoo = oo as xFoo;
            var isFoo = oo is xFoo;

            // Uncaught TypeError: Cannot read property 'LgEABvEJMzKFrGX3QxjvzA' of null

            var om = FormatterServices.GetSerializableMembers(x);
            var ov = FormatterServices.GetObjectData(o, om);

            FormatterServices.PopulateObjectMembers(oo, om, ov);

            // 0:34ms {{ isFoo = true, oo = xFoo: {{ xField1 = field1 {{ Counter = 1 }} }} }}
            // 0:80ms {{ isFoo = true, oo = xFoo: {{ xField1 = null }} }}
            // do we still see ToString?
            Console.WriteLine(new { isFoo, oo });
        }
        public object RecreateClassProxy(SerializationInfo info, StreamingContext context)
        {
            bool delegateBaseSer = info.GetBoolean("__delegateToBase");

            if (!delegateBaseSer)
            {
                _data = (object[])info.GetValue("__data", typeof(object[]));
            }

            object proxy = null;

            GeneratorContext genContext = new GeneratorContext();

            if (_mixins.Length != 0)
            {
                foreach (object mixin in _mixins)
                {
                    genContext.AddMixinInstance(mixin);
                }
            }

            ClassProxyGenerator cpGen = new ClassProxyGenerator(_scope, genContext);

            Type proxy_type;

            if (_mixins.Length == 0)
            {
                proxy_type = cpGen.GenerateCode(_baseType, _interfaces);
            }
            else
            {
                proxy_type = cpGen.GenerateCustomCode(_baseType, _interfaces);
            }

            if (delegateBaseSer)
            {
                proxy = Activator.CreateInstance(proxy_type, new object[] { info, context });
            }
            else
            {
                if (_mixins.Length == 0)
                {
                    proxy = Activator.CreateInstance(proxy_type, new object[] { _interceptor });
                }
                else
                {
                    ArrayList args = new ArrayList();
                    args.Add(_interceptor);
                    args.Add(genContext.MixinsAsArray());

                    proxy = Activator.CreateInstance(proxy_type, args.ToArray());
                }

                MemberInfo[] members = FormatterServices.GetSerializableMembers(_baseType);
                FormatterServices.PopulateObjectMembers(proxy, members, _data);
            }

            return(proxy);
        }
Example #15
0
        public DefaultKernel(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            MemberInfo[] members = FormatterServices.GetSerializableMembers(GetType(), context);

            object[] kernelmembers = (object[])info.GetValue("members", typeof(object[]));

            FormatterServices.PopulateObjectMembers(this, members, kernelmembers);
        }
Example #16
0
 internal void PopulateObjectMembers(object obj, object[] memberData)
 {
     if (this.isSi || memberData == null)
     {
         return;
     }
     FormatterServices.PopulateObjectMembers(obj, this.cache.memberInfos, memberData);
 }
Example #17
0
        private object CloneWithISerializable(object instance)
        {
            object            copy;
            Type              type  = instance.GetType();
            SerializationInfo sInfo = new SerializationInfo(type, new FormatterConverter());

            ((ISerializable)instance).GetObjectData(sInfo, _sCtx);

            Type tcopy = Type.GetType(String.Format("{0}, {1}", sInfo.FullTypeName, sInfo.AssemblyName), true, false);

            copy = FormatterServices.GetUninitializedObject(tcopy);
            Graph.Add(instance, copy);

            SerializationInfo sCopy = new SerializationInfo(tcopy, new FormatterConverter());

            foreach (SerializationEntry se in sInfo)
            {
                sCopy.AddValue(se.Name, this.CloneObject(se.Value), se.ObjectType);
            }

            if (type == tcopy || typeof(ISerializable).IsAssignableFrom(tcopy))
            {
                ConstructorInfo ci = tcopy.GetConstructor(
                    BindingFlags.CreateInstance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null,
                    new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null);
                if (ci == null)
                {
                    throw new SerializationException("Serialization constructor not found.");
                }
                ci.Invoke(copy, new object[] { sCopy, _sCtx });
            }
            else
            {
                List <MemberInfo> fields = new List <MemberInfo>();
                List <object>     values = new List <object>();

                foreach (FieldInfo fi in SerializedFields(tcopy))
                {
                    try
                    {
                        object value = sCopy.GetValue(fi.Name, fi.FieldType);
                        fields.Add(fi);
                        values.Add(value);
                    }
                    catch (SerializationException) { }
                }

                FormatterServices.PopulateObjectMembers(copy, fields.ToArray(), values.ToArray());
            }

            if (copy is IObjectReference)
            {
                copy            = ((IObjectReference)copy).GetRealObject(_sCtx);
                Graph[instance] = copy;
            }
            return(copy);
        }
 public void PopulateObjectMembers_InvalidArguments_ThrowsException()
 {
     Assert.Throws <ArgumentNullException>("obj", () => FormatterServices.PopulateObjectMembers(null, new MemberInfo[0], new object[0]));
     Assert.Throws <ArgumentNullException>("members", () => FormatterServices.PopulateObjectMembers(new object(), null, new object[0]));
     Assert.Throws <ArgumentNullException>("data", () => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[0], null));
     Assert.Throws <ArgumentException>(() => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[1], new object[2]));
     Assert.Throws <ArgumentNullException>("members", () => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[1], new object[1]));
     Assert.Throws <SerializationException>(() => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[] { typeof(object).GetMethod("GetHashCode") }, new object[] { new object() }));
 }
 public c_Settings()
 {
     if (Default == null)
     {
         return;
     }
     MemberInfo[] members = FormatterServices.GetSerializableMembers(typeof(c_Settings));
     FormatterServices.PopulateObjectMembers(this, members, FormatterServices.GetObjectData(Default, members));
 }
Example #20
0
        public DefaultKernel(SerializationInfo info, StreamingContext context)
        {
            var members       = FormatterServices.GetSerializableMembers(GetType(), context);
            var kernelmembers = (object[])info.GetValue("members", typeof(object[]));

            FormatterServices.PopulateObjectMembers(this, members, kernelmembers);

            HandlerRegistered += (HandlerDelegate)info.GetValue("HandlerRegisteredEvent", typeof(Delegate));
        }
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     if (this.returnedObject != null)
     {
         string[]     names   = null;
         MemberInfo[] members = FormatterServicesNoSerializableCheck.GetSerializableMembers(this.type, out names);
         FormatterServices.PopulateObjectMembers(this.returnedObject, members, this.memberDatas);
         this.returnedObject = null;
     }
 }
Example #22
0
        public static object DeepClone(this object obj, Type type)
        {
            var members = FormatterServices.GetSerializableMembers(type);
            var data    = FormatterServices.GetObjectData(obj, members);
            var cloned  = FormatterServices.GetSafeUninitializedObject(type);

            FormatterServices.PopulateObjectMembers
                (cloned, members, data);
            return(cloned);
        }
Example #23
0
        // Fills in the values for an object
        internal void PopulateObjectMembers(Object obj, Object[] memberData)
        {
            SerTrace.Log(this, objectInfoId, " ", objectType, " PopulateObjectMembers  isSi ", isSi);
            if (!isSi && memberData != null)
            {
                DumpPopulate(cache.memberInfos, memberData);

                FormatterServices.PopulateObjectMembers(obj, cache.memberInfos, memberData);
            }
        }
Example #24
0
        private Manager(SerializationInfo si, StreamingContext sc)
        {
            Type t = typeof(Employee);

            MemberInfo[] mi = FormatterServices.GetSerializableMembers(t);
            Object []    os = (Object[])si.GetValue("EmployeeStuff", typeof(Object[]));
            FormatterServices.PopulateObjectMembers(this, mi, os);
            this.m_Reports        = si.GetInt32("Reports");
            this.m_BonusPerReport = si.GetSingle("Bonus");
        }
Example #25
0
        protected T DeepClone <T>(Type type)
        {
            var members = FormatterServices.GetSerializableMembers(type);
            var data    = FormatterServices.GetObjectData(this, members);
            var cloned  = FormatterServices.GetSafeUninitializedObject(type);

            FormatterServices.PopulateObjectMembers(cloned, members, data);

            return((T)cloned);
        }
Example #26
0
        // Fills in the values for an object
        internal void PopulateObjectMembers()
        {
            InternalST.Soap(this, objectInfoId, " ", objectType, " PopulateObjectMembers  isSi ", isSi);
            if (!isSi)
            {
                MemberInfo[] finalMemberInfos = null;
                Object[]     finalMemberData  = null;
                int          finalMemberIndex = 0;

                if (numberMembersSeen < memberNames.Length)
                {
                    finalMemberInfos = new MemberInfo[numberMembersSeen];
                    finalMemberData  = new Object[numberMembersSeen];

                    for (int iMember = 0; iMember < memberNames.Length; ++iMember)
                    {
                        if (memberNames[iMember] == null)
                        {
                            // A field on the type isnt found. See if the field has OptionallySerializable and the type has the deserialization constructor
                            Object [] attrs = cache.memberInfos[iMember].GetCustomAttributes(typeof(OptionalFieldAttribute), false);
                            if ((attrs == null || attrs.Length == 0) && (majorVersion >= 1 && minorVersion >= 0))
                            {
                                // the member isnt optionally serializable
                                throw new SerializationException(SoapUtil.GetResourceString("Serialization_WrongNumberOfMembers",
                                                                                            objectType, cache.memberInfos.Length, numberMembersSeen));
                            }
                        }
                        else
                        {
                            if (memberNames[iMember] != cache.memberInfos[iMember].Name)
                            {
                                throw new SerializationException(SoapUtil.GetResourceString("Serialization_WrongNumberOfMembers",
                                                                                            objectType, cache.memberInfos.Length, numberMembersSeen));
                            }

                            finalMemberInfos[finalMemberIndex] = cache.memberInfos[iMember];
                            finalMemberData[finalMemberIndex]  = memberData[iMember];
                            finalMemberIndex++;
                        }
                    }
                }
                else
                {
                    finalMemberInfos = cache.memberInfos;
                    finalMemberData  = memberData;
                }


                DumpPopulate(finalMemberInfos, finalMemberData);

                FormatterServices.PopulateObjectMembers(obj, finalMemberInfos, finalMemberData);
                numberMembersSeen = 0;
            }
        }
        public static void PopulateFields(SerializationInfo serializationInfo, object instance)
        {
            ArgumentUtility.CheckNotNull("serializationInfo", serializationInfo);
            ArgumentUtility.CheckNotNull("instance", instance);

            var members = FormatterServices.GetSerializableMembers(instance.GetType());
            var mapping = s_serializableFieldFinder.GetSerializableFieldMapping(members.Cast <FieldInfo>());
            var data    = mapping.Select(m => serializationInfo.GetValue(m.Item1, m.Item2.FieldType)).ToArray();

            FormatterServices.PopulateObjectMembers(instance, members, data);
        }
Example #28
0
        private SerializationFixup CreateSerializableFixup(MemberInfo[] missing, StreamingContext context)
        {
            return(fixup);

            SerializationStatus fixup(SerializationInstance instance, object obj, ulong[] ids, object[] values)
            {
                FormatterServices.PopulateObjectMembers(obj, missing, values);
                InvokeOnSerialize(obj, context, false, true);
                return(SerializationStatus.Success);
            }
        }
        object DeserializeSerializable(TypeInfo typeInfo, int id)
        {
            var type = typeInfo.Type;

            var defConstructor = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[0], null);

            object ob;

            if (defConstructor != null)
            {
                ob = Activator.CreateInstance(type, true);
            }
            else
            {
                ob = FormatterServices.GetUninitializedObject(type);
            }

            if (id != -1)
            {
                m_referenceResolver.Add(id, ob);
            }

            var members = typeInfo.SerializableMembers;

            var values = new object[members.Length];

            while (true)
            {
                if (m_reader.TokenType == JsonToken.EndObject)
                {
                    break;
                }

                Trace.Assert(m_reader.TokenType == JsonToken.PropertyName);

                string fieldName = (string)m_reader.Value;

                var idx   = Array.FindIndex(members, fi => fi.Name == fieldName);
                var field = (FieldInfo)members[idx];

                Read();

                object value = DeserializeObject(field.FieldType);

                values[idx] = value;

                Read();
            }

            FormatterServices.PopulateObjectMembers(ob, members, values);

            return(ob);
        }
Example #30
0
        private SerializationStatus DeserializeSerializable(SerializationInstance instance, Type t, SerializationInfo info, StreamingContext context)
        {
            object obj = FormatterServices.GetUninitializedObject(t);

            InvokeOnSerialize(obj, context, false, false);

            if (typeof(ISerializable).IsAssignableFrom(t) && TryDeserializeISerializable(obj, info, context))
            {
                InvokeOnSerialize(obj, context, false, true);
                return(SerializationStatus.Deserialized(obj));
            }

            Dictionary <string, MemberInfo> map = FormatterServices.GetSerializableMembers(t, context).ToDictionary(m => m.Name);

            List <MemberInfo> found  = new List <MemberInfo>();
            List <object>     values = new List <object>();

            List <MemberInfo> missing     = new List <MemberInfo>();
            List <ulong>      missing_ids = new List <ulong>();

            foreach (SerializationEntry entry in info)
            {
                if (!map.TryGetValue(entry.Name, out MemberInfo mi))
                {
                    continue;
                }

                SerializedObject so = (SerializedObject)info.GetValue(entry.Name, typeof(SerializedObject));

                if (instance.TryGetOrDeserialize(GetMemberType(mi), so, out object val))
                {
                    found.Add(mi);
                    values.Add(val);
                }
                else
                {
                    missing.Add(mi);
                    missing_ids.Add(so.Id);
                }
            }

            obj = FormatterServices.PopulateObjectMembers(obj, found.ToArray(), values.ToArray());

            if (missing_ids.Count == 0)
            {
                InvokeOnSerialize(obj, context, false, true);
                return(SerializationStatus.Deserialized(obj));
            }

            return(SerializationStatus.FixupLater(obj, CreateSerializableFixup(missing.ToArray(), context), missing_ids.ToArray()));
        }