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

CC0008: Don't suggest for dynamic objects #837

Closed
pascalberger opened this issue Sep 12, 2016 · 2 comments
Closed

CC0008: Don't suggest for dynamic objects #837

pascalberger opened this issue Sep 12, 2016 · 2 comments

Comments

@pascalberger
Copy link
Contributor

Bug

CC0008 currently suggests to use object initializer, even for dynamic objects.

dynamic email = new Email();
email.From = "foo@example.com";
email.To = "bar@example.com";

Current output after fix applied (if it is a code fix bug):

dynamic email = new Email()
{
    From = "foo@example.com",
    To = "bar@example.com"
}

Since this is a dynamic object, From and To might not be properties of the Email class and can therefore not be initialized with the object initializer syntax.

@giggio
Copy link
Member

giggio commented Sep 13, 2016

@pascalberger If From and To are not properties of the Email class the code will fail in the same way, will it not? The only difference is that the invocation is happening via dynamic dispatch in the first case, so CodeCracker will actually help you find an error.
The only scenario I can see this being a problem is with an ExpandoObject, or an object with similar patterns. So, in this scenario, this would raise an error where previously there was none, in a correct code. So, yes, this is a bug.

@giggio giggio added this to the 1.0.2 milestone Sep 13, 2016
@giggio giggio self-assigned this Nov 12, 2016
giggio added a commit to giggio/code-cracker that referenced this issue Jan 8, 2017
Fixes code-cracker#837

Signed-off-by: Giovanni Bassi <giggio@giggio.net>
@giggio
Copy link
Member

giggio commented Jan 9, 2017

Closed in #860.

@giggio giggio closed this as completed Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants