Skip to content

Two solutions for IDE0004 Cast is redundant suggested, but no preference expressed. #6793

@martineyles

Description

@martineyles

To send a nullable int to a SQL database it must been unboxed, cast to object and have null values replaced with DBNull. I created a method to do this in a data access object:

public object SQLNullableObject(int? input)
{
    return input.HasValue ? (object)input.Value : (object)DBNull.Value;
}

The compiler shows to suggestions that the cast to object is not required. Both of these fixes appear valid on their own. Applying one removes the other auto-fix, as in both cases this would break the code, as the if statement has to give only one type of output.

Perhaps only one of these changes should be suggested, though I don't know which would be considered the better change if any, or perhaps neither should be suggested for the sake of code clarity.

Metadata

Metadata

Labels

Area-IDEResolution-Won't FixA real bug, but Triage feels that the issue is not impactful enough to spend time on.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions