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); }
private static IEnumerable DeserializeCollection(Tag tag, IEnumerable collection, System.Type declaredType) { bool flag1 = tag.Values.Count > 0; bool flag2 = tag.Children.Count > 0; if (collection == null) { collection = !declaredType.IsArray ? ReflectionHelper.Instantiate(declaredType) as IEnumerable : (IEnumerable)Array.CreateInstance(declaredType.GetElementType(), 0); } if (!flag1 && !flag2) { return(collection); } System.Type type1 = collection.GetType(); bool flag3 = collection is IList; bool isArray = type1.IsArray; bool flag4 = ReflectionHelper.IsGenericSet(type1); System.Type type2 = isArray ? type1.GetElementType() : type1.GetGenericArguments()[0]; bool simpleType = SdlSerializer.IsCoercible(type2); DynamicMethodDelegate dynamicMethodDelegate = (DynamicMethodDelegate)null; if (flag4) { dynamicMethodDelegate = ReflectionHelper.GetDelegate(type1.GetMethod("Add")); } if (flag1 && flag2) { throw new SdlSerializationException(Resources.IllegalCollectionStructure, type1, tag.Name); } if (isArray) { int length = flag1 ? tag.Values.Count : tag.Children.Count; collection = (IEnumerable)Array.CreateInstance(type2, length); } int num = 0; if (flag1) { foreach (object coerced in (IEnumerable <object>)tag.Values) { object obj1 = SdlSerializer.DeCoerce(coerced, type2); if (isArray) { ((IList)collection)[num++] = obj1; } else if (flag4) { object obj2 = dynamicMethodDelegate((object)collection, new object[1] { obj1 }); } else { if (!flag3) { throw new NotImplementedException(); } ((IList)collection).Add(obj1); } } } else { foreach (Tag tag1 in (IEnumerable <Tag>)tag.Children) { object obj1 = SdlSerializer.IsNull(tag1) ? (object)null : SdlSerializer.DeserializeChild(tag1, type2, (object)null, simpleType); if (isArray) { ((IList)collection)[num++] = obj1; } else if (flag4) { object obj2 = dynamicMethodDelegate((object)collection, new object[1] { obj1 }); } else { if (!flag3) { throw new NotImplementedException(); } ((IList)collection).Add(obj1); } } } return(collection); }