Пример #1
0
 /// <summary>
 /// Retrieves the Misc field (if available) from the serialized given object
 /// </summary>
 /// <typeparam name="T">subtype of BaseEntity</typeparam>
 /// <param name="resp">serialized object which the miscellaneous should be retrieved from</param>
 /// <returns>null if any error occurred; the miscellaneous field otherwise</returns>
 public static Dictionary <string, string[]> GetMiscFromResp <T>(this S2CResListBaseEntity <T> resp, out int totNumWithNonDefOp)
     where T : BaseEntity
 {
     totNumWithNonDefOp = 0;
     if ((resp == null) || (resp.Misc == null))
     {
         return(null);
     }
     else
     {
         Dictionary <string, string[]> res = new Dictionary <string, string[]>();
         foreach (string key in resp.Misc.Keys)
         {
             if (string.IsNullOrEmpty(key) || (resp.Misc[key] == null))
             {
                 continue;
             }
             if (key.Equals(TOT_NUM_WITH_NON_DEF_OP, StringComparison.InvariantCultureIgnoreCase))
             {
                 int.TryParse(resp.Misc[key], out totNumWithNonDefOp);
             }
             else
             {
                 res.Add(key, resp.Misc[key].Split(','));
             }
         }
         return(res);
     }
 }
Пример #2
0
        /// <summary>
        /// Builds a list of BaseEntities from the serialized given object
        /// </summary>
        /// <typeparam name="T">subtype of BaseEntity</typeparam>
        /// <param name="resp">serialized object which the list should be retrieved from</param>
        /// <returns>an empty list if any error occurred; the parsed list otherwise</returns>
        public static List <U> GetListFromResp <T, U>(this S2CResListBaseEntity <T> resp, out int totNum)
            where T : BaseEntity
            where U : BaseEntity
        {
            totNum = 0;
            List <U> result = new List <U>();

            if ((resp == null) || (resp.Data == null) || (!(resp.Data is object[])))
            {
                return(result);
            }

            object[] respData = (object[])resp.Data;
            totNum = resp.TotNum;
            foreach (object obj in respData)
            {
                T typedObj = (T)obj;
                result.Add((U)typedObj.ToBaseEntity());
            }

            return(result);
        }