Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ dotnet_diagnostic.IDE1003.severity = silent
dotnet_diagnostic.IDE1004.severity = silent

# InvokeDelegateWithConditionalAccess
dotnet_diagnostic.IDE1005.severity = silent
dotnet_diagnostic.IDE1005.severity = warning

# NamingRule
dotnet_diagnostic.IDE1006.severity = silent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,11 +779,7 @@ private void FireOperationCreatedEvent(

OperationEventArgs args = new OperationEventArgs(
cancelOperation, operation, false);
OperationEventHandler temp = this.OnOperationCreated;
if (temp != null)
{
temp(this.session, args);
}
this.OnOperationCreated?.Invoke(this.session, args);
Comment thread
xtqqczze marked this conversation as resolved.

this.PostOperationCreateEvent(args);
}
Expand All @@ -803,11 +799,7 @@ private void FireOperationDeletedEvent(
OperationEventArgs args = new OperationEventArgs(
null, operation, success);
PreOperationDeleteEvent(args);
OperationEventHandler temp = this.OnOperationDeleted;
if (temp != null)
{
temp(this.session, args);
}
this.OnOperationDeleted?.Invoke(this.session, args);

this.PostOperationDeleteEvent(args);
this.RemoveOperation(operation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,7 @@ private void HandleJobOutput(Job job, TSession sessionForJob, bool discardNonPip
return;
}

if (outputAction != null)
{
outputAction(pso);
}
outputAction?.Invoke(pso);
};

job.Output.DataAdded +=
Expand Down
25 changes: 4 additions & 21 deletions src/System.Management.Automation/engine/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,12 +1511,7 @@ private Type GenerateEventHandler(MethodInfo invokeSignature)
/// </summary>
protected virtual void OnForwardEvent(PSEventArgs e)
{
EventHandler<PSEventArgs> eh = ForwardEvent;

if (eh != null)
{
eh(this, e);
}
ForwardEvent?.Invoke(this, e);
}

/// <summary>
Expand Down Expand Up @@ -1824,12 +1819,7 @@ public override void UnsubscribeEvent(PSEventSubscriber subscriber)
/// </summary>
protected virtual void OnForwardEvent(PSEventArgs e)
{
EventHandler<PSEventArgs> eh = ForwardEvent;

if (eh != null)
{
eh(this, e);
}
ForwardEvent?.Invoke(this, e);
}
}

Expand Down Expand Up @@ -2067,10 +2057,7 @@ public override int GetHashCode()

internal void OnPSEventUnsubscribed(object sender, PSEventUnsubscribedEventArgs e)
{
if (Unsubscribed != null)
{
Unsubscribed(sender, e);
}
Unsubscribed?.Invoke(sender, e);
}
}

Expand Down Expand Up @@ -2404,11 +2391,7 @@ public PSEventArgs this[int index]

private void OnPSEventReceived(object sender, PSEventArgs e)
{
PSEventReceivedEventHandler eventHandler = PSEventReceived;
if (eventHandler != null)
{
eventHandler(sender, e);
}
PSEventReceived?.Invoke(sender, e);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ internal void SetAsCompleted(Exception exception)
}

// call the user supplied callback
if (Callback != null)
{
Callback(this);
}
Callback?.Invoke(this);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,7 @@ public void Complete()

// A temporary variable is used as the Completed may
// reach null (because of -='s) after the null check
EventHandler tempCompleted = Completed;
if (tempCompleted != null)
{
tempCompleted(this, EventArgs.Empty);
}
Completed?.Invoke(this, EventArgs.Empty);
}

if (raiseDataAdded)
Expand Down Expand Up @@ -1405,22 +1401,14 @@ private void RaiseDataAddingEvent(Guid psInstanceId, object itemAdded)
{
// A temporary variable is used as the DataAdding may
// reach null (because of -='s) after the null check
EventHandler<DataAddingEventArgs> tempDataAdding = DataAdding;
if (tempDataAdding != null)
{
tempDataAdding(this, new DataAddingEventArgs(psInstanceId, itemAdded));
}
DataAdding?.Invoke(this, new DataAddingEventArgs(psInstanceId, itemAdded));
}

private void RaiseDataAddedEvent(Guid psInstanceId, int index)
{
// A temporary variable is used as the DataAdded may
// reach null (because of -='s) after the null check
EventHandler<DataAddedEventArgs> tempDataAdded = DataAdded;
if (tempDataAdded != null)
{
tempDataAdded(this, new DataAddedEventArgs(psInstanceId, index));
}
DataAdded?.Invoke(this, new DataAddedEventArgs(psInstanceId, index));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,7 @@ private void OnInternalPoolForwardEvent(object sender, PSEventArgs e)
/// </summary>
private void OnEventForwarded(PSEventArgs e)
{
EventHandler<PSEventArgs> eh = InternalForwardEvent;

if (eh != null)
{
eh(this, e);
}
InternalForwardEvent?.Invoke(this, e);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1640,12 +1640,7 @@ protected void AssertIfStateIsBeforeOpen()
/// </summary>
protected virtual void OnForwardEvent(PSEventArgs e)
{
EventHandler<PSEventArgs> eh = this.ForwardEvent;

if (eh != null)
{
eh(this, e);
}
this.ForwardEvent?.Invoke(this, e);
}

/// <summary>
Expand Down
8 changes: 3 additions & 5 deletions src/System.Management.Automation/engine/parser/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2265,11 +2265,9 @@ private Expression CaptureAstResults(
exprs.Add(Expression.Assign(resultList, Expression.New(CachedReflectionInfo.ObjectList_ctor)));
exprs.Add(Expression.Assign(s_getCurrentPipe, Expression.New(CachedReflectionInfo.Pipe_ctor, resultList)));
exprs.Add(Expression.Call(oldPipe, CachedReflectionInfo.Pipe_SetVariableListForTemporaryPipe, s_getCurrentPipe));
if (generateRedirectExprs != null)
{
// Add merge redirection expressions if delegate is provided.
generateRedirectExprs(exprs, finallyExprs);
}

// Add merge redirection expressions if delegate is provided.
generateRedirectExprs?.Invoke(exprs, finallyExprs);

exprs.Add(Compile(ast));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,7 @@ private void RaiseCompletedHandler(int operation, AsyncCompletedEventArgs eventA
#pragma warning disable 56500
try
{
if (handler != null)
{
handler(this, eventArgs);
}
handler?.Invoke(this, eventArgs);
}
catch (Exception exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,7 @@ internal void DisableFlowControlForPendingJobsQueue()
while (_actionsForUnblockingChildAdditions.Count > 0)
{
Action a = _actionsForUnblockingChildAdditions.Dequeue();
if (a != null)
{
a();
}
a?.Invoke();
}
}
}
Expand Down Expand Up @@ -406,10 +403,7 @@ internal void AddChildJobWithoutBlocking(StartableJob childJob, ChildJobFlags fl
}
else
{
if (jobEnqueuedAction != null)
{
jobEnqueuedAction();
}
jobEnqueuedAction?.Invoke();
}
}

Expand Down Expand Up @@ -746,10 +740,7 @@ private void childJob_StateChanged(object sender, JobStateEventArgs e)
if (_actionsForUnblockingChildAdditions.Count > 0)
{
Action a = _actionsForUnblockingChildAdditions.Dequeue();
if (a != null)
{
a();
}
a?.Invoke();
}

if (_cmdletMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ private void PerformURIRedirectionStep2(System.Uri newURI)
}

// raise warning to report the redirection
if (_uriRedirectionHandler != null)
{
_uriRedirectionHandler(newURI);
}
_uriRedirectionHandler?.Invoke(newURI);

// start a new connection
_transportManager.Redirect(newURI, _connectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ private void InvokeEndProcessingAction()
}

// Invoke action outside lock.
if (endProcessingAction != null)
{
endProcessingAction();
}
endProcessingAction?.Invoke();
}

private void CleanUpEndProcessing()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,7 @@ private void WriteCurrentFragmentAndReset()
}

// call the callback since we have data available
if (_onDataAvailableCallback != null)
{
_onDataAvailableCallback(data, _currentFragment.IsEndFragment);
}
_onDataAvailableCallback?.Invoke(data, _currentFragment.IsEndFragment);

// prepare a new fragment
_currentFragment.FragmentId = ++_fragmentId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,15 @@ public static class WSManServerChannelEvents
/// </summary>
internal static void RaiseShuttingDownEvent()
{
EventHandler handler = ShuttingDown;
if (handler != null)
{
handler(null, EventArgs.Empty);
}
ShuttingDown?.Invoke(null, EventArgs.Empty);
}

/// <summary>
/// Raising ActiveSessionsChanged event.
/// </summary>
internal static void RaiseActiveSessionsChangedEvent(ActiveSessionsChangedEventArgs eventArgs)
{
EventHandler<ActiveSessionsChangedEventArgs> handler = ActiveSessionsChanged;
if (handler != null)
{
handler(null, eventArgs);
}
ActiveSessionsChanged?.Invoke(null, eventArgs);
}

#endregion internal members
Expand Down
10 changes: 2 additions & 8 deletions src/System.Management.Automation/utils/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,12 @@ internal static class ExtensionMethods
{
public static void SafeInvoke(this EventHandler eventHandler, object sender, EventArgs eventArgs)
{
if (eventHandler != null)
{
eventHandler(sender, eventArgs);
}
eventHandler?.Invoke(sender, eventArgs);
}

public static void SafeInvoke<T>(this EventHandler<T> eventHandler, object sender, T eventArgs) where T : EventArgs
{
if (eventHandler != null)
{
eventHandler(sender, eventArgs);
}
eventHandler?.Invoke(sender, eventArgs);
}
}

Expand Down