Created
February 7, 2013 11:38
-
-
Save LambdaSix/4730435 to your computer and use it in GitHub Desktop.
Convert between String and Boolean? in a bad way.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Convert between Boolean? and String | |
/// </summary> | |
public class BooleanToStringConverter : IValueConverter | |
{ | |
public object Convert( object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
// bool? to string. | |
bool castValue = (value as bool?) ?? false; | |
return castValue ? "True" : "False"; | |
} | |
public object ConvertBack( object value, Type targetType, object parameter, CultureInfo culture) | |
{ | |
string castValue = (value as String) ?? "False"; | |
bool outVal = false; | |
Boolean.TryParse(castValue, out outVal); | |
return outVal as bool?; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment