c# relaxed boolean cast
/// <summary>
/// Parse strings into true or false bools using relaxed parsing rules
/// </summary>
public static class BoolParser
{
/// <summary>
/// Get the boolean value for this string
/// </summary>
public static bool GetValue(string value, bool defaultValue)
{
var result = IsTrue(value, defaultValue);
if (result == null) return defaultValue;
return (bool) result;
}
public static bool? GetValue(string value)
{
return IsTrue(value);
}
/// <summary>
/// Determine whether the string is equal to True
/// </summary>
private static bool? IsTrue(string value, bool? defaultValue = null)
{
try
{
if (value == null)
{
return defaultValue;
}
value = value.Trim().ToLower();
switch (value)
{
case "true":
case "t":
case "1":
case "yes":
case "yeah":
case "yup":
case "y":
return true;
case "false":
case "f":
case "0":
case "no":
case "nope":
case "n":
return false;
default:
return defaultValue;
}
}
catch
{
return defaultValue;
}
}
}
Also in C#:
- c# double value with 2 decimal places
- same click event diffrenet buttonms c#
- c# list to string
- copy a list C#
- How to get the world position of the edge of an object?
- .net core copy file in folder to root
- move file from one folder to another c#
- https request c#
- c# getter setter
- C# how to get public key for InternalsVisibleTo
- get variable from another script unity
- check if enabled unity
- add row count devepxress report
- unity movement on forward
- c# lambda expression
- unity rigidbody constraints
- how to access the dictionary from another script in unity
- c# sort for loop
- convert string array to int C#
- check which activity in focus in android
- what does gameobject.find return
- s3 upload base64 .net core
- c# instantiate