mirror of
https://github.com/chylex/TweetDuck.git
synced 2024-11-23 17:42:46 +01:00
29 lines
840 B
C#
29 lines
840 B
C#
using System;
|
|
|
|
namespace TweetDuck.Data.Serialization{
|
|
sealed class SingleTypeConverter<T> : ITypeConverter{
|
|
public Func<T, string> ConvertToString { get; set; }
|
|
public Func<string, T> ConvertToObject { get; set; }
|
|
|
|
bool ITypeConverter.TryWriteType(Type type, object value, out string converted){
|
|
try{
|
|
converted = ConvertToString((T)value);
|
|
return true;
|
|
}catch{
|
|
converted = null;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool ITypeConverter.TryReadType(Type type, string value, out object converted){
|
|
try{
|
|
converted = ConvertToObject(value);
|
|
return true;
|
|
}catch{
|
|
converted = null;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|