I\'m trying to convert the value \"0\" ( System.String ) to its Boolean representation, like:
var myValue = Convert.To
public static bool GetBoolValue(string featureKeyValue)
{
if (!string.IsNullOrEmpty(featureKeyValue))
{
try
{
bool value;
if (bool.TryParse(featureKeyValue, out value))
{
return value;
}
else
{
return Convert.ToBoolean(Convert.ToInt32(featureKeyValue));
}
}
catch
{
return false;
}
}
else
{
return false;
}
}
You can call it like following -:
GetBoolValue("TRUE") // true
GetBoolValue("1") // true
GetBoolValue("") // false
GetBoolValue(null) // false
GetBoolValue("randomString") // false