Skip to content

ExpandoObject.ContainsKey and ExpandoObject.Keys.Contains return different results #39897

@loftyinclination

Description

@loftyinclination

I'm attempting to test whether an ExpandoObject contains a given key. The object is created, the key added, and then removed. Using the IDictionary.ContainsKey method returns false, but using IDictionary.Keys.Contains returns true.

This seems to be because the ExpandoObject.Remove method does not actually remove the key from the private _data field, but instead sets the value to ExpandoObject.Uninitialized. Then, the ExpandoObject.KeyCollection.Contains method does not check whether or data stored the ExpandoObject._data is Uninitialized, as ContainsKey does.

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