Make TLVector Implement IList

This commit is contained in:
Afshin Arani 2017-11-09 01:52:29 -08:00
parent 3ba3ea53fd
commit e708464857
3 changed files with 70 additions and 12 deletions

View file

@ -76,7 +76,7 @@ namespace TLSharp.Core
await _sender.Send(invokewithLayer);
await _sender.Receive(invokewithLayer);
dcOptions = ((TLConfig)invokewithLayer.Response).dc_options.lists;
dcOptions = ((TLConfig)invokewithLayer.Response).dc_options.ToList();
return true;
}

View file

@ -171,7 +171,7 @@ namespace TLSharp.Tests
var result = await client.GetContactsAsync();
var user = result.users.lists
var user = result.users
.OfType<TLUser>()
.FirstOrDefault(x => x.phone == normalizedNumber);
@ -192,7 +192,7 @@ namespace TLSharp.Tests
await client.ConnectAsync();
var dialogs = (TLDialogs) await client.GetUserDialogsAsync();
var chat = dialogs.chats.lists
var chat = dialogs.chats
.OfType<TLChannel>()
.FirstOrDefault(c => c.title == "TestGroup");
@ -207,7 +207,7 @@ namespace TLSharp.Tests
var result = await client.GetContactsAsync();
var user = result.users.lists
var user = result.users
.OfType<TLUser>()
.FirstOrDefault(x => x.phone == NumberToSendMessage);
@ -223,7 +223,7 @@ namespace TLSharp.Tests
var result = await client.GetContactsAsync();
var user = result.users.lists
var user = result.users
.OfType<TLUser>()
.FirstOrDefault(x => x.phone == NumberToSendMessage);
@ -245,13 +245,13 @@ namespace TLSharp.Tests
var result = await client.GetContactsAsync();
var user = result.users.lists
var user = result.users
.OfType<TLUser>()
.FirstOrDefault(x => x.phone == NumberToSendMessage);
var inputPeer = new TLInputPeerUser() { user_id = user.id };
var res = await client.SendRequestAsync<TLMessagesSlice>(new TLRequestGetHistory() { peer = inputPeer });
var document = res.messages.lists
var document = res.messages
.OfType<TLMessage>()
.Where(m => m.media != null)
.Select(m => m.media)
@ -280,7 +280,7 @@ namespace TLSharp.Tests
var result = await client.GetContactsAsync();
var user = result.users.lists
var user = result.users
.OfType<TLUser>()
.FirstOrDefault(x => x.id == 5880094);
@ -352,7 +352,7 @@ namespace TLSharp.Tests
var result = await client.SearchUserAsync(UserNameToSendMessage);
var user = result.users.lists
var user = result.users
.Where(x => x.GetType() == typeof(TLUser))
.OfType<TLUser>()
.FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@'));
@ -361,7 +361,7 @@ namespace TLSharp.Tests
{
var contacts = await client.GetContactsAsync();
user = contacts.users.lists
user = contacts.users
.Where(x => x.GetType() == typeof(TLUser))
.OfType<TLUser>()
.FirstOrDefault(x => x.username == UserNameToSendMessage.TrimStart('@'));

View file

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -7,10 +8,13 @@ using System.Threading.Tasks;
namespace TeleSharp.TL
{
public class TLVector<T> : TLObject
public class TLVector<T> : TLObject, IList<T>
{
[TLObject(481674261)]
public List<T> lists = new List<T>();
private List<T> lists = new List<T>();
public T this[int index] { get => ((IList<T>)lists)[index]; set => ((IList<T>)lists)[index] = value; }
public override int Constructor
{
get
@ -19,6 +23,30 @@ namespace TeleSharp.TL
}
}
public int Count => ((IList<T>)lists).Count;
public bool IsReadOnly => ((IList<T>)lists).IsReadOnly;
public void Add(T item)
{
((IList<T>)lists).Add(item);
}
public void Clear()
{
((IList<T>)lists).Clear();
}
public bool Contains(T item)
{
return ((IList<T>)lists).Contains(item);
}
public void CopyTo(T[] array, int arrayIndex)
{
((IList<T>)lists).CopyTo(array, arrayIndex);
}
public override void DeserializeBody(BinaryReader br)
{
int count = br.ReadInt32();
@ -51,6 +79,31 @@ namespace TeleSharp.TL
}
}
public IEnumerator<T> GetEnumerator()
{
return ((IList<T>)lists).GetEnumerator();
}
public int IndexOf(T item)
{
return ((IList<T>)lists).IndexOf(item);
}
public void Insert(int index, T item)
{
((IList<T>)lists).Insert(index, item);
}
public bool Remove(T item)
{
return ((IList<T>)lists).Remove(item);
}
public void RemoveAt(int index)
{
((IList<T>)lists).RemoveAt(index);
}
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
@ -86,5 +139,10 @@ namespace TeleSharp.TL
}
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IList<T>)lists).GetEnumerator();
}
}
}