예제 #1
0
        public static Dictionary <string, object> ToDictionary(this DBRecord record, DbMapping mapping)
        {
            var dictionary = new Dictionary <string, object>();

            foreach (var fieldName in record.FieldNames())
            {
                var property = mapping.PropertiesInfos.SingleOrDefault(p => p.Name.Equals(fieldName));
                if (property != null)
                {
                    object value = null;
                    var    type  = property.PropertyType;
                    if (type.IsLong())
                    {
                        value = record.GetLong(fieldName);
                    }
                    else if (type.IsNumeric())
                    {
                        value = record.GetDouble(fieldName);
                    }
                    else if (type.IsBool())
                    {
                        value = record.GetBoolean(fieldName);
                    }
                    else if (type.IsDateTime())
                    {
                        var date = record.GetDate(fieldName);
                        value = date.ToDateTime();
                    }
                    else if (type == typeof(string))
                    {
                        value = record.GetString(fieldName);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                    dictionary.Add(fieldName, value);
                }
            }
            return(dictionary);
        }