Enable IDE1005: InvokeDelegateWithConditionalAccess (#13911)
* Enable IDE1005: InvokeDelegateWithConditionalAccess https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide1005
This commit is contained in:
parent
432dd56ea8
commit
20401c9583
@ -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
|
||||
|
@ -779,11 +779,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
|
||||
OperationEventArgs args = new OperationEventArgs(
|
||||
cancelOperation, operation, false);
|
||||
OperationEventHandler temp = this.OnOperationCreated;
|
||||
if (temp != null)
|
||||
{
|
||||
temp(this.session, args);
|
||||
}
|
||||
this.OnOperationCreated?.Invoke(this.session, args);
|
||||
|
||||
this.PostOperationCreateEvent(args);
|
||||
}
|
||||
@ -803,11 +799,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
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);
|
||||
|
@ -246,10 +246,7 @@ namespace Microsoft.PowerShell.Cmdletization
|
||||
return;
|
||||
}
|
||||
|
||||
if (outputAction != null)
|
||||
{
|
||||
outputAction(pso);
|
||||
}
|
||||
outputAction?.Invoke(pso);
|
||||
};
|
||||
|
||||
job.Output.DataAdded +=
|
||||
|
@ -1511,12 +1511,7 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
protected virtual void OnForwardEvent(PSEventArgs e)
|
||||
{
|
||||
EventHandler<PSEventArgs> eh = ForwardEvent;
|
||||
|
||||
if (eh != null)
|
||||
{
|
||||
eh(this, e);
|
||||
}
|
||||
ForwardEvent?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1824,12 +1819,7 @@ namespace System.Management.Automation
|
||||
/// </summary>
|
||||
protected virtual void OnForwardEvent(PSEventArgs e)
|
||||
{
|
||||
EventHandler<PSEventArgs> eh = ForwardEvent;
|
||||
|
||||
if (eh != null)
|
||||
{
|
||||
eh(this, e);
|
||||
}
|
||||
ForwardEvent?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2067,10 +2057,7 @@ namespace System.Management.Automation
|
||||
|
||||
internal void OnPSEventUnsubscribed(object sender, PSEventUnsubscribedEventArgs e)
|
||||
{
|
||||
if (Unsubscribed != null)
|
||||
{
|
||||
Unsubscribed(sender, e);
|
||||
}
|
||||
Unsubscribed?.Invoke(sender, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2404,11 +2391,7 @@ namespace System.Management.Automation
|
||||
|
||||
private void OnPSEventReceived(object sender, PSEventArgs e)
|
||||
{
|
||||
PSEventReceivedEventHandler eventHandler = PSEventReceived;
|
||||
if (eventHandler != null)
|
||||
{
|
||||
eventHandler(sender, e);
|
||||
}
|
||||
PSEventReceived?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -152,10 +152,7 @@ namespace System.Management.Automation.Runspaces
|
||||
}
|
||||
|
||||
// call the user supplied callback
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(this);
|
||||
}
|
||||
Callback?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -560,11 +560,7 @@ namespace System.Management.Automation
|
||||
|
||||
// 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)
|
||||
@ -1405,22 +1401,14 @@ namespace System.Management.Automation
|
||||
{
|
||||
// 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>
|
||||
|
@ -837,12 +837,7 @@ namespace System.Management.Automation.Runspaces
|
||||
/// </summary>
|
||||
private void OnEventForwarded(PSEventArgs e)
|
||||
{
|
||||
EventHandler<PSEventArgs> eh = InternalForwardEvent;
|
||||
|
||||
if (eh != null)
|
||||
{
|
||||
eh(this, e);
|
||||
}
|
||||
InternalForwardEvent?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1640,12 +1640,7 @@ namespace System.Management.Automation.Runspaces.Internal
|
||||
/// </summary>
|
||||
protected virtual void OnForwardEvent(PSEventArgs e)
|
||||
{
|
||||
EventHandler<PSEventArgs> eh = this.ForwardEvent;
|
||||
|
||||
if (eh != null)
|
||||
{
|
||||
eh(this, e);
|
||||
}
|
||||
this.ForwardEvent?.Invoke(this, e);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -2265,11 +2265,9 @@ namespace System.Management.Automation.Language
|
||||
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));
|
||||
|
||||
|
@ -342,10 +342,7 @@ namespace System.Management.Automation
|
||||
#pragma warning disable 56500
|
||||
try
|
||||
{
|
||||
if (handler != null)
|
||||
{
|
||||
handler(this, eventArgs);
|
||||
}
|
||||
handler?.Invoke(this, eventArgs);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
@ -337,10 +337,7 @@ namespace System.Management.Automation
|
||||
while (_actionsForUnblockingChildAdditions.Count > 0)
|
||||
{
|
||||
Action a = _actionsForUnblockingChildAdditions.Dequeue();
|
||||
if (a != null)
|
||||
{
|
||||
a();
|
||||
}
|
||||
a?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,10 +403,7 @@ namespace System.Management.Automation
|
||||
}
|
||||
else
|
||||
{
|
||||
if (jobEnqueuedAction != null)
|
||||
{
|
||||
jobEnqueuedAction();
|
||||
}
|
||||
jobEnqueuedAction?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
@ -746,10 +740,7 @@ namespace System.Management.Automation
|
||||
if (_actionsForUnblockingChildAdditions.Count > 0)
|
||||
{
|
||||
Action a = _actionsForUnblockingChildAdditions.Dequeue();
|
||||
if (a != null)
|
||||
{
|
||||
a();
|
||||
}
|
||||
a?.Invoke();
|
||||
}
|
||||
|
||||
if (_cmdletMode)
|
||||
|
@ -444,10 +444,7 @@ namespace System.Management.Automation.Remoting
|
||||
}
|
||||
|
||||
// raise warning to report the redirection
|
||||
if (_uriRedirectionHandler != null)
|
||||
{
|
||||
_uriRedirectionHandler(newURI);
|
||||
}
|
||||
_uriRedirectionHandler?.Invoke(newURI);
|
||||
|
||||
// start a new connection
|
||||
_transportManager.Redirect(newURI, _connectionInfo);
|
||||
|
@ -105,10 +105,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
}
|
||||
|
||||
// Invoke action outside lock.
|
||||
if (endProcessingAction != null)
|
||||
{
|
||||
endProcessingAction();
|
||||
}
|
||||
endProcessingAction?.Invoke();
|
||||
}
|
||||
|
||||
private void CleanUpEndProcessing()
|
||||
|
@ -811,10 +811,7 @@ namespace System.Management.Automation.Remoting
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
@ -30,11 +30,7 @@ namespace System.Management.Automation.Remoting.WSMan
|
||||
/// </summary>
|
||||
internal static void RaiseShuttingDownEvent()
|
||||
{
|
||||
EventHandler handler = ShuttingDown;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(null, EventArgs.Empty);
|
||||
}
|
||||
ShuttingDown?.Invoke(null, EventArgs.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -42,11 +38,7 @@ namespace System.Management.Automation.Remoting.WSMan
|
||||
/// </summary>
|
||||
internal static void RaiseActiveSessionsChangedEvent(ActiveSessionsChangedEventArgs eventArgs)
|
||||
{
|
||||
EventHandler<ActiveSessionsChangedEventArgs> handler = ActiveSessionsChanged;
|
||||
if (handler != null)
|
||||
{
|
||||
handler(null, eventArgs);
|
||||
}
|
||||
ActiveSessionsChanged?.Invoke(null, eventArgs);
|
||||
}
|
||||
|
||||
#endregion internal members
|
||||
|
@ -12,18 +12,12 @@ namespace System.Management.Automation
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user