本文整理汇总了C#中MappingSchema.GetNullValue方法的典型用法代码示例。如果您正苦于以下问题:C# MappingSchema.GetNullValue方法的具体用法?C# MappingSchema.GetNullValue怎么用?C# MappingSchema.GetNullValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MappingSchema
的用法示例。
在下文中一共展示了MappingSchema.GetNullValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNullValue
public virtual object GetNullValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
{
isSet = false;
if (member.Type.IsEnum)
return null;
var value = mappingSchema.GetNullValue(member.Type);
if (value is Type && (Type)value == typeof(DBNull))
{
value = DBNull.Value;
if (member.Type == typeof(string))
value = null;
}
return value;
}
示例2: GetNullValue
public override object GetNullValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
{
// Check member [NullValue(0)]
//
var attr = member.GetAttribute<NullValueAttribute>();
if (attr != null)
{
isSet = true;
return CheckNullValue(attr.Value, member);
}
// Check type [NullValues(typeof(int), 0)]
//
var attrs = member.GetTypeAttributes(typeof(NullValueAttribute));
foreach (NullValueAttribute a in attrs)
{
if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type ||
a.Type != null && a.Type == member.Type)
{
isSet = true;
return CheckNullValue(a.Value, member);
}
}
if (member.Type.IsEnum)
{
var value = CheckNullValue(mappingSchema.GetNullValue(member.Type), member);
if (value != null)
{
isSet = true;
return value;
}
}
isSet = false;
return null;
}
示例3: GetNullValue
public override object GetNullValue(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
{
if (member.Type == typeof(string))
{
isSet = true;
return null;
}
if (TypeHelper.IsNullableType(member.Type))
{
isSet = true;
return null;
}
if (member.Type.IsEnum)
{
var value = CheckNullValue(mappingSchema.GetNullValue(member.Type), member);
if (value != null)
{
isSet = true;
return value;
}
}
return base.GetNullValue(mappingSchema, typeExtension, member, out isSet);
}
示例4: GetNullable
public override bool GetNullable(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
{
// Check member [Nullable(true | false)]
//
var attr1 = member.GetAttribute<NullableAttribute>();
if (attr1 != null)
{
isSet = true;
return attr1.IsNullable;
}
// Check member [NullValue(0)]
//
var attr2 = member.GetAttribute<NullValueAttribute>();
if (attr2 != null)
return isSet = true;
// Check type [Nullable(true || false)]
//
attr1 = (NullableAttribute)TypeHelper.GetFirstAttribute(
member.MemberInfo.DeclaringType, typeof(NullableAttribute));
if (attr1 != null)
{
isSet = true;
return attr1.IsNullable;
}
// Check type [NullValues(typeof(int), 0)]
//
var attrs = member.GetTypeAttributes(typeof(NullValueAttribute));
foreach (NullValueAttribute a in attrs)
if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type ||
a.Type != null && a.Type == member.Type)
return isSet = true;
if (member.Type.IsEnum)
return isSet = mappingSchema.GetNullValue(member.Type) != null;
if (member.Type.IsClass)
{
var pk = member.GetAttribute<PrimaryKeyAttribute>();
if (pk != null)
{
isSet = false;
return false;
}
}
return base.GetNullable(mappingSchema, typeExtension, member, out isSet);
}
示例5: GetNullable
public override bool GetNullable(MappingSchema mappingSchema, TypeExtension typeExtension, MemberAccessor member, out bool isSet)
{
var keyAttr = member.GetAttribute<KeyAttribute>();
if (keyAttr != null)
{
isSet = true;
return false;
}
var requiredAttr = member.GetAttribute<RequiredAttribute>();
if(requiredAttr != null)
{
isSet = true;
return false;
}
if (member.Type == typeof(string))
{
isSet = true;
return true;
}
if (TypeHelper.IsNullableType(member.Type))
{
isSet = true;
return true;
}
if (member.Type.IsEnum)
return isSet = mappingSchema.GetNullValue(member.Type) != null;
return base.GetNullable(mappingSchema, typeExtension, member, out isSet);
}