Skip to content

BoolFormat

The spelling a boolean is written in: words, a digit, a letter or a label.

A true-or-false value has no single written form. JSON and XML want the lowercase words true and false; a database flag column wants 1 and 0; a legacy CHAR(1) column holds Y and N; a screen shows Yes and No. .NET's own spelling, True, suits none of those — it is not valid JSON, and an XML boolean rejects it. BoolFormat names the spelling, so the writer never guesses.

Members

Member True / false Meant for
Lowercase "true" / "false" JSON, XML (xs:boolean), JavaScript, URLs. This is the default.
Capitalized "True" / "False" The .NET spelling — what CkText.BoolToString writes.
OneZero "1" / "0" A numeric flag: SQL BIT and TINYINT columns, CSV exports.
YN "Y" / "N" A legacy CHAR(1) flag column.
YesNo "Yes" / "No" A label for people.

Where it is used

CkBool.Format takes a format parameter. The default is Lowercase (CkSettings.DefaultBoolFormat). Whichever spelling you write, the readers on CkBool read it back as the same boolean.

Quick look

using SafeCoder.CommonKit;
using SafeCoder.CommonKit.Enums;

CkBool.Format(true);                  // -> "true"  (Lowercase is the default)

CkBool.Format(
    input: true,
    format: BoolFormat.OneZero
);                                    // -> "1"

CkBool.Format(
    input: "no",
    format: BoolFormat.YesNo
);                                    // -> "No"

CkBool.Format(
    input: "maybe",
    format: BoolFormat.YN
);                                    // -> ""  (unreadable: rejected, in every spelling)