How to create a generic class that allows types which has constructor taking one string argument and implements ToString and implements Two functions as below.
class Convert<T>:ConverterBase
where T:new()
{
public override object StringToField(string from)
{
try
{
return new T(from);
}
catch (ArgumentException exception)
{
ThrowConvertException(from, exception.Message);
return null;
}
}
public override string FieldToString(object from)
{
return from.ToString();
}
}
Note: ConvertBase is a abstract class in FileHelpers csv reader library. I already have classes that corresponds to my fields in csv, didn't want to create seperate Classes that inherit ConvertBase inorder to use with the FileHelpres library.