Пример #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);
        }
Пример #2
0
        private static void DeserializeDictionary(Tag tag, IDictionary dictionary, System.Type declaredType)
        {
            bool flag = tag.Children.Count == 0;

            if (dictionary == null)
            {
                dictionary = ReflectionHelper.Instantiate(declaredType) as IDictionary;
            }
            System.Type[] genericArguments = dictionary.GetType().GetGenericArguments();
            System.Type   type1            = genericArguments[0];
            System.Type   type2            = genericArguments[1];
            if (flag)
            {
                foreach (string index in (IEnumerable <string>)tag.Attributes.Keys)
                {
                    object key = SdlSerializer.DeCoerce((object)index, type1);
                    object obj = SdlSerializer.DeCoerce(tag[index], type2);
                    SdlSerializer.SafeAddToDictionary(dictionary, key, obj);
                }
            }
            else
            {
                foreach (Tag tag1 in (IEnumerable <Tag>)tag.Children)
                {
                    object coerced = tag1["key"];
                    Tag    child   = tag1.GetChild("key");
                    if (!(coerced != null ^ child != null))
                    {
                        throw new SdlSerializationException(Resources.IllegalCollectionStructure, dictionary.GetType(), tag.Name);
                    }
                    if (coerced != null)
                    {
                        object key = SdlSerializer.DeCoerce(coerced, type1);
                        object obj = SdlSerializer.DeserializeInternal(type2, tag1, (object)null);
                        SdlSerializer.SafeAddToDictionary(dictionary, key, obj);
                    }
                    else
                    {
                        object key        = SdlSerializer.DeserializeInternal(type1, child, (object)null);
                        bool   simpleType = SdlSerializer.IsCoercible(type2);
                        bool   valueFound;
                        object obj = SdlSerializer.DeserializeChild("value", (object)null, type2, simpleType, SdlSerializer.DefaultAttribute, tag1, out valueFound);
                        SdlSerializer.SafeAddToDictionary(dictionary, key, obj);
                    }
                }
            }
        }
Пример #3
0
 public static T Deserialize <T>(string filePath)
 {
     return((T)SdlSerializer.DeserializeInternal((System.Type)null, new Tag("content").ReadFile(filePath).Children[0], (object)null));
 }
Пример #4
0
 public static T Deserialize <T>(StreamReader reader)
 {
     return((T)SdlSerializer.DeserializeInternal((System.Type)null, new Tag("content").Read(reader).Children[0], (object)null));
 }