Skip to content

GCop415 false alarm #308

@sungam3r

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

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