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 @@ -817,7 +817,7 @@ dotnet_diagnostic.IDE0029.severity = silent
dotnet_diagnostic.IDE0030.severity = silent

# IDE0031: UseNullPropagation
dotnet_diagnostic.IDE0031.severity = silent
dotnet_diagnostic.IDE0031.severity = warning

# IDE0032: UseAutoProperty
dotnet_diagnostic.IDE0032.severity = silent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public CimInstance NewEvent
{
get
{
return (result == null) ? null : result.Instance;
return result?.Instance;
}
}

Expand All @@ -92,7 +92,7 @@ public string MachineId
{
get
{
return (result == null) ? null : result.MachineId;
return result?.MachineId;
}
}

Expand All @@ -103,7 +103,7 @@ public string Bookmark
{
get
{
return (result == null) ? null : result.Bookmark;
return result?.Bookmark;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private void InitializeErrorRecordCore(CimJobContext jobContext, Exception excep
exception: exception,
errorId: errorId,
errorCategory: errorCategory,
targetObject: jobContext != null ? jobContext.TargetObject : null);
targetObject: jobContext?.TargetObject);

if (jobContext != null)
{
Expand Down Expand Up @@ -242,7 +242,7 @@ private void InitializeErrorRecord(CimJobContext jobContext, CimException cimExc
if (cimException.ErrorData != null)
{
_errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
_errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null;
_errorRecord.CategoryInfo.TargetType = jobContext?.CmdletizationClassName;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter m
Dbg.Assert(this.MethodSubject != null, "MethodSubject property should be initialized before starting main job processing");

CimMethodParameter outParameter = methodResult.OutParameters[methodParameter.Name];
object valueReturnedFromMethod = (outParameter == null) ? null : outParameter.Value;
object valueReturnedFromMethod = outParameter?.Value;

object dotNetValue = CimValueConverter.ConvertFromCimToDotNet(valueReturnedFromMethod, methodParameter.ParameterType);
if (MethodParameterBindings.Out == (methodParameter.Bindings & MethodParameterBindings.Out))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ internal static string GetLocaleName(string locale)
}
}

return culture == null ? null : culture.Name;
return culture?.Name;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ObjectCmdletBase : PSCmdlet
[System.Diagnostics.CodeAnalysis.SuppressMessage("GoldMan", "#pw17903:UseOfLCID", Justification = "The CultureNumber is only used if the property has been set with a hex string starting with 0x")]
public string Culture
{
get { return _cultureInfo != null ? _cultureInfo.ToString() : null; }
get { return _cultureInfo?.ToString(); }

set
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal static StringBuilder GetRawContentHeader(HttpResponseMessage response)
HttpHeaders[] headerCollections =
{
response.Headers,
response.Content == null ? null : response.Content.Headers
response.Content?.Headers
};

foreach (var headerCollection in headerCollections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ internal static PSControlGroupBy Get(GroupBy groupBy)
return new PSControlGroupBy
{
Expression = new DisplayEntry(expressionToken),
Label = (groupBy.startGroup.labelTextToken != null) ? groupBy.startGroup.labelTextToken.text : null
Label = groupBy.startGroup.labelTextToken?.text
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ internal Type TargetType
{
get
{
return _convertTypes == null
? null
: _convertTypes.LastOrDefault();
return _convertTypes?.LastOrDefault();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4224,7 +4224,7 @@ private void RestoreDefaultParameterValues(IEnumerable<MergedCompiledCommandPara

if (error != null)
{
Type specifiedType = (argumentToBind.ArgumentValue == null) ? null : argumentToBind.ArgumentValue.GetType();
Type specifiedType = argumentToBind.ArgumentValue?.GetType();
ParameterBindingException bindingException =
new ParameterBindingException(
error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static CommandCompletion CompleteInput(string input, int cursorIndex, Has
}

// If we are in a debugger stop, let the debugger do the command completion.
var debugger = (powershell.Runspace != null) ? powershell.Runspace.Debugger : null;
var debugger = powershell.Runspace?.Debugger;
if ((debugger != null) && debugger.InBreakpoint)
{
return CompleteInputInDebugger(input, cursorIndex, options, debugger);
Expand Down Expand Up @@ -236,7 +236,7 @@ public static CommandCompletion CompleteInput(Ast ast, Token[] tokens, IScriptPo
}

// If we are in a debugger stop, let the debugger do the command completion.
var debugger = (powershell.Runspace != null) ? powershell.Runspace.Debugger : null;
var debugger = powershell.Runspace?.Debugger;
if ((debugger != null) && debugger.InBreakpoint)
{
return CompleteInputInDebugger(ast, tokens, cursorPosition, options, debugger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ internal AstPair(CommandParameterAst parameterAst, ExpressionAst argumentAst)
ParameterArgumentType = AstParameterArgumentType.AstPair;
ParameterSpecified = parameterAst != null;
ArgumentSpecified = argumentAst != null;
ParameterName = parameterAst != null ? parameterAst.ParameterName : null;
ParameterText = parameterAst != null ? parameterAst.ParameterName : null;
ArgumentType = argumentAst != null ? argumentAst.StaticType : null;
ParameterName = parameterAst?.ParameterName;
ParameterText = parameterAst?.ParameterName;
ArgumentType = argumentAst?.StaticType;

ParameterContainsArgument = false;
Argument = argumentAst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ private void WriteInputObjectError(
string errorId,
params object[] args)
{
Type inputObjectType = (inputObject == null) ? null : inputObject.GetType();
Type inputObjectType = inputObject?.GetType();

ParameterBindingException bindingException = new ParameterBindingException(
ErrorCategory.InvalidArgument,
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/EventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,7 @@ public class PSEventJob : Job
/// </param>
/// </summary>
public PSEventJob(PSEventManager eventManager, PSEventSubscriber subscriber, ScriptBlock action, string name) :
base(action == null ? null : action.ToString(), name)
base(action?.ToString(), name)
{
if (eventManager == null)
throw new ArgumentNullException(nameof(eventManager));
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/ExternalScriptInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ internal string RequiresApplicationID
get
{
var data = GetRequiresData();
return data == null ? null : data.RequiredApplicationId;
return data?.RequiredApplicationId;
}
}

Expand All @@ -417,7 +417,7 @@ internal Version RequiresPSVersion
get
{
var data = GetRequiresData();
return data == null ? null : data.RequiredPSVersion;
return data?.RequiredPSVersion;
}
}

Expand All @@ -426,7 +426,7 @@ internal IEnumerable<string> RequiresPSEditions
get
{
var data = GetRequiresData();
return data == null ? null : data.RequiredPSEditions;
return data?.RequiredPSEditions;
}
}

Expand All @@ -435,7 +435,7 @@ internal IEnumerable<ModuleSpecification> RequiresModules
get
{
var data = GetRequiresData();
return data == null ? null : data.RequiredModules;
return data?.RequiredModules;
}
}

Expand All @@ -458,7 +458,7 @@ internal IEnumerable<PSSnapInSpecification> RequiresPSSnapIns
get
{
var data = GetRequiresData();
return data == null ? null : data.RequiresPSSnapIns;
return data?.RequiresPSSnapIns;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private static ErrorRecord GetErrorRecordForRemotePipelineInvocation(Exception i
Exception outerException = new InvalidOperationException(errorMessage, innerException);

RemoteException remoteException = innerException as RemoteException;
ErrorRecord remoteErrorRecord = remoteException != null ? remoteException.ErrorRecord : null;
ErrorRecord remoteErrorRecord = remoteException?.ErrorRecord;
string errorId = remoteErrorRecord != null ? remoteErrorRecord.FullyQualifiedErrorId : innerException.GetType().Name;
ErrorCategory errorCategory = remoteErrorRecord != null ? remoteErrorRecord.CategoryInfo.Category : ErrorCategory.NotSpecified;
ErrorRecord errorRecord = new ErrorRecord(outerException, errorId, errorCategory, null);
Expand Down
14 changes: 7 additions & 7 deletions src/System.Management.Automation/engine/ParameterBinderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ internal virtual bool BindParameter(
GetErrorExtent(parameter),
parameterMetadata.Name,
parameterMetadata.Type,
(parameterValue == null) ? null : parameterValue.GetType(),
parameterValue?.GetType(),
ParameterBinderStrings.ParameterArgumentTransformationError,
"ParameterArgumentTransformationError",
e.Message);
Expand Down Expand Up @@ -522,7 +522,7 @@ internal virtual bool BindParameter(
GetErrorExtent(parameter),
parameterMetadata.Name,
parameterMetadata.Type,
(parameterValue == null) ? null : parameterValue.GetType(),
parameterValue?.GetType(),
ParameterBinderStrings.ParameterArgumentValidationError,
"ParameterArgumentValidationError",
e.Message);
Expand Down Expand Up @@ -586,7 +586,7 @@ internal virtual bool BindParameter(

if (bindError != null)
{
Type specifiedType = (parameterValue == null) ? null : parameterValue.GetType();
Type specifiedType = parameterValue?.GetType();
ParameterBindingException bindingException =
new ParameterBindingException(
bindError,
Expand Down Expand Up @@ -736,7 +736,7 @@ private void ValidateNullOrEmptyArgument(
GetErrorExtent(parameter),
parameterMetadata.Name,
parameterMetadata.Type,
(parameterValue == null) ? null : parameterValue.GetType(),
parameterValue?.GetType(),
ParameterBinderStrings.ParameterArgumentValidationErrorEmptyStringNotAllowed,
"ParameterArgumentValidationErrorEmptyStringNotAllowed");
throw bindingException;
Expand Down Expand Up @@ -813,7 +813,7 @@ private void ValidateNullOrEmptyArgument(
GetErrorExtent(parameter),
parameterMetadata.Name,
parameterMetadata.Type,
(parameterValue == null) ? null : parameterValue.GetType(),
parameterValue?.GetType(),
resourceString,
errorId);
throw bindingException;
Expand Down Expand Up @@ -1781,7 +1781,7 @@ private object EncodeCollection(
GetErrorExtent(argument),
parameterName,
toType,
(currentValueElement == null) ? null : currentValueElement.GetType(),
currentValueElement?.GetType(),
ParameterBinderStrings.CannotConvertArgument,
"CannotConvertArgument",
currentValueElement ?? "null",
Expand Down Expand Up @@ -1878,7 +1878,7 @@ private object EncodeCollection(
GetErrorExtent(argument),
parameterName,
toType,
(currentValue == null) ? null : currentValue.GetType(),
currentValue?.GetType(),
ParameterBinderStrings.CannotConvertArgument,
"CannotConvertArgument",
currentValue ?? "null",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal RuntimeDefinedParameterBinder(
{
string key = pair.Key;
RuntimeDefinedParameter pp = pair.Value;
string ppName = (pp == null) ? null : pp.Name;
string ppName = pp?.Name;
if (pp == null || key != ppName)
{
ParameterBindingException bindingException =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ internal PSVariable SetVariable(string name, object value, bool asValue, bool fo
}
else
{
variable = (LocalsTuple != null ? LocalsTuple.TrySetVariable(name, value) : null) ?? new PSVariable(name, value);
variable = (LocalsTuple?.TrySetVariable(name, value)) ?? new PSVariable(name, value);
}

if (ExecutionContext.HasEverUsedConstrainedLanguage)
Expand Down
8 changes: 4 additions & 4 deletions src/System.Management.Automation/engine/debugger/debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ private List<VariableBreakpoint> GetVariableBreakpointsToTrigger(string variable
return null;

var callStackInfo = _callStack.Last();
var currentScriptFile = (callStackInfo != null) ? callStackInfo.File : null;
var currentScriptFile = callStackInfo?.File;
return breakpoints.Values.Where(bp => bp.Trigger(currentScriptFile, read: read)).ToList();
}
finally
Expand Down Expand Up @@ -1633,7 +1633,7 @@ internal CallStackInfo Last()
internal FunctionContext LastFunctionContext()
{
var last = Last();
return last != null ? last.FunctionContext : null;
return last?.FunctionContext;
}

internal bool Any()
Expand Down Expand Up @@ -3678,7 +3678,7 @@ private void RemoveFromRunningRunspaceList(Runspace runspace)
}

// Clean up nested debugger.
NestedRunspaceDebugger nestedDebugger = (runspaceInfo != null) ? runspaceInfo.NestedDebugger : null;
NestedRunspaceDebugger nestedDebugger = runspaceInfo?.NestedDebugger;
if (nestedDebugger != null)
{
nestedDebugger.DebuggerStop -= HandleMonitorRunningRSDebuggerStop;
Expand Down Expand Up @@ -4449,7 +4449,7 @@ protected virtual DebuggerCommandResults HandlePromptCommand(PSDataCollection<PS
{
// Nested debugged runspace prompt should look like:
// [ComputerName]: [DBG]: [Process:<id>]: [RunspaceName]: PS C:\>
string computerName = (_runspace.ConnectionInfo != null) ? _runspace.ConnectionInfo.ComputerName : null;
string computerName = _runspace.ConnectionInfo?.ComputerName;
string processPartPattern = "{0}[{1}:{2}]:{3}";
string processPart = StringUtil.Format(processPartPattern,
@"""",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ internal void UpdateRunspaceAvailability(PipelineState pipelineState, bool raise
{
RemoteRunspace remoteRunspace = this as RemoteRunspace;
RemoteDebugger remoteDebugger = (remoteRunspace != null) ? remoteRunspace.Debugger as RemoteDebugger : null;
Internal.ConnectCommandInfo remoteCommand = (remoteRunspace != null) ? remoteRunspace.RemoteCommand : null;
Internal.ConnectCommandInfo remoteCommand = remoteRunspace?.RemoteCommand;
if (((pipelineState == PipelineState.Completed) || (pipelineState == PipelineState.Failed) ||
((pipelineState == PipelineState.Stopped) && (this.RunspaceStateInfo.State == RunspaceState.Opened)))
&& (remoteCommand != null) && (cmdInstanceId != null) && (remoteCommand.CommandId == cmdInstanceId))
Expand Down Expand Up @@ -1590,7 +1590,7 @@ public virtual Debugger Debugger
get
{
var context = GetExecutionContext;
return (context != null) ? context.Debugger : null;
return context?.Debugger;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ private int GetHistorySize()
{
int historySize = 0;
var executionContext = LocalPipeline.GetExecutionContextFromTLS();
object obj = (executionContext != null) ? executionContext.GetVariableValue(SpecialVariables.HistorySizeVarPath) : null;
object obj = executionContext?.GetVariableValue(SpecialVariables.HistorySizeVarPath);
if (obj != null)
{
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public InstructionArray ToArray()
_maxStackDepth,
_maxContinuationDepth,
_instructions.ToArray(),
(_objects != null) ? _objects.ToArray() : null,
_objects?.ToArray(),
BuildRuntimeLabels(),
_debugCookies
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ private void CompileTryExpression(Expression expr)
enterTryInstr.SetTryHandler(
new TryCatchFinallyHandler(tryStart, tryEnd, gotoEnd.TargetIndex,
startOfFinally.TargetIndex, _instructions.Count,
exHandlers != null ? exHandlers.ToArray() : null));
exHandlers?.ToArray()));
PopLabelBlock(LabelScopeKind.Finally);
}
else
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/engine/lang/parserutils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ internal static object ImplicitOp(object lval, object rval, string op, IScriptEx
lval = PSObject.Base(lval);
rval = PSObject.Base(rval);

Type lvalType = lval != null ? lval.GetType() : null;
Type rvalType = rval != null ? rval.GetType() : null;
Type lvalType = lval?.GetType();
Type rvalType = rval?.GetType();
Type opType;
if (lvalType == null || (lvalType.IsPrimitive))
{
Expand Down
Loading