private PropertyValue GetSupportedValue(bool isNull, PropertyMapping mapper, DataRow row) { if (mapper.Property.Type == typeof(Guid)) { return(isNull ? new Guid?() : new Guid(row[mapper.Index].ToString())); } var typeCode = Type.GetTypeCode(mapper.Property.Type.GetNonNullableType()); switch (typeCode) { case TypeCode.Boolean: return(isNull ? new bool?() : Convert.ToBoolean(row[mapper.Index])); case TypeCode.Char: return(isNull ? new char?() : Convert.ToChar(row[mapper.Index])); case TypeCode.Byte: return(isNull ? new byte?() : Convert.ToByte(row[mapper.Index])); case TypeCode.Int16: return(isNull ? new short?() : Convert.ToInt16(row[mapper.Index])); case TypeCode.Int32: return(isNull ? new int?() : Convert.ToInt32(row[mapper.Index])); case TypeCode.Int64: return(isNull ? new long?() : Convert.ToInt64(row[mapper.Index])); case TypeCode.Decimal: return(isNull ? new decimal?() : Convert.ToDecimal(row[mapper.Index])); case TypeCode.Double: return(isNull ? new double?() : Convert.ToDouble(row[mapper.Index])); case TypeCode.String: return(isNull ? string.Empty : Convert.ToString(row[mapper.Index])); case TypeCode.DateTime: return(isNull ? new DateTime?() : Convert.ToDateTime(row[mapper.Index])); case TypeCode.Single: return(isNull ? new float?() : Convert.ToSingle(row[mapper.Index])); default: return(PropertyValue.NewValue(row[mapper.Index], null)); } }
private PropertyValue GetConvertedValue(PropertyMapping mapper, bool isNull, Func <int, object> funcGetValue) { var converter = ConvertManager.GetConverter(mapper.Property.Type); if (converter == null) { throw new NotSupportedException(SR.GetString(SRKind.UnableConvertComplexType, mapper.Property.Type)); } if (isNull) { return(PropertyValue.Empty); } var dbType = mapper.Property.Info.DataType ?? DbType.String; return(PropertyValue.NewValue(converter.ConvertFrom(funcGetValue(mapper.Index), dbType))); }
private PropertyValue GetPropertyValue(PropertyMapping mapper, Func <int, bool> funcIsNull, Func <int, object> funcGetValue, Func <bool, PropertyValue> funcRead) { var isNull = funcIsNull(mapper.Index); if (mapper.Property.Type.IsArray && mapper.Property.Type.GetElementType() == typeof(byte)) { return(isNull ? new byte[0] : (byte[])funcGetValue(mapper.Index)); } if (mapper.Property.Type.IsEnum) { return(GetEnumValue(mapper, isNull, funcGetValue)); } if (PropertyValue.IsSupportedType(mapper.Property.Type)) { return(funcRead(isNull)); } return(GetConvertedValue(mapper, isNull, funcGetValue)); }