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¶
ToBooleanreturnsfalseimmediately for a null input. (BR-072)- Otherwise uppercase the value and test membership in the fixed truthy set
{"Y","YES","TRUE","1","ON"}viaIEnumerableExtensions.IsIn. Anything else isfalse. (BR-072) ToY_N_Stringrenderstrueas"Y"andfalseas"N". (BR-073)ToYesNoStringrenders"YES"/"NO"(uppercase);ToOnOffStringrenders"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
Related documentation¶
Sources¶
Common/SAIF.Common/Extensions/StringExtensions.csCommon/SAIF.Common/Extensions/BooleanExtensions.cs