✅ Specialising a generic method
I've got a generic method that takes a string and uses a TypeConverter to convert it to a specific type.
However, when the requested type is bool, I want 0 and 1 to convert to false and true.
I was hoping that I'd be able to do this:
However, I get an error on
How can I get this to work, either by convincing the compiler that T is bool in that situation, or any other way?
Thanks
However, when the requested type is bool, I want 0 and 1 to convert to false and true.
I was hoping that I'd be able to do this:
However, I get an error on
return Convert<int>(input) != 0; as it says "Cannot implicitly convert type 'bool' to 'T'", even though in this case the if statement has ensured that T is bool.How can I get this to work, either by convincing the compiler that T is bool in that situation, or any other way?
Thanks