Today I want to talk to you about the boolean conversions to different types. Why do I want to do this? Because I heard a discussion about the BooleanConverter on DotNetRocks. In the Better-Know-A-Framework section of show #254 Carl Franklin talked about it. He could get it to work as he expected it to work. I think this is because the BooleanConverter, like all converters like it, is not meant to work with in the way he proposed: converting types to and from booleans. But the BooleanConverter only converts booleans to strings and strings to booleans. The BooleanConverter is meant to be used by the designer property window.

The Convert class, in the System namespace, can be used to convert a value to a boolean and a boolean to a value of another type. For the purpose of converting values to booleans the Convert class exposes the ‘ToBoolean’ method. This method has an overload for the every type that implements the IConvertable interface and Object type. If a value is put into the Object overload that instance must implement the IConvertible interface. To convert a boolean to another type the Convert class has type specific methods like ToByte, ToString, ToInt32, etc..