本文整理汇总了C#中System.Reflection.MemberInfo.GetGetter方法的典型用法代码示例。如果您正苦于以下问题:C# MemberInfo.GetGetter方法的具体用法?C# MemberInfo.GetGetter怎么用?C# MemberInfo.GetGetter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MemberInfo
的用法示例。
在下文中一共展示了MemberInfo.GetGetter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MemberMapping
internal MemberMapping(MemberInfo member, MemberAttribute attribute, EntityMapping entity)
{
this.member = member;
this.entity = entity;
memberType = member.GetMemberType();
var isEnumerableType = memberType != Types.String
&& memberType != typeof(byte[])
&& Types.IEnumerable.IsAssignableFrom(memberType);
if (attribute == null)
{
InitializeConversionMapping(isEnumerableType);
}
else
InitializeAttributeMapping(attribute, isEnumerableType);
getter = member.GetGetter();
if (storageMember != null)
setter = storageMember.GetSetter();
else
setter = member.GetSetter();
if (columnName == null)
columnName = member.Name;
}
示例2: ColumnModel
public ColumnModel(MemberInfo member)
{
MemberType = member.GetMemberType();
var sourceType = MemberType;
AllowDBNull = sourceType.IsNullable();
if (!AllowDBNull)
{
IsEnum = sourceType.IsEnum;
if (IsEnum)
DataType = Enum.GetUnderlyingType(sourceType);
else
DataType = sourceType;
}
else
{
sourceType = Nullable.GetUnderlyingType(sourceType);
IsEnum = sourceType.IsEnum;
if (IsEnum)
DataType = Enum.GetUnderlyingType(sourceType);
else
DataType = sourceType;
}
ColumnName = member.Name;
var getter = member.GetGetter();
if (AllowDBNull)
{
var p = MemberType.GetProperty("Value");
if (IsEnum)
{
SetColumnValue = (entity, row) =>
{
var v = getter(entity);
if (v == null)
row[ColumnName] = DBNull.Value;
else
row[ColumnName] = Converter.Convert(p.GetValue(v, null), DataType);
};
}
else
{
SetColumnValue = (entity, row) =>
{
var v = getter(entity);
if (v == null)
row[ColumnName] = DBNull.Value;
else
row[ColumnName] = p.GetValue(v, null);
};
}
}
else
{
if (DataType == Types.String)
{
AllowDBNull = true;
SetColumnValue = (entity, row) =>
{
var v = getter(entity);
row[ColumnName] = v == null ? DBNull.Value : v;
};
}
else
{
if(IsEnum)
SetColumnValue = (entity, row) => row[ColumnName] = Converter.Convert(getter(entity),DataType);
else
SetColumnValue = (entity, row) => row[ColumnName] = getter(entity);
}
}
}