-
-
Notifications
You must be signed in to change notification settings - Fork 105
Null _ NullFormatter
Bidimus edited this page Nov 4, 2022
·
3 revisions
The NullFormatter
outputs a custom string literal, if a variable is null
, else another literal (default is string.Empty
) or nested Placeholder
.
{ Any Value : isnull : output-if-null | output-not-null }
Value | formatter name | outputs |
---|---|---|
Any value | "isnull" | one of the 2 options |
- output-not-null: A text literal or a nested placeholder.
string Name
: default isisnull
The name to use a named formatter
char SplitChar
: default is'|'
The split character for the 2 output options
Smart.Format("{0:isnull:N/A}", default(object));
// outputs: "N/A"
int? arg = null;
Smart.Format("{0:isnull:N/A|Value is {:000}}", arg);
// outputs depending on arg:
arg == null: "N/A"
arg == 12: "Value is 012"
Nullable Number has member Value == 1:
var arg = new { Number = new { Value = 1} };
Smart.Format("{Number?.Value:isnull:N/A|Value is {:000}}", arg);
// outputs: "Value is 001"
Nullable Number is null
, Value won't get evaluated:
var arg = new { Number = default(object) };
Smart.Format("{Number?.Value:isnull:N/A|Value is {:000}}", arg);
// outputs: "N/A"
- Syntax, Terminology
- Placeholders and Nesting
- string.Format Compatibility
- Character Literals in Format Strings
- HTML With CSS or JavaScript
- Data Source Extensions
- Default _ DefaultFormatter
- Lists _ ListFormatter
- Choose _ ChooseFormatter
- Condition _ ConditionalFormatter
- Null _ NullFormatter
- SubString _ SubStringFormatter
- RegEx _ IsMatchFormatter
- Pluralization _ PluralLocalizationFormatter
- Localization _ LocalizationFormatter
- Templates _ TemplateFormatter
- TimeSpan _ TimeFormatter
- XML _ XElementFormatter
- Extension Methods
- Home
- Common Pitfalls
- HTML with CSS or JavaScript
- Overview
- Main Features
- Formatters
- Extra Features
- Console and StringBuilder
- TemplateFormatter
- SmartSettings to control Smart.Format behavior
- Additional Info
- License