Skip to content

No support in ExpandoObject for case-insensitive #41831

Closed

Description

@steveharter

Background and Motivation

A common use case of creating an ExpandoObject is based on reading XML or JSON which may be in mixed case for the same values (e.g. Pascal-cased on server, camel-cased on client). Currently there is no way, other than using obsolete methods, to configure an ExpandoObject to be case-insensitive. This means users must duplicate the code from ExpandoObject or implement a derived class from DynamicObject.

For context, see https://stackoverflow.com/questions/7760035/how-to-set-expandoobjects-dictionary-as-case-insensitive.

This capability may be used when implementing support for ExpandoObject in System.Text.Json

Proposed API

namespace System.Dynamic
{
    public class ExpandoObject
    {
        + public ExpandoObject(bool caseInsensitive);
    }
}

Usage Examples

// Raw usage
dynamic obj = new ExpandoObject(caseInsensitive: true);
obj.A = 42;
Debug.Assert(obj.A == 42);
Debug.Assert(obj.a == 42);

// When used by STJ deserialization
var options = new JsonSerializerOptions();
options.PropertyNameCaseInsensitive = true;
dynamic obj = JsonSerializer.Deserialize<dynamic>(@"{""A"":42}", options);
Debug.Assert(obj.A == 42);
Debug.Assert(obj.a == 42);

Implementation

The internal implementation appears to support case-insensitivity.

Activity

  1. added
    api-suggestion
    on Sep 3, 2020
  2. added
    untriaged
    on Sep 3, 2020
  3. removed
    untriaged
    on Sep 14, 2020
  4. added this to the Future milestone on Sep 14, 2020
  5. steveharter commented on Sep 22, 2020

    @steveharter
    ContributorAuthor

    If we get support for case-insensitive here, then it makes sense to support an ExpandoObject custom converter for System.Text.Json serialization. Without case-insensitive support, a custom converter would be somewhat broken so we likely wouldn't want to add and support that implementation.

    A benefit of adding a custom converter, besides matching the casing support in JsonSerializerOptions, is to use the property naming policy.

    An alternative to ExpandoObject in prototype form for System.Text.Json exists at #42097. See also Also see #29690.

  6. added
    backlog-cleanup-candidate
    on Mar 24, 2025
  7. dotnet-policy-service commented on Apr 8, 2025

    @dotnet-policy-service
    Contributor

    This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  8. removed this from the Future milestone on Apr 8, 2025
  9. locked and limited conversation to collaborators on May 8, 2025
  10. removed
    backlog-cleanup-candidate
    on May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Linq.Expressions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions