Exemple #1
0
        private object DeserializeObjectFromCurrent()
        {
            var identifier = CurrentNode["Identifier"].Value;

            if (UseReferences && ReferenceObjects.ContainsKey(identifier))
            {
                return(ReferenceObjects[identifier]);
            }
            if (CurrentNode["CLRType"] == null)
            {
                return(null);
            }
            var clrType        = CurrentNode["CLRType"].Value;
            var instance       = TypeResolver.CreateInstance(clrType, identifier);
            var ufSerializable = instance as IUFSerializable;

            if (ufSerializable != null)
            {
                if (UseReferences)
                {
                    ReferenceObjects.Add(identifier, ufSerializable);
                }
                ufSerializable.Read(this);
            }
            return(instance);
        }
Exemple #2
0
        public void SerializeObject(string name, object value)
        {
            if (value is int)
            {
                SerializeInt(name, (int)value);
                return;
            }
            if (value is string)
            {
                SerializeString(name, (string)value);
                return;
            }
            if (value is bool)
            {
                SerializeBool(name, (bool)value);
                return;
            }
            if (value is Vector2)
            {
                SerializeVector2(name, (Vector2)value);
                return;
            }
            if (value is Vector3)
            {
                SerializeVector3(name, (Vector3)value);
                return;
            }
            if (value is Quaternion)
            {
                SerializeQuaternion(name, (Quaternion)value);
                return;
            }
            if (value is double)
            {
                SerializeDouble(name, (double)value);
                return;
            }
            var cls = new JSONClass();

            if (name == null)
            {
                CurrentNode.Add(cls);
            }
            else
            {
                CurrentNode.Add(name, cls);
            }
            Push(name, cls);

            var serializable = value as IUFSerializable;

            if (serializable != null)
            {
                SerializeString("Identifier", serializable.Identifier);
                if (!UseReferences || !ReferenceObjects.ContainsKey(serializable.Identifier))
                {
                    SerializeString("CLRType", TypeResolver.SetType(value.GetType()));

                    if (UseReferences)
                    {
                        ReferenceObjects.Add(serializable.Identifier, serializable);
                    }

                    serializable.Write(this);
                }
            }
            Pop();
        }