Skip to content

[BUG] REFL018 on ExpandoObject #216

Open
@jzabroski

Description

@jzabroski

Library Version Info

Confirmed repro on latest on nuget.org repository:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
    <PackageReference Include="ReflectionAnalyzers" Version="0.1.20-dev">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
</Project>

Bad

dynamic expando = new ExpandoObject();

expando.name = "John"; // fine

Console.WriteLine(expando["name"] // BAD - expando explicitly implements the IDictionary<TKey, TValue> interface

Correct

((IDictionary<String, Object>)expando)["name"]

I believe this is a bug in REFL018. I believe the issue is due to the dynamic keyword silencing errors, but that is just a hunch - I have done zero debugging so far.

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