Skip to content

Issue adding a custom selector in 3.2.1 #334

@mg72266

Description

@mg72266

Hello,

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$}"

Is there away to get this to work in 3.2.1?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions