Skip to content

IDE0004 Cast is redundant from class to interface only for fields #34326

@Materix

Description

@Materix

Visual Studio 2017 Version 15.9.9

Steps to Reproduce:

public class MyContext : DbContext { }

public class Class
{
    private readonly MyContext _context;
    private readonly DbContext _dbContext;

    public Class(MyContext context)
    {
        _dbContext = context;
        _context = context;

        ((IDisposable)_context).Dispose();
        ((IDisposable)_dbContext).Dispose();

        ((IDisposable)context).Dispose();
        DbContext dbContext = _context;
        ((IDisposable)dbContext).Dispose();
    }
}

obraz

Expected Behavior:
Show IDE0004 message for all cast

Actual Behavior:
IDE0004 was only shown when casting for fields

Metadata

Metadata

Labels

Area-IDEBugIDE-CodeStyleBuilt-in analyzers, fixes, and refactoringsResolution-FixedThe bug has been fixed and/or the requested behavior has been implemented

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions