本文整理汇总了C#中BLToolkit.Mapping.MapMemberInfo类的典型用法代码示例。如果您正苦于以下问题:C# MapMemberInfo类的具体用法?C# MapMemberInfo怎么用?C# MapMemberInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MapMemberInfo类属于BLToolkit.Mapping命名空间,在下文中一共展示了MapMemberInfo类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMemberMapper
internal static MemberMapper CreateMemberMapper(MapMemberInfo mi)
{
var type = mi.Type;
var mm = null as MemberMapper;
if (type.IsEnum && mi.DbType == DbType.String)
mm = new EnumStringMapper(type);
if (mm == null && (type.IsPrimitive || type.IsEnum))
mm = GetPrimitiveMemberMapper(mi);
if (mm == null)
{
mm = GetNullableMemberMapper(mi);
//if (mm != null)
// mi.IsNullable = true;
}
if (mm == null) mm = GetSimpleMemberMapper(mi);
#if !SILVERLIGHT
if (mm == null) mm = GetSqlTypeMemberMapper(mi);
#endif
return mm ?? new DefaultMemberMapper();
}
示例2: Init
public override void Init(MapMemberInfo mapMemberInfo)
{
if (mapMemberInfo == null) throw new ArgumentNullException("mapMemberInfo");
_nullValue = Convert.ToInt16(mapMemberInfo.NullValue);
base.Init(mapMemberInfo);
}
示例3: Init
public virtual void Init(MapMemberInfo mapMemberInfo)
{
if (mapMemberInfo == null) throw new ArgumentNullException("mapMemberInfo");
_mapMemberInfo = mapMemberInfo;
_name = mapMemberInfo.Name;
_dbType = mapMemberInfo.DbType;
_type = mapMemberInfo.Type;
_memberName = mapMemberInfo.MemberName;
_memberAccessor = mapMemberInfo.MemberAccessor;
_complexMemberAccessor = mapMemberInfo.ComplexMemberAccessor;
_mappingSchema = mapMemberInfo.MappingSchema;
}
示例4: Init
public virtual void Init(MapMemberInfo mapMemberInfo)
{
if (mapMemberInfo == null) throw new ArgumentNullException("mapMemberInfo");
MapMemberInfo = mapMemberInfo;
Name = mapMemberInfo.Name;
MemberName = mapMemberInfo.MemberName;
Storage = mapMemberInfo.Storage;
DbType = mapMemberInfo.DbType;
_type = mapMemberInfo.Type;
MemberAccessor = mapMemberInfo.MemberAccessor;
_complexMemberAccessor = mapMemberInfo.ComplexMemberAccessor;
MappingSchema = mapMemberInfo.MappingSchema;
if (Storage != null)
MemberAccessor = ExprMemberAccessor.GetMemberAccessor(MemberAccessor.TypeAccessor, Storage);
}
示例5: CreateMemberMapper
internal static MemberMapper CreateMemberMapper(MapMemberInfo mi)
{
Type type = mi.Type;
MemberMapper mm = null;
if (type.IsPrimitive || type.IsEnum)
mm = GetPrimitiveMemberMapper(mi);
if (mm == null)
{
mm = GetNullableMemberMapper(mi);
//if (mm != null)
// mi.IsNullable = true;
}
if (mm == null) mm = GetSimpleMemberMapper(mi);
if (mm == null) mm = GetSqlTypeMemberMapper(mi);
if (mm == null) mm = new DefaultMemberMapper();
return mm;
}
示例6: GetSqlTypeMemberMapper
private static MemberMapper GetSqlTypeMemberMapper(MapMemberInfo mi)
{
var type = mi.Type;
if (TypeHelper.IsSameOrParent(typeof(INullable), type) == false)
return null;
var d = mi.MapValues != null;
if (type == typeof(SqlByte)) return d? new SqlByteMapper. Default(): new SqlByteMapper();
if (type == typeof(SqlInt16)) return d? new SqlInt16Mapper. Default(): new SqlInt16Mapper();
if (type == typeof(SqlInt32)) return d? new SqlInt32Mapper. Default(): new SqlInt32Mapper();
if (type == typeof(SqlInt64)) return d? new SqlInt64Mapper. Default(): new SqlInt64Mapper();
if (type == typeof(SqlSingle)) return d? new SqlSingleMapper. Default(): new SqlSingleMapper();
if (type == typeof(SqlBoolean)) return d? new SqlBooleanMapper. Default(): new SqlBooleanMapper();
if (type == typeof(SqlDouble)) return d? new SqlDoubleMapper. Default(): new SqlDoubleMapper();
if (type == typeof(SqlDateTime)) return d? new SqlDateTimeMapper.Default(): new SqlDateTimeMapper();
if (type == typeof(SqlDecimal)) return d? new SqlDecimalMapper. Default(): new SqlDecimalMapper();
if (type == typeof(SqlMoney)) return d? new SqlMoneyMapper. Default(): new SqlMoneyMapper();
if (type == typeof(SqlGuid)) return d? new SqlGuidMapper. Default(): new SqlGuidMapper();
if (type == typeof(SqlString)) return d? new SqlStringMapper. Default(): new SqlStringMapper();
return null;
}
示例7: GetNullableMemberMapper
private static MemberMapper GetNullableMemberMapper(MapMemberInfo mi)
{
var type = mi.Type;
if (type.IsGenericType == false || mi.MapValues != null)
return null;
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType == null)
return null;
if (underlyingType.IsEnum)
{
underlyingType = Enum.GetUnderlyingType(underlyingType);
if (underlyingType == typeof(SByte)) return new NullableSByteMapper. Enum();
if (underlyingType == typeof(Int16)) return new NullableInt16Mapper. Enum();
if (underlyingType == typeof(Int32)) return new NullableInt32Mapper. Enum();
if (underlyingType == typeof(Int64)) return new NullableInt64Mapper. Enum();
if (underlyingType == typeof(Byte)) return new NullableByteMapper. Enum();
if (underlyingType == typeof(UInt16)) return new NullableUInt16Mapper.Enum();
if (underlyingType == typeof(UInt32)) return new NullableUInt32Mapper.Enum();
if (underlyingType == typeof(UInt64)) return new NullableUInt64Mapper.Enum();
}
else
{
if (underlyingType == typeof(SByte)) return new NullableSByteMapper();
if (underlyingType == typeof(Int16)) return new NullableInt16Mapper();
if (underlyingType == typeof(Int32)) return new NullableInt32Mapper();
if (underlyingType == typeof(Int64)) return new NullableInt64Mapper();
if (underlyingType == typeof(Byte)) return new NullableByteMapper();
if (underlyingType == typeof(UInt16)) return new NullableUInt16Mapper();
if (underlyingType == typeof(UInt32)) return new NullableUInt32Mapper();
if (underlyingType == typeof(UInt64)) return new NullableUInt64Mapper();
if (underlyingType == typeof(Char)) return new NullableCharMapper();
if (underlyingType == typeof(Single)) return new NullableSingleMapper();
if (underlyingType == typeof(Boolean)) return new NullableBooleanMapper();
if (underlyingType == typeof(Double)) return new NullableDoubleMapper();
if (underlyingType == typeof(DateTime)) return new NullableDateTimeMapper();
if (underlyingType == typeof(Decimal)) return new NullableDecimalMapper();
if (underlyingType == typeof(Guid)) return new NullableGuidMapper();
}
return null;
}
示例8: GetSimpleMemberMapper
private static MemberMapper GetSimpleMemberMapper(MapMemberInfo mi)
{
if (mi.MapValues != null)
return null;
var n = mi.Nullable;
var type = mi.Type;
if (type == typeof(String))
if (mi.Trimmable) return n? new StringMapper.Trimmable.NullableT(): new StringMapper.Trimmable();
else return n? new StringMapper.Nullable() : new StringMapper();
if (type == typeof(DateTime)) return n? new DateTimeMapper.Nullable() : new DateTimeMapper();
if (type == typeof(DateTimeOffset)) return n? new DateTimeOffsetMapper.Nullable() : new DateTimeOffsetMapper();
if (type == typeof(Decimal)) return n? new DecimalMapper.Nullable() : new DecimalMapper();
if (type == typeof(Guid)) return n? new GuidMapper.Nullable() : new GuidMapper();
if (type == typeof(Stream)) return n? new StreamMapper.Nullable() : new StreamMapper();
#if !SILVERLIGHT
if (type == typeof(XmlReader)) return n? new XmlReaderMapper.Nullable() : new XmlReaderMapper();
if (type == typeof(XmlDocument)) return n? new XmlDocumentMapper.Nullable() : new XmlDocumentMapper();
#endif
return null;
}
示例9: GetPrimitiveMemberMapper
private static MemberMapper GetPrimitiveMemberMapper(MapMemberInfo mi)
{
if (mi.MapValues != null)
return null;
var n = mi.Nullable;
var type = mi.MemberAccessor.UnderlyingType;
if (type == typeof(SByte)) return n? new SByteMapper. Nullable(): new SByteMapper();
if (type == typeof(Int16)) return n? new Int16Mapper. Nullable(): new Int16Mapper();
if (type == typeof(Int32)) return n? new Int32Mapper. Nullable(): new Int32Mapper();
if (type == typeof(Int64)) return n? new Int64Mapper. Nullable(): new Int64Mapper();
if (type == typeof(Byte)) return n? new ByteMapper. Nullable(): new ByteMapper();
if (type == typeof(UInt16)) return n? new UInt16Mapper. Nullable(): new UInt16Mapper();
if (type == typeof(UInt32)) return n? new UInt32Mapper. Nullable(): new UInt32Mapper();
if (type == typeof(UInt64)) return n? new UInt64Mapper. Nullable(): new UInt64Mapper();
if (type == typeof(Single)) return n? new SingleMapper. Nullable(): new SingleMapper();
if (type == typeof(Double)) return n? new DoubleMapper. Nullable(): new DoubleMapper();
if (type == typeof(Char)) return n? new CharMapper. Nullable(): new CharMapper();
if (type == typeof(Boolean)) return n? new BooleanMapper.Nullable(): new BooleanMapper();
throw new InvalidOperationException();
}
示例10: Init
public override void Init(MapMemberInfo mapMemberInfo)
{
mapMemberInfo.DbType = DbType.AnsiString;
base.Init(mapMemberInfo);
}
示例11: MapTo
protected static object MapTo(object value, MapMemberInfo mapInfo)
{
if (mapInfo == null) throw new ArgumentNullException("mapInfo");
if (value == null)
return null;
if (mapInfo.Nullable && mapInfo.NullValue != null)
{
try
{
var comp = (IComparable)value;
if (comp.CompareTo(mapInfo.NullValue) == 0)
return null;
}
catch
{
}
}
if (mapInfo.MapValues != null)
{
object mapValue;
if (mapInfo.TryGetMapValue(value, out mapValue))
return mapValue;
//2011-11-16 ili: this is too slow when we have for ex. enum with 50+ values
//
//var comp = (IComparable)value;
//foreach (var mv in mapInfo.MapValues)
//{
// try
// {
// if (comp.CompareTo(mv.OrigValue) == 0)
// return mv.MapValues[0];
// }
// catch
// {
// }
//}
}
return value;
}
示例12: MapFrom
protected object MapFrom(object value, MapMemberInfo mapInfo)
{
if (mapInfo == null) throw new ArgumentNullException("mapInfo");
if (value == null)
return mapInfo.NullValue;
if (mapInfo.Trimmable && value is string)
value = value.ToString().TrimEnd(_trim);
if (mapInfo.MapValues != null)
{
var comp = (IComparable)value;
foreach (var mv in mapInfo.MapValues)
foreach (var mapValue in mv.MapValues)
{
try
{
if (comp.CompareTo(mapValue) == 0)
return mv.OrigValue;
}
catch
{
}
}
// Default value.
//
if (mapInfo.DefaultValue != null)
return mapInfo.DefaultValue;
}
var valueType = value.GetType();
var memberType = mapInfo.Type;
if (!TypeHelper.IsSameOrParent(memberType, valueType))
{
if (memberType.IsGenericType)
{
var underlyingType = Nullable.GetUnderlyingType(memberType);
if (valueType == underlyingType)
return value;
memberType = underlyingType;
}
if (memberType.IsEnum)
{
var underlyingType = mapInfo.MemberAccessor.UnderlyingType;
if (valueType != underlyingType)
//value = _mappingSchema.ConvertChangeType(value, underlyingType);
return MapFrom(MappingSchema.ConvertChangeType(value, underlyingType), mapInfo);
//value = Enum.Parse(type, Enum.GetName(type, value));
value = Enum.ToObject(memberType, value);
}
else
{
value = MappingSchema.ConvertChangeType(value, memberType);
}
}
return value;
}
示例13: MapTo
protected static object MapTo(object value, MapMemberInfo mapInfo)
{
if (mapInfo == null) throw new ArgumentNullException("mapInfo");
if (value == null)
return null;
if (mapInfo.Nullable && mapInfo.NullValue != null)
{
try
{
var comp = (IComparable)value;
if (comp.CompareTo(mapInfo.NullValue) == 0)
return null;
}
catch
{
}
}
if (mapInfo.MapValues != null)
{
var comp = (IComparable)value;
foreach (var mv in mapInfo.MapValues)
{
try
{
if (comp.CompareTo(mv.OrigValue) == 0)
return mv.MapValues[0];
}
catch
{
}
}
}
return value;
}
示例14: CreateMemberMapper
protected override MemberMapper CreateMemberMapper(MapMemberInfo mapMemberInfo)
{
if (mapMemberInfo.Type == typeof(CustomString))
{
MemberMapper mm = new CustomString.Mapper();
mm.Init(mapMemberInfo);
return mm;
}
return base.CreateMemberMapper(mapMemberInfo);
}