-
-
Notifications
You must be signed in to change notification settings - Fork 104
Common Pitfalls
The section string.Format Compatibility is a "must read".
Most of the examples in this Wiki are using "Smart.Format(...)". This is for a good reason: Smart.Format(..) automatically initializes the SmartFormatter
with default extensions. If you're using SmartFormatter.Format(...)
directly, then it's your job to initialize the SmartFormatter
before. So for the beginning just leave SmartFormatter.Format(...)
alone.
Note:
Smart.Format(...)
is just the short version forSmart.Default.Format(...)
.
By default, SmartFormat sets ParseErrorAction.ThrowError
for the Parser
and FormatErrorAction.ThrowError
for the SmartFormatter
.
If you change it to Ignore
, this can lead to confusing results. It's highly recommended, to turn exceptions on at least while developing and debugging the code:
Smart.Default.Settings.FormatErrorAction = FormatErrorAction.ThrowError;
Smart.Default.Settings.ParseErrorAction = ParseErrorAction.ThrowError;
Same as with string.Format
it may be necessary to supply the CultureInfo
in order to generate properly formatted output strings. Example:
Smart.Format(new CultureInfo("en-US"), "{0:C}", 1234)
// Result: "$1,234.00"
Please read docs for templates.
Only parameterless instance methods of a type can be used in a placeholder, extension methods cannot.
- 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