private static List <T> GetList <T>(PacketReader reader, IPacketConverter converter) { var itm = reader.GetList(); var len = itm.Count; if (len < 1) { return(new List <T>()); } var lst = new List <T>(len); var gen = converter as IPacketConverter <T>; try { if (gen != null) { for (int i = 0; i < len; i++) { lst.Add(gen.GetValue(itm[i].element)); } } else { for (int i = 0; i < len; i++) { lst.Add((T)converter.GetValue(itm[i].element)); } } } catch (Exception ex) when(PacketException.WrapFilter(ex)) { throw PacketException.ConvertError(ex); } return(lst); }
private static T[] GetArray <T>(PacketReader reader, IPacketConverter converter) { var itm = reader.GetList(); var len = itm.Count; if (len < 1) { return(new T[0]); } var arr = new T[len]; var gen = converter as IPacketConverter <T>; try { if (gen != null) { for (int i = 0; i < len; i++) { arr[i] = gen.GetValue(itm[i].element); } } else { for (int i = 0; i < len; i++) { arr[i] = (T)converter.GetValue(itm[i].element); } } } catch (Exception ex) when(PacketException.WrapFilter(ex)) { throw PacketException.ConvertError(ex); } return(arr); }
private IEnumerator <T> Enumerator() { var lst = reader.GetList(); for (int i = 0; i < lst.Count; i++) { yield return((T)lst[i].GetValueMatch(typeof(T), level, info)); } }
IEnumerator IEnumerable.GetEnumerator() { var def = converter.Length; if (def < 1) { return(Enumerator(reader.GetList(), converter)); } var ele = reader.element; var sum = Math.DivRem(ele.length, def, out var rem); if (rem != 0) { throw PacketException.Overflow(); } return(Enumerator(ele.buffer, ele.offset, sum, def, converter)); }