Example #1
0
        // Token: 0x0600006B RID: 107 RVA: 0x00003644 File Offset: 0x00001844
        private static Dictionary <string, PropertyInfo> GetFieldnameFromCache <T>()
        {
            int hashCode = typeof(T).GetHashCode();

            if (!SqlDataReaderEx.propInfoCache.ContainsKey(hashCode))
            {
                SqlDataReaderEx.propInfoCache.Add(hashCode, SqlDataReaderEx.GetFieldname <T>());
            }
            return(SqlDataReaderEx.propInfoCache[hashCode]);
        }
Example #2
0
        // Token: 0x0600006A RID: 106 RVA: 0x000033B8 File Offset: 0x000015B8
        public static T To <T>(this SQLiteDataReader reader) where T : new()
        {
            if (reader == null || !reader.HasRows)
            {
                return(default(T));
            }
            T t = Activator.CreateInstance <T>();
            Dictionary <string, PropertyInfo> fieldnameFromCache = SqlDataReaderEx.GetFieldnameFromCache <T>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                string key = reader.GetName(i).ToLower();
                if (fieldnameFromCache.ContainsKey(key))
                {
                    PropertyInfo propertyInfo = fieldnameFromCache[key];
                    if (propertyInfo.PropertyType == typeof(string))
                    {
                        object obj     = null;
                        string @string = reader.GetString(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(@string) ? obj : @string, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(int))
                    {
                        object obj  = 0;
                        int    @int = reader.GetInt32(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(@int) ? obj : @int, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(decimal))
                    {
                        object  obj      = 0m;
                        decimal @decimal = reader.GetDecimal(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(@decimal) ? obj : @decimal, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(double))
                    {
                        object obj     = 0.0;
                        double @double = reader.GetDouble(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(@double) ? obj : @double, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(DateTime))
                    {
                        object obj     = default(DateTime);
                        string string2 = reader.GetString(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(string2) ? obj : string2, null);
                    }
                    else if (propertyInfo.PropertyType == typeof(bool))
                    {
                        object obj     = false;
                        bool   boolean = reader.GetBoolean(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(boolean) ? obj : boolean, null);
                    }
                    else
                    {
                        object obj   = null;
                        object value = reader.GetValue(i);
                        propertyInfo.SetValue(t, Convert.IsDBNull(value) ? obj : value, null);
                    }
                }
            }
            return(t);
        }