Skip to content

A dictionary type that only implements the generic IDictionary interface doesn't support dot notation (property-access syntax) #17190

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Related:

[Tomlyn.Model.TomlTable], from the Tomlyn package, is an example of a type that implements IDictionary`2, but not also its non-generic counterpart, IDictionary.

Seemingly, this prevents use of dot notation (property-access syntax via the member-access operator) to access the dictionary's entries.

# Determine the package's local installation location.
# If it isn't installed, install it first, in the current user's scope.
while (-not ($installDir = (Get-Package -ErrorAction Ignore -ProviderName NuGet Tomlyn).Source)) {
  $null = Install-Package -Scope CurrentUser -ErrorAction Stop -ProviderName NuGet Tomlyn
}

# Load the package's assembly into the session.
Add-Type -ErrorAction Stop -LiteralPath (Join-Path $installDir '../lib/netstandard2.0/Tomlyn.dll')

# Define a sample TOML string to parse.
$tomlStr = @'
foo = "bar"
'@

# Parse the TOML string into an object mod)el (nested dictionaries).
$tomlTable = [Tomlyn.Toml]::ToModel($tomlStr)

# Output the global section's 'foo' value,
# first via an indexer, then via dot notation.
$tomlTable['foo'], $tomlTable.foo | ForEach-Object { "[$_]" }

Expected behavior

[bar]
[bar]

Actual behavior

[bar]
[]

Error details

No response

Environment data

PowerShell Core 7.3.0-preview.3

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions