-
-
Notifications
You must be signed in to change notification settings - Fork 105
v2 Choose
axunonb edited this page Mar 3, 2022
·
4 revisions
Added in v1.5
The ChooseFormatter
lets you add simple logic to your templates.
Smart.Format("{0:choose(1|2|3):one|two|three|other}", someNumber)
Smart.Format("{0:choose(True|False):yes|no}", someBoolean)
Smart.Format("{0:choose(Male|Female):his|her|their}", genderEnum)
Smart.Format("{0:choose(null): N/A | {} }", valueOrNull)
{ Any Value : choose(1|2|3) : output 1 | output 2 | output 3 | default }
Value | formatter name | (choices) | outputs | default |
---|---|---|---|---|
Any value | "choose" | pipe-separated list of choices | pipe-separated list of outputs | (optional) output if nothing matched |
- The value can be anything. It will be converted to string (using
ToString
), and then matched against the choices. This works great for numbers, booleans, strings, enums, and most simple types. - Choices are case-sensitive by default. This is tricky with some values, such as
true.ToString() == "True"
. This will be improved in a future version. -
null
is supported too:{0:choose(null): NULL | NOT NULL }
- 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