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

GCop415 false alarm #308

Open
sungam3r opened this issue May 1, 2019 · 0 comments
Open

GCop415 false alarm #308

sungam3r opened this issue May 1, 2019 · 0 comments

Comments

@sungam3r
Copy link
Contributor

sungam3r commented May 1, 2019

It seems to me that this rule should take method overloads into account.

  internal class Program
  {
        internal static void DoSomething(object input)
        {
            switch (input)
            {
                case int value:
                    Do(value);
                    break;
                case string value:
                    Do(value); // GCop415 The same code is repeated in multiple IF branches. Instead update the IF condition to cover both scenarios.
                    break;
                case DateTime value:
                    Do(value); // GCop415 The same code is repeated in multiple IF branches. Instead update the IF condition to cover both scenarios.
                    break;
                default:
                    throw new NotImplementedException();
            }
        }

        private static void Do(int value)
        {
            Console.Write(value + 1);
        }

        private static void Do(string value)
        {
            Console.WriteLine(value.Substring(1, 4));
        }

        private static void Do(DateTime value)
        {
            Console.WriteLine(value.AddDays(2));
        }
}
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

1 participant