我有简单的DTO
public class SimpleDto
{
public int Status { get; set; }
public long FromDate { get; set; }
public long ToDate { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我有ProxyDto TypeConverterAttribute:
[TypeConverter(typeof(SimpleConvert<SimpleDto>))]
public class ProxyDto<T>
{
public T Object { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这是执行SimpleConvert:
public class SimpleConvert<T> : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(string) ||
base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var strValue …Run Code Online (Sandbox Code Playgroud)