Sunday, August 9, 2015

Convert existing event handler invocations to C#6 Null Propagation

Search for:

if \(handler \!= null\)\s*\r?\n\s*\{\r?\n\s*handler\((?<args>.*?)\);\r?\n\s*\}
and replace using:
handler?.Invoke(${args});

For example, this will be matched and replaced

if (handler != null)
{
    handler(this, new DialogResponseEventArgs(id, true));
}

with this
handler?.Invoke(this, new DialogResponseEventArgs(this.dialogCorrelationId, message.Response == ShellDialogButton.Cancel));

No comments:

Post a Comment