/// <summary> /// 获取好友列表 /// </summary> /// <exception cref="InvalidDataException">数据流格式错误或为 null</exception> /// <exception cref="EndOfStreamException">无法读取数据, 因为已经读取到数据流末尾</exception> /// <returns>获取成功返回 <see cref="FriendInfoCollection"/>, 失败返回 <see langword="null"/></returns> public FriendInfoCollection GetFriendList() { string data = CQP.CQ_getFriendList(this.AppInfo.AuthCode, false).ToString(_defaultEncoding); if (string.IsNullOrEmpty(data)) { #if DEBUG throw new InvalidDataException("获取的数据流格式无效"); #else return(null); #endif } try { return(new FriendInfoCollection(this, data)); } catch { #if DEBUG throw; #else return(null); #endif } }
/// <summary> /// 获取好友列表 /// </summary> /// <returns>获取成功返回 <see cref="List{FriendInfo}"/>, 否则返回 null</returns> public List <FriendInfo> GetFriendList() { string result = CQP.CQ_getFriendList(_authCode, false).ToString(_defaultEncoding); if (string.IsNullOrEmpty(result)) { return(null); } #region --其他_转换_文本到好友列表信息a-- using (BinaryReader reader = new BinaryReader(new MemoryStream(Convert.FromBase64String(result)))) { if (reader.Length() < 4) { return(null); } List <FriendInfo> friends = new List <FriendInfo> (); for (int i = 0, len = reader.ReadInt32_Ex(); i < len; i++) { FriendInfo temp = new FriendInfo(); if (reader.Length() <= 0) { return(null); } #region --其他_转换_ansihex到好友信息-- using (BinaryReader tempReader = new BinaryReader(new MemoryStream(reader.ReadToken_Ex()))) { if (tempReader.Length() < 12) { return(null); } temp.Id = tempReader.ReadInt64_Ex(); temp.Nick = tempReader.ReadString_Ex(_defaultEncoding); temp.Note = tempReader.ReadString_Ex(_defaultEncoding); } #endregion friends.Add(temp); } return(friends); } #endregion }