Skip to content

Is IReadOnlyDictionary supported as DictionarySource? #340

Closed

Description

@dombrovsky

Is your feature request related to a problem? Please describe.
If arguments for formatting are coming as IReadOnlyDictionary (not upcastable to IDictionary), there is no built in Source that can handle it.
,
Describe the solution you'd like
Should be a straightforward piece to add IReadOnlyDictionary support to DictionarySource, same way as it handles IDictionary.

Describe alternatives you've considered
Workaround is to convert IReadOnlyDictionary to IDictionary, but that would cause additional allocations.
There is always a possibility to implement custom Source on consumer side.

Activity

  1. axunonb commented on Jul 17, 2023

    @axunonb
    Member

    You're saying that this tests fails for SmartFormat v3.2.1?

    [Test]
    public void ReadOnlyDictionaryTest()
    {
        var dict = new Dictionary<string, object> { { "One", 1 }, { "Two", 2 }, { "Three", 3 }, };
        var roDict = new ReadOnlyDictionary<string, object>(dict);
    
        var formatter = Smart.CreateDefaultSmartFormat();
        var result = formatter.Format("{One}{Two}{Three}", roDict);
    
        Assert.That(result, Is.EqualTo("123"));
    }
  2. changed the title [-]Support IReadOnlyDictionary is DictionarySource[/-] [+]Is IReadOnlyDictionary supported as DictionarySource?[/+] on Jul 20, 2023
  3. locked and limited conversation to collaborators on Jul 20, 2023
  4. converted this issue into a discussion #342 on Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions