You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am upgrading SmartFormat to 3.2.1 from 2.7.2 and I am running into an issue adding a custom selector char. This is for replacing values in an XML, where the replacement key uses the $ sign to indicate the text that will get replaced.
In 2.7.2 I have code that looks like this,
var format = "{$number1$}";
Smart.Default.Parser.AddAdditionalSelectorChars(" $");
IDictionary<string, object> templateData = new Dictionary<string, object>();
templateData.Add("$number1$", "test");
Console.WriteLine(Smart.Format(format, templateData)); // prints: test, works as expected
In 3.2.1, I have modified the code to use the new AddCustomSelectorChars, so the code looks as follows,
var format = "{$number1$}";
Smart.Default.Settings.Parser.AddCustomSelectorChars(" $".ToCharArray());
IDictionary<string, object> templateData = new Dictionary<string, object>();
templateData.Add("$number1$", "test");
Console.WriteLine(Smart.Format(format, templateData));
// exception on the Format function that says,
// SmartFormat.Core.Parsing.ParsingErrors: 'The format string has 2 issues:
// '0x24': Invalid character in the selector, '0x24': Invalid character in the selector
// In: "{$number1$}"
As pointed out in the Wiki, changes to settings after the instances are created won't be processed. But this is what happens when calling Smart.Default: it creates default SmartSettings.
Activity
axunonb commentedon Mar 23, 2023
This does not work:
As pointed out in the Wiki, changes to settings after the instances are created won't be processed. But this is what happens when calling
Smart.Default: it creates defaultSmartSettings.This works: