Skip to content

GCop415 false alarm #308

Description

@sungam3r

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));
        }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions