Ejemplo n.º 1
0
            private bool ByMemberName(out object result, string memberName)
            {
                var value = _getter(_item, memberName);

                result = DBNullHelper.FromDb(value);
                return(true);
            }
Ejemplo n.º 2
0
 private static T ConvertValueType(object value)
 {
     if (DBNullHelper.IsNull(value))
     {
         throw new NullReferenceException("Value is DbNull");
     }
     return(ConvertPrivate <T>(value));
 }
Ejemplo n.º 3
0
        internal static T MapTo <T>(this IDataRecord record, SetterMap <T> setterMap)
        {
            var result = Activator.CreateInstance <T>();

            foreach (var item in setterMap)
            {
                var val    = DBNullHelper.FromDb(record.GetValue(item.FieldIndex));
                var setter = item.Action;
                setter(result, val);
            }
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Builder method - adds a name/value pair as parameter
        /// </summary>
        /// <param name="name">the parameter name</param>
        /// <param name="value">the parameter value</param>
        /// <returns>the same CommandBuilder instance</returns>
        public CommandBuilder WithParameter(string name, object value)
        {
            IDataParameter p;

            if (Command.Parameters.Contains(name))
            {
                p       = (IDbDataParameter)Command.Parameters[name];
                p.Value = DBNullHelper.ToDb(value);
            }
            else
            {
                p = Command.CreateParameter();
                p.ParameterName = name;
                p.Value         = DBNullHelper.ToDb(value);
                Command.Parameters.Add(p);
            }
            return(this);
        }
Ejemplo n.º 5
0
        internal static T MapTo <T>(this IDataRecord record, DbConfig config)
        {
            var convention = config.MappingConvention;
            var setters    = FastReflection.Instance.GetSettersForType <T>();
            var result     = Activator.CreateInstance <T>();

            for (var i = 0; i < record.FieldCount; i++)
            {
                Action <T, object> setter;
                var columnName = convention.FromDb(record.GetName(i));
                if (!setters.TryGetValue(columnName, out setter))
                {
                    continue;
                }
                var val = DBNullHelper.FromDb(record.GetValue(i));
                setter(result, val);
            }
            return(result);
        }
Ejemplo n.º 6
0
 public override object GetValue(int i)
 => DBNullHelper.ToDb(Getters[Properties[i].Name](_enumerator.Current));
Ejemplo n.º 7
0
 private static T ConvertRefType(object value) => DBNullHelper.IsNull(value) ? default(T) : ConvertPrivate <T>(value);
Ejemplo n.º 8
0
 // ReSharper disable once UnusedMember.Local
 // (used via reflection!)
 private static TElem?ConvertNullableValueType <TElem>(object value) where TElem : struct
 => DBNullHelper.IsNull(value) ? (TElem?)null : ConvertPrivate <TElem>(value);