From df66bfb6e30e88a8cfa84124053a14cd814cde81 Mon Sep 17 00:00:00 2001 From: Ilya P Date: Sat, 29 Oct 2016 09:53:45 +0300 Subject: [PATCH] bug-fix --- TeleSharp.TL/TLVector.cs | 47 ++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/TeleSharp.TL/TLVector.cs b/TeleSharp.TL/TLVector.cs index 8f35b7d..bf3d025 100644 --- a/TeleSharp.TL/TLVector.cs +++ b/TeleSharp.TL/TLVector.cs @@ -10,7 +10,7 @@ namespace TeleSharp.TL public class TLVector : TLObject { [TLObject(481674261)] - public List lists = new List() ; + public List lists = new List(); public override int Constructor { get @@ -22,21 +22,21 @@ namespace TeleSharp.TL public override void DeserializeBody(BinaryReader br) { int count = br.ReadInt32(); - for(int i= 0;i< count;i++) + for (var i = 0; i < count; i++) { if (typeof(T) == typeof(int)) { - lists.Add((T)Convert.ChangeType(br.ReadInt32(),typeof(T))); + lists.Add((T)Convert.ChangeType(br.ReadInt32(), typeof(T))); } - else if (typeof(T)==typeof(long)) + else if (typeof(T) == typeof(long)) { lists.Add((T)Convert.ChangeType(br.ReadInt64(), typeof(T))); } - else if (typeof(T) ==typeof(string)) + else if (typeof(T) == typeof(string)) { lists.Add((T)Convert.ChangeType(StringUtil.Deserialize(br), typeof(T))); } - else if(typeof(T)==typeof(double)) + else if (typeof(T) == typeof(double)) { lists.Add((T)Convert.ChangeType(br.ReadDouble(), typeof(T))); } @@ -53,13 +53,38 @@ namespace TeleSharp.TL public override void SerializeBody(BinaryWriter bw) { - bw.Write(Constructor); + bw.Write(Constructor); bw.Write(lists.Count()); - foreach (var item in lists.Cast()) - { - item.SerializeBody(bw); - } + foreach (var item in lists) + { + if (typeof(T) == typeof(int)) + { + var res = (int)Convert.ChangeType(item, typeof(int)); + + bw.Write(res); + } + else if (typeof(T) == typeof(long)) + { + var res = (long)Convert.ChangeType(item, typeof(long)); + bw.Write(res); + } + else if (typeof(T) == typeof(string)) + { + var res = (string)(Convert.ChangeType(item, typeof(string))); + StringUtil.Serialize(res, bw); + } + else if (typeof(T) == typeof(double)) + { + var res = (double)Convert.ChangeType(item, typeof(double)); + bw.Write(res); + } + else if (typeof(T).BaseType == typeof(TLObject)) + { + var res = (TLObject) (Convert.ChangeType(item, typeof (TLObject))); + res.SerializeBody(bw); + } + } } } }