internal SettingFieldEventArgs(object obj, StreamingContext context, SerializationInfo info, SerializationEntry entry)
 {
     Object            = obj;
     Context           = context;
     SerializationInfo = info;
     Entry             = entry;
 }
        protected OwnerDrawPropertyBag(SerializationInfo info, StreamingContext context)
        {
            this.foreColor = Color.Empty;
            this.backColor = Color.Empty;
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                if (current.Name == "Font")
                {
                    this.font = (System.Drawing.Font)current.Value;
                }
                else
                {
                    if (current.Name == "ForeColor")
                    {
                        this.foreColor = (Color)current.Value;
                        continue;
                    }
                    if (current.Name == "BackColor")
                    {
                        this.backColor = (Color)current.Value;
                    }
                }
            }
        }
Exemple #3
0
        // Token: 0x06000401 RID: 1025 RVA: 0x0000BE44 File Offset: 0x0000AE44
        private PropertyID(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator enumerator = info.GetEnumerator();
            string name = "";
            string ns   = "";

            enumerator.Reset();
            while (enumerator.MoveNext())
            {
                SerializationEntry serializationEntry = enumerator.Current;
                if (serializationEntry.Name.Equals("NA"))
                {
                    SerializationEntry serializationEntry2 = enumerator.Current;
                    name = (string)serializationEntry2.Value;
                }
                else
                {
                    SerializationEntry serializationEntry3 = enumerator.Current;
                    if (serializationEntry3.Name.Equals("NS"))
                    {
                        SerializationEntry serializationEntry4 = enumerator.Current;
                        ns = (string)serializationEntry4.Value;
                    }
                }
            }
            this.m_name = new XmlQualifiedName(name, ns);
            this.m_code = (int)info.GetValue("CO", typeof(int));
        }
        private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
        {
            if (!JsonTypeReflector.FullyTrusted)
            {
                throw JsonSerializationException.Create(null, writer.ContainerPath, "Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.\r\nTo fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.".FormatWith(CultureInfo.InvariantCulture, value.GetType()), null);
            }
            this.OnSerializing(writer, contract, value);
            this._serializeStack.Add(value);
            this.WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);
            SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());

            value.GetObjectData(serializationInfo, this.Serializer._context);
            SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current      = enumerator.Current;
                JsonContract       contractSafe = this.GetContractSafe(current.Value);
                if (this.CheckForCircularReference(writer, current.Value, null, contractSafe, contract, member))
                {
                    writer.WritePropertyName(current.Name);
                    this.SerializeValue(writer, current.Value, contractSafe, null, contract, member);
                }
            }
            writer.WriteEndObject();
            this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
            this.OnSerialized(writer, contract, value);
        }
        protected XmlSchemaException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            this.res          = (string)info.GetValue("res", typeof(string));
            this.args         = (string[])info.GetValue("args", typeof(string[]));
            this.sourceUri    = (string)info.GetValue("sourceUri", typeof(string));
            this.lineNumber   = (int)info.GetValue("lineNumber", typeof(int));
            this.linePosition = (int)info.GetValue("linePosition", typeof(int));
            string str = null;
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                if (current.Name == "version")
                {
                    str = (string)current.Value;
                }
            }
            if (str == null)
            {
                this.message = CreateMessage(this.res, this.args);
            }
            else
            {
                this.message = null;
            }
        }
Exemple #6
0
        /// <summary>
        /// Deserializes the data on the provided stream and reconstitutes the graph of objects.
        /// </summary>
        /// <param name="serializationStream">The stream that contains the data to deserialize.</param>
        /// <returns>The top object of the deserialized graph.</returns>
        /// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception>
        public object Deserialize(Stream serializationStream)
        {
            if (null == serializationStream)
            {
                throw new ArgumentNullException("serializationStream", "The Stream serializationStream cannot be null.");
            }

            long      initialStreamPosition = serializationStream.Position;
            XmlReader xmlReader             = null;

            try {
                xmlReader = XmlReader.Create(serializationStream, this.createXmlReaderSettings());

                if (!xmlReader.IsStartElement())
                {
                    throw new SerializationException("Root element is missing.");
                }

                this.registeredReferenceObjects.Clear();

                IFormatterConverter converter  = new FormatterConverter();
                SerializationEntry  graphEntry = this.deserialize(xmlReader, converter);

                return(graphEntry.Value);
            }
            finally {
                if (null != xmlReader)
                {
                    serializationStream.Position = this.getStreamPosition(xmlReader, serializationStream, initialStreamPosition);
                    xmlReader.Close();
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Serializes an object, or graph of objects with the given root to the provided stream.
        /// </summary>
        /// <param name="serializationStream">
        /// The stream where the formatter puts the serialized data. This stream can reference a variety
        /// of backing stores (such as files, network, memory, and so on).
        /// </param>
        /// <param name="graph">
        /// The object, or root of the object graph, to serialize. All child objects of this root object
        /// are automatically serialized.
        /// </param>
        /// <exception cref="T:System.ArgumentNullException">The <para>serializationStream</para> cannot be null.</exception>
        /// <exception cref="T:System.ArgumentNullException">The <para>graph</para> cannot be null.</exception>
        public void Serialize(Stream serializationStream, object graph)
        {
            if (null == serializationStream)
            {
                throw new ArgumentNullException("serializationStream", "Stream serializationStream cannot be null.");
            }

            if (null == graph)
            {
                throw new ArgumentNullException("graph", "Object graph cannot be null.");
            }

            XmlWriter xmlWriter = null;

            try {
                xmlWriter = XmlWriter.Create(serializationStream, this.createXmlWriterSettings());

                this.registeredReferenceObjects.Clear();
                this.idGenerator = new ObjectIDGenerator();

                IFormatterConverter converter  = new FormatterConverter();
                SerializationEntry  graphEntry = this.createSerializationEntry(this.getName(graph.GetType()), graph, converter);
                this.serializeEntry(xmlWriter, graphEntry, converter);
                xmlWriter.WriteWhitespace(Environment.NewLine);
            }
            finally {
                if (null != xmlWriter)
                {
                    xmlWriter.Flush();
                }
            }
        }
Exemple #8
0
        /// <summary>
        /// helper function to deserialize the object from the serialization info.
        /// </summary>
        /// <param name="serializationEntry">the serialization entry.</param>
        /// <returns>the deserialized object.</returns>
        private static object DeserializeObject(SerializationEntry serializationEntry)
        {
            object deserializedObject = null;

            byte[] deserializeData = null;
            try
            {
                deserializeData = (byte[])serializationEntry.Value;
            }
            catch (Exception e)
            {
                BrokerTracing.TraceWarning("[PersistMessage] .DeserializeObject: the serialization entry.Value data type is, {0}, can not cast to byte[], the exception: {1}", serializationEntry.Value.GetType(), e);
            }

            if (deserializeData != null)
            {
                using (MemoryStream memoryStream = new MemoryStream(deserializeData))
                {
                    IFormatter formatter = (IFormatter) new BinaryFormatter();
                    deserializedObject = formatter.Deserialize(memoryStream);
                }
            }

            return(deserializedObject);
        }
        private XElement SerializeEntry(SerializationEntry entry)
        {
            var serialized = Serializator.AutoResolve(entry.Value);

            serialized.SetAttributeValue(XML_ATTRIBUTE_NAME, entry.Name);
            return(serialized);
        }
Exemple #10
0
        private void method_30(JsonWriter jsonWriter_0, ISerializable iserializable_0, JsonISerializableContract jsonISerializableContract_0, JsonProperty jsonProperty_0, JsonContainerContract jsonContainerContract_0, JsonProperty jsonProperty_1)
        {
            if (!Class139.Boolean_1)
            {
                throw JsonSerializationException.smethod_3(null, jsonWriter_0.String_0, "Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data.\r\nTo fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true.".smethod_0(CultureInfo.InvariantCulture, iserializable_0.GetType()), null);
            }
            this.method_15(jsonWriter_0, jsonISerializableContract_0, iserializable_0);
            this.list_0.Add(iserializable_0);
            this.method_19(jsonWriter_0, iserializable_0, jsonISerializableContract_0, jsonProperty_0, jsonContainerContract_0, jsonProperty_1);
            SerializationInfo info = new SerializationInfo(jsonISerializableContract_0.UnderlyingType, new FormatterConverter());

            iserializable_0.GetObjectData(info, base.jsonSerializer_0.streamingContext_0);
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current  = enumerator.Current;
                JsonContract       contract = this.method_5(current.Value);
                if (this.method_11(jsonWriter_0, current.Value, null, contract, jsonISerializableContract_0, jsonProperty_0))
                {
                    jsonWriter_0.WritePropertyName(current.Name);
                    this.method_7(jsonWriter_0, current.Value, contract, null, jsonISerializableContract_0, jsonProperty_0);
                }
            }
            jsonWriter_0.WriteEndObject();
            this.list_0.RemoveAt(this.list_0.Count - 1);
            this.method_16(jsonWriter_0, jsonISerializableContract_0, iserializable_0);
        }
Exemple #11
0
        private void serializeEntry(XmlWriter xmlWriter, SerializationEntry entry, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlWriter, "The 'xmlWriter' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            if (entry.Name.Contains("+"))
            {
                string[] nameParts = entry.Name.Split(new char[] { '+' });

                xmlWriter.WriteStartElement(nameParts[1]);

                xmlWriter.WriteStartAttribute("declaringType");
                xmlWriter.WriteValue(nameParts[0]);
                xmlWriter.WriteEndAttribute();
            }
            else
            {
                xmlWriter.WriteStartElement(entry.Name);
            }

            object entryValue = entry.Value;

            if (null == entryValue)
            {
                xmlWriter.WriteStartAttribute("isNull");
                xmlWriter.WriteValue(true);
                xmlWriter.WriteEndAttribute();
            }
            else
            {
                this.serializeObject(xmlWriter, entryValue, converter);
            }

            xmlWriter.WriteEndElement();
        }
Exemple #12
0
        private void Deserialize(SerializationInfo info, StreamingContext context)
        {
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                var pi = GetType().GetProperty(current.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, current.ObjectType, Type.EmptyTypes, null);
                if (pi != null)
                {
                    pi.SetValue(this, current.Value, null);
                }
                else
                {
                    switch (current.Name)
                    {
                    case "GroupState":
                        var state = (ListViewGroupState)current.Value;
                        if ((state & ListViewGroupState.Collapsed) != 0)
                        {
                            collapsed = true;
                        }
                        if ((state & ListViewGroupState.Collapsible) != 0)
                        {
                            collapsible = true;
                        }
                        if ((state & ListViewGroupState.Focused) != 0)
                        {
                            focused = true;
                        }
                        if ((state & ListViewGroupState.Hidden) != 0)
                        {
                            hidden = true;
                        }
                        if ((state & ListViewGroupState.NoHeader) != 0)
                        {
                            noheader = true;
                        }
                        if ((state & ListViewGroupState.Selected) != 0)
                        {
                            selected = true;
                        }
                        if ((state & ListViewGroupState.Subseted) != 0)
                        {
                            subseted = true;
                        }
                        if ((state & ListViewGroupState.SubsetLinkFocused) != 0)
                        {
                            subsetlinkfocused = true;
                        }
                        ListView.SetGroupState(this, state, true);
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        protected ReadOnlyPropertiesDictionary(SerializationInfo info, StreamingContext context)
        {
            this.m_hashtable = new Hashtable();
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                this.InnerHashtable[XmlConvert.DecodeName(current.Name)] = current.Value;
            }
        }
Exemple #14
0
        protected virtual void Deserialize(SerializationInfo info, StreamingContext context)
        {
            int itemLength = 0;
            SerializationInfoEnumerator serializationInfos = info.GetEnumerator();

            while (serializationInfos.MoveNext())
            {
                SerializationEntry entry = serializationInfos.Current;
                if (entry.Name == "Text")
                {
                    Text = entry.Value as String;
                }
                else if (entry.Name == "ImageIndex")
                {
                    imageIndex = (int)entry.Value;
                }
                else if (entry.Name == "SubItemCount")
                {
                    itemLength = (int)entry.Value;
                }
                else if (entry.Name == "BackColor")
                {
                    BackColor = (System.Drawing.Color)entry.Value;
                }
                else if (entry.Name == "Checked")
                {
                    Checked = (bool)entry.Value;
                }
                else if (entry.Name == "Font")
                {
                    Font = (Font)entry.Value;
                }
                else if (entry.Name == "ForeColor")
                {
                    ForeColor = (System.Drawing.Color)entry.Value;
                }
                else if (entry.Name == "UseItemStyleForSubItems")
                {
                    UseItemStyleForSubItems = (bool)entry.Value;
                }
            }
            if (itemLength > 0)
            {
                ListViewSubItem[] subItems = new ListViewSubItem[itemLength];
                for (int i = 1; i < itemLength; i++)
                {
                    ListViewSubItem item = info.GetValue("SubItem" + i, typeof(ListViewSubItem)) as ListViewSubItem;
                    item.owner  = this;
                    subItems[i] = item;
                }
                subItems[0]   = this.subItems[0];
                this.subItems = subItems;
            }
        }
Exemple #15
0
        internal static T Get <T>(SerializationEntry entry, string name, Func <SerializationEntry, T> getter)
        {
            Contract.Assert(name != null);
            Contract.Assert(getter != null);

            try {
                return(getter(entry));
            }
            catch (InvalidCastException ex) {
                throw new SerializationException(string.Format(CultureInfo.CurrentCulture, "Invalid '{0}' value.", name), ex);
            }
        }
        public static SerializationEntry?TryGetEntry(this SerializationInfo info, string name)
        {
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                if (string.Equals(current.Name, name, StringComparison.InvariantCulture))
                {
                    return(new SerializationEntry?(current));
                }
            }
            return(null);
        }
Exemple #17
0
        private SerializationEntry deserialize(XmlReader xmlReader, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlReader, "The 'xmlReader' argument cannot be null.");
            System.Diagnostics.Debug.Assert(xmlReader.IsStartElement(), "The XmlReader xmlReader position must be at the beginning of an element.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            string entryName     = xmlReader.Name;
            string declaringType = null;

            if (xmlReader.HasAttributes)
            {
                declaringType = xmlReader.GetAttribute("declaringType");
                if (!String.IsNullOrEmpty(declaringType))
                {
                    entryName = String.Format("{0}+{1}", declaringType, entryName);
                }
            }

            object entryValue = null;

            if (this.isNull(xmlReader))
            {
                entryValue = null;
                xmlReader.ReadStartElement();
            }
            else if (this.isHref(xmlReader))
            {
                int referencedId = this.readHref(xmlReader);
                entryValue = this.getRegisteredReferenceObject(referencedId);
                if (entryValue is IObjectReference)
                {
                    entryValue = ((IObjectReference)entryValue).GetRealObject(this.context);
                }

                xmlReader.ReadStartElement();
            }
            else
            {
                int               id = this.readId(xmlReader);
                List <int>        dimensionLengths = this.readArrayDimensions(xmlReader);
                Type              entryType        = this.readType(xmlReader);
                SerializationInfo info             = new SerializationInfo(entryType, converter);
                entryValue = this.deserialize(xmlReader, id, info, dimensionLengths, converter);
            }

            SerializationEntry entry = this.createSerializationEntry(entryName, entryValue, converter);

            return(entry);
        }
Exemple #18
0
        protected bool SerializeSerializable(ISerializable obj, StringBuilder builder)
        {
            IDictionary       anObject = this.ordered ? ((IDictionary) new OrderedDictionary()) : ((IDictionary) new Hashtable());
            SerializationInfo info     = new SerializationInfo(obj.GetType(), new FormatterConverter());

            obj.GetObjectData(info, new StreamingContext(StreamingContextStates.Persistence));
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                anObject[current.Name] = current.Value;
            }
            return(this.SerializeObject(anObject, builder));
        }
            public Wrapper(SerializationInfo serializationInfo, StreamingContext streamingContext)
            {
                //try
                //{
                //    UseFastSerialization = true;
                //    DateTime start = DateTime.Now;

                //    using (Slyce.Common.SerializationReader reader = new SerializationReader((byte[])serializationInfo.GetValue("d", typeof(byte[]))))
                //    {
                //        //byte[] oo = (byte[])serializationInfo.GetValue("d", typeof(byte[]));
                //        _Version = reader.ReadInt32();
                //        UseFastSerialization = true;
                //        Databases = (List<Model.Database>)reader.ReadObject();
                //        // TODO: Deserialize child objects
                //        DateTime end = DateTime.Now;
                //        TimeSpan ts = end - start;
                //        string dd = string.Format("{0},{1}", ts.Seconds, ts.Milliseconds);
                //        dd = "";
                //        return;
                //    }
                //}
                //catch (SerializationException ex)
                //{
                // Do nothing
                UseFastSerialization = false;
                //}
                System.Collections.IEnumerator enumerator = serializationInfo.GetEnumerator();

                while (enumerator.MoveNext())
                {
                    SerializationEntry entry = (SerializationEntry)enumerator.Current;

                    switch (entry.ObjectType.Name)
                    {
                    case "Int32":
                        _Version = (int)entry.Value;
                        break;

                    case "List`1":
                        Databases = (List <Model.Database>)entry.Value;
                        break;

                    default:
                        throw new NotImplementedException("Not coded yet: " + entry.ObjectType.Name);
                    }
                }
                FileVersionCurrent = Version;
            }
Exemple #20
0
        private Array deserializeArray(XmlReader xmlReader, int id, Type elementType, List <int> dimensionLengths, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlReader, "The 'xmlReader' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != elementType, "The 'elementType' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != dimensionLengths, "The 'dimensionLengths' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            Array array = Array.CreateInstance(elementType, dimensionLengths.ToArray());

            // Register array
            this.registeredReferenceObjects.Add(array, id);

            int itemCount = 1;

            foreach (int length in dimensionLengths)
            {
                itemCount *= length;
            }

            int rank = array.Rank;

            int[] indices = new int[rank];
            for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
            {
                SerializationEntry itemEntry = this.deserialize(xmlReader, converter);
                array.SetValue(itemEntry.Value, indices);

                for (int dimensionIndex = rank - 1; dimensionIndex >= 0; dimensionIndex--)
                {
                    if (indices[dimensionIndex] < dimensionLengths[dimensionIndex] - 1)
                    {
                        indices[dimensionIndex]++;
                        break;
                    }
                    else
                    {
                        indices[dimensionIndex] = 0;
                    }
                }
            }

            if (0 == itemCount && XmlNodeType.Element == xmlReader.NodeType)
            {
                xmlReader.ReadStartElement();
            }

            return(array);
        }
Exemple #21
0
        private void Deserialize(SerializationInfo info, StreamingContext context)
        {
            int num = 0;
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                if (current.Name == "Header")
                {
                    this.Header = (string)current.Value;
                }
                else
                {
                    if (current.Name == "HeaderAlignment")
                    {
                        this.HeaderAlignment = (HorizontalAlignment)current.Value;
                        continue;
                    }
                    if (current.Name == "Tag")
                    {
                        this.Tag = current.Value;
                        continue;
                    }
                    if (current.Name == "ItemsCount")
                    {
                        num = (int)current.Value;
                        continue;
                    }
                    if (current.Name == "Name")
                    {
                        this.Name = (string)current.Value;
                    }
                }
            }
            if (num > 0)
            {
                ListViewItem[] items = new ListViewItem[num];
                for (int i = 0; i < num; i++)
                {
                    items[i] = (ListViewItem)info.GetValue("Item" + i, typeof(ListViewItem));
                }
                this.Items.AddRange(items);
            }
        }
Exemple #22
0
        public static void readSaveData(ref SerializationInfo info, ref StreamingContext context)
        {
            SerializationInfoEnumerator infoEnum = info.GetEnumerator();
            Hashtable values = new Hashtable();

            while (infoEnum.MoveNext())
            {
                SerializationEntry val = infoEnum.Current;
                values.Add(val.Name, val.Value);
            }
            foreach (Skill s in allSkills)
            {
                if (values.Contains(s.name))
                {
                    s.setRanks((int)values[s.name]);
                }
            }
        }
        protected DictionaryObjectViewModel(SerializationInfo info, StreamingContext context)
            : this()
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            SerializationInfoEnumerator enumerator = info.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                string             str     = null;
                object[]           value   = current.Value as object[];
                str = (value == null ? current.Value.ToString() : JsonConvert.SerializeObject(value));//JsonSerializer.SerializeToString<object[]>(value));
                this.Dictionary[current.Name] = str;
            }
        }
        /// <summary>
        /// Deserialize a previously serialized game object.
        /// </summary>

        static void DeserializeHierarchy(this GameObject go, DataNode root)
        {
            SerializationEntry ent = new SerializationEntry();

            ent.go   = go;
            ent.node = root;
            mSerList.Add(ent);

            Transform trans = go.transform;

            trans.localPosition    = root.GetChild <Vector3>("position", trans.localPosition);
            trans.localEulerAngles = root.GetChild <Vector3>("rotation", trans.localEulerAngles);
            trans.localScale       = root.GetChild <Vector3>("scale", trans.localScale);
            go.layer = root.GetChild <int>("layer", go.layer);

            DataNode childNode = root.GetChild("Children");

            if (childNode != null && childNode.children.size > 0)
            {
                for (int i = 0; i < childNode.children.size; ++i)
                {
                    DataNode   node   = childNode.children[i];
                    GameObject child  = null;
                    GameObject prefab = UnityTools.Load <GameObject>(node.GetChild <string>("prefab"));
                    if (prefab != null)
                    {
                        child = GameObject.Instantiate(prefab) as GameObject;
                    }
                    if (child == null)
                    {
                        child = new GameObject();
                    }
                    child.name = node.name;

                    Transform t = child.transform;
                    t.parent        = trans;
                    t.localPosition = Vector3.zero;
                    t.localRotation = Quaternion.identity;
                    t.localScale    = Vector3.one;

                    child.DeserializeHierarchy(node);
                }
            }
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            ISerializable serializableException = value as ISerializable;

            if (serializableException == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Expected an ISerializable type, got {0} instead.", value.GetType()));
            }
            else
            {
                writer.WriteStartObject();
                SerializationInfo serializationInfo = new SerializationInfo(value.GetType(), new FormatterConverter());
                serializableException.GetObjectData(serializationInfo, serializer.Context);
                SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    SerializationEntry current = enumerator.Current;
                    writer.WritePropertyName(current.Name);
                    if (ExceptionConverter.IsPrimitive(current.ObjectType) ||
                        serializer.Converters.Where(c => c.GetType() != typeof(ExceptionConverter))
                        .Any(c => c.CanConvert(current.ObjectType)))
                    {
                        // Do not stringify primitives
                        serializer.Serialize(writer, current.Value);
                    }
                    else
                    {
                        // Stringify all complex types.
                        ObjectConverter.Instance.WriteJson(writer, current.Value, serializer);
                    }
                }
                writer.WriteEndObject();
            }
        }
Exemple #26
0
    public SerializableEntity(SerializationInfo info, StreamingContext context)
    {
        _entity = new T();
        PropertyInfo[] properties = _entity.GetType().GetProperties();

        SerializationInfoEnumerator enumerator = info.GetEnumerator();

        while (enumerator.MoveNext())
        {
            SerializationEntry se = enumerator.Current;
            foreach (PropertyInfo pi in properties)
            {
                if (pi.Name == se.Name)
                {
                    pi.SetValue(_entity, info.GetValue(se.Name, pi.PropertyType), null);
                }
            }
        }
    }
Exemple #27
0
        private void serializeArray(XmlWriter xmlWriter, Array array, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlWriter, "The 'xmlWriter' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != array, "The 'array' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            this.writeType(xmlWriter, array, this.assemblyFormat);

            int rank      = array.Rank;
            int itemCount = 1;

            int[] upperBounds = new int[rank];
            for (int i = 0; i < rank; i++)
            {
                upperBounds[i] = array.GetUpperBound(i);
                itemCount     *= upperBounds[i] + 1;
            }

            SerializationEntry[] entries = new SerializationEntry[itemCount];             // Return value
            int[] indices = new int[rank];
            for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
            {
                entries[itemIndex] = this.createSerializationEntry("Item", array.GetValue(indices), converter);

                for (int dimensionIndex = rank - 1; dimensionIndex >= 0; dimensionIndex--)
                {
                    if (indices[dimensionIndex] < upperBounds[dimensionIndex])
                    {
                        indices[dimensionIndex]++;
                        break;
                    }
                    else
                    {
                        indices[dimensionIndex] = 0;
                    }
                }
            }

            foreach (SerializationEntry entry in entries)
            {
                this.serializeEntry(xmlWriter, entry, converter);
            }
        }
Exemple #28
0
        private object deserializeObject(XmlReader xmlReader, int id, Type objectType, SerializationInfo info, IFormatterConverter converter)
        {
            System.Diagnostics.Debug.Assert(null != xmlReader, "The 'xmlReader' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != objectType, "The 'objectType' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != info, "The 'info' argument cannot be null.");
            System.Diagnostics.Debug.Assert(null != converter, "The 'converter' argument cannot be null.");

            object deserialized = null;             // Return value

            if (!objectType.IsValueType)
            {
                deserialized = FormatterServices.GetUninitializedObject(objectType);

                // Register object
                this.registeredReferenceObjects.Add(deserialized, id);
            }

            bool hasSerializableMembers = this.hasSerializableMembers(objectType, this.context);

            if (hasSerializableMembers)
            {
                while (xmlReader.IsStartElement())
                {
                    SerializationEntry entry = this.deserialize(xmlReader, converter);
                    info.AddValue(entry.Name, entry.Value, entry.ObjectType);
                }
            }
            else
            {
                if (XmlNodeType.Element == xmlReader.NodeType)
                {
                    xmlReader.ReadStartElement();
                }
            }

            ISurrogateSelector      selector  = null;
            ISerializationSurrogate surrogate = this.getSerializationSurrogate(objectType, out selector);

            deserialized = surrogate.SetObjectData(deserialized, info, this.context, selector);

            return(deserialized);
        }
Exemple #29
0
 public static void deserialize(ref SerializationInfo info, ref StreamingContext context)
 {
     if (Main.saveVersionFromDisk >= 23)
     {
         SerializationInfoEnumerator infoEnum = info.GetEnumerator();
         Hashtable values = new Hashtable();
         while (infoEnum.MoveNext())
         {
             SerializationEntry val = infoEnum.Current;
             values.Add(val.Name, val.Value);
         }
         foreach (TutorialList list in allTutorials)
         {
             if (values.Contains(list.saveID))
             {
                 list.lastStep = (int)values[list.saveID];
             }
         }
     }
 }
        private void SerializeISerializable(JsonWriter writer, ISerializable value, JsonISerializableContract contract)
        {
            contract.InvokeOnSerializing(value, base.Serializer.Context);
            SerializeStack.Add(value);
            writer.WriteStartObject();
            SerializationInfo serializationInfo = new SerializationInfo(contract.UnderlyingType, new FormatterConverter());

            value.GetObjectData(serializationInfo, base.Serializer.Context);
            SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current = enumerator.Current;
                writer.WritePropertyName(current.Name);
                SerializeValue(writer, current.Value, GetContractSafe(current.Value), null, null);
            }
            writer.WriteEndObject();
            SerializeStack.RemoveAt(SerializeStack.Count - 1);
            contract.InvokeOnSerialized(value, base.Serializer.Context);
        }