Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] REFL018 on ExpandoObject #216

Open
jzabroski opened this issue Apr 26, 2019 · 5 comments
Open

[BUG] REFL018 on ExpandoObject #216

jzabroski opened this issue Apr 26, 2019 · 5 comments

Comments

@jzabroski
Copy link

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.

@JohanLarsson
Copy link
Collaborator

Thanks for reporting!

@JohanLarsson
Copy link
Collaborator

The bug is that there is no warning when doing expando["name"]?

@jzabroski
Copy link
Author

I need to look. I don't know what REFL018 is. ExpandoObject explicitly implements the IDictionary interface, so my bad vs correct breakdown of usage is correct.

@JohanLarsson
Copy link
Collaborator

I'm thinking maybe this is a new ID for checking use of dynamic.

@jnm2
Copy link
Collaborator

jnm2 commented Jan 26, 2020

Why is explicit dictionary access better?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants