实现代码
代码
/// <summary>
/// 测试类
/// </summary>
public class User : XPObject
{
private string login;
private DateTime regDate;
public string Login
{
get { return login; }
set { SetPropertyValue<string>("Login", ref login, value); }
}
[ValueConverter(typeof(Encryption))] //类型转换
public DateTime RegistrationDate
{
get { return regDate; }
set { SetPropertyValue<DateTime>("Password", ref regDate, value); }
}
}
/// <summary>
/// 实现自己的类型转换
/// 字符类型与日期类型换转
/// </summary>
public class Encryption : ValueConverter
{
//从显示类型转换到数据库存储类型
public override object ConvertToStorageType(object value)
{
return value.ToString();
}
//从数据库存储类型转换到显示
public override object ConvertFromStorageType(object value)
{
return Convert.ToDateTime(value);
}
//存储类型
public override Type StorageType
{
get { return typeof(string); }
}
}
/// 测试类
/// </summary>
public class User : XPObject
{
private string login;
private DateTime regDate;
public string Login
{
get { return login; }
set { SetPropertyValue<string>("Login", ref login, value); }
}
[ValueConverter(typeof(Encryption))] //类型转换
public DateTime RegistrationDate
{
get { return regDate; }
set { SetPropertyValue<DateTime>("Password", ref regDate, value); }
}
}
/// <summary>
/// 实现自己的类型转换
/// 字符类型与日期类型换转
/// </summary>
public class Encryption : ValueConverter
{
//从显示类型转换到数据库存储类型
public override object ConvertToStorageType(object value)
{
return value.ToString();
}
//从数据库存储类型转换到显示
public override object ConvertFromStorageType(object value)
{
return Convert.ToDateTime(value);
}
//存储类型
public override Type StorageType
{
get { return typeof(string); }
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/