private static void SerializeChild(string name, object value, System.Type type, bool simpleType, SerializationAttribute attr, Tag parent) { Tag tag = new Tag(name); if ((!simpleType || type == typeof(object)) && (value != null && !ReflectionHelper.IsNullable(type)) && value.GetType() != type) { type = value.GetType(); tag["type"] = (object)ReflectionHelper.GetShortAssemblyQualifiedName(type); } if (simpleType) { tag.AddValue(value); } else if (type == typeof(Color)) { Color color = (Color)value; SdlSerializer.AddValueList(tag, (object)color.R, (object)color.G, (object)color.B); if ((int)color.A != (int)byte.MaxValue) { tag.AddValue((object)color.A); } } else if (type == typeof(Vector2)) { Vector2 vector2 = (Vector2)value; SdlSerializer.AddValueList(tag, (object)vector2.X, (object)vector2.Y); } else if (type == typeof(Vector3)) { Vector3 vector3 = (Vector3)value; SdlSerializer.AddValueList(tag, (object)vector3.X, (object)vector3.Y, (object)vector3.Z); } else if (type == typeof(Vector4)) { Vector4 vector4 = (Vector4)value; SdlSerializer.AddValueList(tag, (object)vector4.X, (object)vector4.Y, (object)vector4.Z, (object)vector4.W); } else if (type == typeof(Quaternion)) { Quaternion quaternion = (Quaternion)value; SdlSerializer.AddValueList(tag, (object)quaternion.X, (object)quaternion.Y, (object)quaternion.Z, (object)quaternion.W); } else if (type == typeof(Matrix)) { SdlSerializer.SerializeMatrix(tag, (Matrix)value); } else if (ReflectionHelper.IsGenericDictionary(type)) { SdlSerializer.SerializeDictionary(tag, value as IDictionary, attr.CollectionItemName); } else if (ReflectionHelper.IsGenericCollection(type)) { SdlSerializer.SerializeCollection(tag, value as IEnumerable, attr.CollectionItemName); } else { SdlSerializer.SerializeInternal(value, type, tag); } parent.AddChild(tag); }
private static void SerializeMatrix(Tag tag, Matrix matrix) { Tag tag1 = new Tag("content"); tag.AddChild(tag1); SdlSerializer.AddValueList(tag1, (object)matrix.M11, (object)matrix.M12, (object)matrix.M13, (object)matrix.M14); Tag tag2 = new Tag("content"); tag.AddChild(tag2); SdlSerializer.AddValueList(tag2, (object)matrix.M21, (object)matrix.M22, (object)matrix.M23, (object)matrix.M24); Tag tag3 = new Tag("content"); tag.AddChild(tag3); SdlSerializer.AddValueList(tag3, (object)matrix.M31, (object)matrix.M32, (object)matrix.M33, (object)matrix.M34); Tag tag4 = new Tag("content"); tag.AddChild(tag4); SdlSerializer.AddValueList(tag4, (object)matrix.M41, (object)matrix.M42, (object)matrix.M43, (object)matrix.M44); }
private static void AddValueList(Tag tag, params object[] list) { SdlSerializer.AddValueList(tag, (IList)list); }