实现代码
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
///
<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 ); }
}
}