You have not determined what should happen if rawValue is not converted to bool. The usual choice is to return false, null or throw an exception. It is also possible to convert the rawValue string representation to a bool type, for example, Yes / No, True / False, 1/0, etc.
I would use bool.TryParse to do the conversion. This will succeed if rawValue is a bool or its string value is "True" or "False".
bool result; if (!bool.TryParse(rawValue as string, out result)) {
Jamie Ide Dec 29 '09 at 2:51 p.m. 2009-12-29 14:51
source share