All docs
V19.2
19.2
19.1
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Inline Lambda

  • 2 min to read

Purpose

This refactoring creates a lambda expression and inlines a referenced delegate. If there is only one reference to a delegate method, the Inline Lambda refactoring deletes the delegate method. Use this Refactoring to create the delegate in a lambda syntax.

Availability

Available when the caret is in a method reference within a delegate creation statement.

How to Use

  1. Place the caret on a method reference within a delegate creation statement.

    Note

    The blinking cursor shows the caret's position at which the Refactoring is available.

namespace Inline {   
    public partial class UserControl1 : UserControl {
        public UserControl1() {
            InitializeComponent();

            Loaded += UserControl1_Loaded;
        }

        private void UserControl1_Loaded(object sender, RoutedEventArgs e) {
            if(sender != null)
                sender.ToString();
        }
    }
}
  1. Use the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions Menu.

  2. Select Inline Lambda from the menu.

After execution, this Refactoring creates a lambda expression and inlines the referenced delegate.

namespace Inline {   
    public partial class UserControl1 : UserControl {
        public UserControl1() {
            InitializeComponent();

            Loaded += (sender, e) =>
            {
                if (sender != null)
                    sender.ToString();
            };
        }
    }
}