dotnet/roslyn

Extract method over-indents second line of expression

Open

#21,453 建立於 2017年8月11日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)C# (20,414 star) (4,257 fork)batch import
Area-IDEBugFeature - Extract MethodIDE-Formatterhelp wanted

描述

Version Used: 15.3 Preview 7

:link: Originally revealed by ExtractMethodTests.TestUseExpressionWhenOnSingleLine_AndNotIsOnSingleLine in #21439.

Steps to Reproduce:

  1. Use the following code

    using System;
    
    namespace ConsoleApp5
    {
        class Program
        {
            static void Main(string[] args)
            {
                bool b = true;
                Console.WriteLine(b !=
                    true ? b = true : b = false);
            }
        }
    }
    
  2. Select b != true

  3. Apply the Extract Method refactoring

Expected Behavior:

using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;
            Console.WriteLine(NewMethod(b) ? b = true : b = false);
        }

        private static bool NewMethod(bool b)
        {
            return b !=
                true;
        }
    }
}

Actual Behavior:

using System;

namespace ConsoleApp5
{
    class Program
    {
        static void Main(string[] args)
        {
            bool b = true;
            Console.WriteLine(NewMethod(b) ? b = true : b = false);
        }

        private static bool NewMethod(bool b)
        {
            return b !=
                            true;
        }
    }
}

貢獻者指南