示例#1
0
        // chuyển datareader => dictionary
        public static List <Dictionary <string, object> > ToListDictionary(this IDataReader dataReader)
        {
            if (dataReader == null)
            {
                return(null);
            }
            List <Dictionary <string, object> > lstResult = new List <Dictionary <string, object> >();

            try
            {
                while (dataReader.Read())
                {
                    Dictionary <string, object> dicData = new Dictionary <string, object>();
                    for (int i = 0; i < dataReader.FieldCount; i++)
                    {
                        string name = dataReader.GetName(i);
                        if (!dicData.ContainsKey(name))
                        {
                            //dicData.Add(name, dataReader.GetValueFromDataReader(i));
                            dicData.Add(name, dataReader.GetValue(i));
                        }
                    }
                    lstResult.Add(dicData);
                }
            }
            catch (Exception ex)
            {
                CommonLog.CommonErrorLog(ex, $"ExtensionMethod.TolistDictionary");
            }
            return(lstResult);
        }
示例#2
0
        /// <summary>
        /// đọc từ file json
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static string ReadToEnd(string path)
        {
            string line = string.Empty;

            try
            {
                using (StreamReader sr = new StreamReader(path))
                {
                    line = sr.ReadToEnd();
                }
            }catch (Exception ex)
            {
                CommonLog.CommonErrorLog(ex, $"Error - ReadtoEnd: {path}");
            }
            return(line);
        }