Esempio n. 1
0
        private static object DeserializeChild(Tag childTag, System.Type type, object existingInstance, bool simpleType)
        {
            string typeName = childTag["type"] as string;

            if (typeName != null)
            {
                if (SdlSerializer.Compiling)
                {
                    typeName = typeName.Replace(", FezEngine", ", FezContentPipeline");
                }
                type       = System.Type.GetType(typeName);
                simpleType = SdlSerializer.IsCoercible(type);
            }
            object existingInstance1 = existingInstance;

            if (SdlSerializer.IsNull(childTag))
            {
                existingInstance1 = (object)null;
            }
            else if (simpleType)
            {
                existingInstance1 = SdlSerializer.DeCoerce(childTag.Value, type);
            }
            else if (type.Name == "Color")
            {
                existingInstance1 = (object)(childTag.Values.Count == 4 ? new Color((int)(byte)(int)childTag.Values[0], (int)(byte)(int)childTag.Values[1], (int)(byte)(int)childTag.Values[2], (int)(byte)(int)childTag.Values[3]) : new Color((int)(byte)(int)childTag.Values[0], (int)(byte)(int)childTag.Values[1], (int)(byte)(int)childTag.Values[2]));
            }
            else if (type.Name == "Vector2")
            {
                existingInstance1 = (object)new Vector2((float)childTag.Values[0], (float)childTag.Values[1]);
            }
            else if (type.Name == "Vector3")
            {
                existingInstance1 = (object)new Vector3(Convert.ToSingle(childTag.Values[0]), Convert.ToSingle(childTag.Values[1]), Convert.ToSingle(childTag.Values[2]));
            }
            else if (type.Name == "Vector4")
            {
                existingInstance1 = (object)new Vector4((float)childTag.Values[0], (float)childTag.Values[1], (float)childTag.Values[2], (float)childTag.Values[3]);
            }
            else if (type.Name == "Quaternion")
            {
                existingInstance1 = (object)new Quaternion((float)childTag.Values[0], (float)childTag.Values[1], (float)childTag.Values[2], (float)childTag.Values[3]);
            }
            else if (type.Name == "Matrix")
            {
                existingInstance1 = (object)SdlSerializer.DeserializeMatrix(childTag);
            }
            else if (ReflectionHelper.IsGenericDictionary(type))
            {
                SdlSerializer.DeserializeDictionary(childTag, existingInstance1 as IDictionary, type);
            }
            else
            {
                existingInstance1 = !ReflectionHelper.IsGenericCollection(type) ? SdlSerializer.DeserializeInternal(type, childTag, existingInstance1) : (object)SdlSerializer.DeserializeCollection(childTag, existingInstance1 as IEnumerable, type);
            }
            return(existingInstance1);
        }