Skip to content

Interpret a string as a boolean and render booleans as flags

Convert between truthy flag strings and boolean values, triggered when caller converts between flag strings (from files, code tables, or UI) and bool.

Field Value
Operation ID OP-031
Trigger Caller converts between flag strings (from files, code tables, or UI) and bool
Inputs string / bool
Outputs bool / string
Primary components StringExtensions.ToBoolean(this string)`; `BooleanExtensions.ToY_N_String` / `ToYesNoString` / `ToOnOffString
Entry point Common/SAIF.Common/Extensions/StringExtensions.cs

Steps

  1. ToBoolean returns false immediately for a null input. (BR-072)
  2. Otherwise uppercase the value and test membership in the fixed truthy set {"Y","YES","TRUE","1","ON"} via IEnumerableExtensions.IsIn. Anything else is false. (BR-072)
  3. ToY_N_String renders true as "Y" and false as "N". (BR-073)
  4. ToYesNoString renders "YES" / "NO" (uppercase); ToOnOffString renders "On" / "Off" (mixed case). (BR-073)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Caller converts between<br>flag strings and bool"]) --> Dir{"Direction of<br>conversion?"}
    Dir -->|"string -> bool"| C1{"ToBoolean input<br>is null?"}
    C1 -->|Yes| False([Return false])
    C1 -->|No| S1["Uppercase value, test<br>membership in {Y, YES,<br>TRUE, 1, ON}"]
    S1 --> C2{"Value is in<br>truthy set?"}
    C2 -->|Yes| True([Return true])
    C2 -->|No| False2([Return false])
    Dir -->|"bool -> string"| Method{"Which render<br>method is called?"}
    Method -->|ToY_N_String| S2(["Render 'Y' or 'N'"])
    Method -->|ToYesNoString| S3(["Render 'YES' or 'NO'"])
    Method -->|ToOnOffString| S4(["Render 'On' or 'Off'"])
    True --> End([Result returned])
    False --> End
    False2 --> End
    S2 --> End
    S3 --> End
    S4 --> End

Sources

  • Common/SAIF.Common/Extensions/StringExtensions.cs
  • Common/SAIF.Common/Extensions/BooleanExtensions.cs