mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Apply IDE0019: InlineAsTypeCheck in Microsoft.Management (#19687)
This commit is contained in:
@@ -344,16 +344,14 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
/// <returns></returns>
|
||||
protected object GetBaseObject(object value)
|
||||
{
|
||||
PSObject psObject = value as PSObject;
|
||||
if (psObject == null)
|
||||
if (value is not PSObject psObject)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
else
|
||||
{
|
||||
object baseObject = psObject.BaseObject;
|
||||
var arrayObject = baseObject as object[];
|
||||
if (arrayObject == null)
|
||||
if (baseObject is not object[] arrayObject)
|
||||
{
|
||||
return baseObject;
|
||||
}
|
||||
@@ -380,8 +378,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
/// <returns>The object.</returns>
|
||||
protected object GetReferenceOrReferenceArrayObject(object value, ref CimType referenceType)
|
||||
{
|
||||
PSReference cimReference = value as PSReference;
|
||||
if (cimReference != null)
|
||||
if (value is PSReference cimReference)
|
||||
{
|
||||
object baseObject = GetBaseObject(cimReference.Value);
|
||||
if (!(baseObject is CimInstance cimInstance))
|
||||
@@ -394,8 +391,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
}
|
||||
else
|
||||
{
|
||||
object[] cimReferenceArray = value as object[];
|
||||
if (cimReferenceArray == null)
|
||||
if (value is not object[] cimReferenceArray)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -284,8 +284,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
internal static bool IsClassNameQuerySet(CimBaseCommand cmdlet)
|
||||
{
|
||||
DebugHelper.WriteLogEx();
|
||||
GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;
|
||||
if (cmd != null)
|
||||
if (cmdlet is GetCimInstanceCommand cmd)
|
||||
{
|
||||
if (cmd.QueryDialect != null || cmd.SelectProperties != null || cmd.Filter != null)
|
||||
{
|
||||
@@ -299,8 +298,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
protected static string CreateQuery(CimBaseCommand cmdlet)
|
||||
{
|
||||
DebugHelper.WriteLogEx();
|
||||
GetCimInstanceCommand cmd = cmdlet as GetCimInstanceCommand;
|
||||
if (cmd != null)
|
||||
if (cmdlet is GetCimInstanceCommand cmd)
|
||||
{
|
||||
StringBuilder propertyList = new();
|
||||
if (cmd.SelectProperties == null)
|
||||
|
||||
@@ -221,14 +221,11 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
if (temp != null)
|
||||
{
|
||||
// raise the event
|
||||
CimSubscriptionResultEventArgs resultArgs = args as CimSubscriptionResultEventArgs;
|
||||
if (resultArgs != null)
|
||||
if (args is CimSubscriptionResultEventArgs resultArgs)
|
||||
temp(this, new CimIndicationEventInstanceEventArgs(resultArgs.Result));
|
||||
else
|
||||
else if (args is CimSubscriptionExceptionEventArgs exceptionArgs)
|
||||
{
|
||||
CimSubscriptionExceptionEventArgs exceptionArgs = args as CimSubscriptionExceptionEventArgs;
|
||||
if (exceptionArgs != null)
|
||||
temp(this, new CimIndicationEventExceptionEventArgs(exceptionArgs.Exception));
|
||||
temp(this, new CimIndicationEventExceptionEventArgs(exceptionArgs.Exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,8 +179,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
{
|
||||
DebugHelper.WriteLogEx();
|
||||
|
||||
CimNewCimInstanceContext newCimInstanceContext = context as CimNewCimInstanceContext;
|
||||
if (newCimInstanceContext == null)
|
||||
if (context is not CimNewCimInstanceContext newCimInstanceContext)
|
||||
{
|
||||
DebugHelper.WriteLog("Invalid (null) CimNewCimInstanceContext", 1);
|
||||
return;
|
||||
@@ -295,8 +294,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
|
||||
DebugHelper.WriteLog("Create and add new property to ciminstance: name = {0}; value = {1}; flags = {2}", 5, propertyName, propertyValue, flag);
|
||||
|
||||
PSReference cimReference = propertyValue as PSReference;
|
||||
if (cimReference != null)
|
||||
if (propertyValue is PSReference cimReference)
|
||||
{
|
||||
CimProperty newProperty = CimProperty.Create(propertyName, GetBaseObject(cimReference.Value), CimType.Reference, flag);
|
||||
cimInstance.CimInstanceProperties.Add(newProperty);
|
||||
|
||||
@@ -196,8 +196,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
}
|
||||
|
||||
// NOTES: should move after this.Disposed, but need to log the exception
|
||||
CimWriteError cimWriteError = actionArgs.Action as CimWriteError;
|
||||
if (cimWriteError != null)
|
||||
if (actionArgs.Action is CimWriteError cimWriteError)
|
||||
{
|
||||
this.Exception = cimWriteError.Exception;
|
||||
if (!this.ackedEvent.IsSet)
|
||||
@@ -219,11 +218,9 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
DebugHelper.WriteLog("Got an exception: {0}", 2, Exception);
|
||||
}
|
||||
|
||||
CimWriteResultObject cimWriteResultObject = actionArgs.Action as CimWriteResultObject;
|
||||
if (cimWriteResultObject != null)
|
||||
if (actionArgs.Action is CimWriteResultObject cimWriteResultObject)
|
||||
{
|
||||
CimSubscriptionResult result = cimWriteResultObject.Result as CimSubscriptionResult;
|
||||
if (result != null)
|
||||
if (cimWriteResultObject.Result is CimSubscriptionResult result)
|
||||
{
|
||||
EventHandler<CimSubscriptionEventArgs> temp = this.OnNewSubscriptionResult;
|
||||
if (temp != null)
|
||||
|
||||
@@ -419,8 +419,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
|
||||
string resultObjectPSType = null;
|
||||
PSObject resultObject = null;
|
||||
CimMethodResult methodResult = value as CimMethodResult;
|
||||
if (methodResult != null)
|
||||
if (value is CimMethodResult methodResult)
|
||||
{
|
||||
resultObjectPSType = PSTypeCimMethodResult;
|
||||
resultObject = new PSObject();
|
||||
@@ -431,8 +430,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
}
|
||||
else
|
||||
{
|
||||
CimMethodStreamedResult methodStreamedResult = value as CimMethodStreamedResult;
|
||||
if (methodStreamedResult != null)
|
||||
if (value is CimMethodStreamedResult methodStreamedResult)
|
||||
{
|
||||
resultObjectPSType = PSTypeCimMethodStreamedResult;
|
||||
resultObject = new PSObject();
|
||||
|
||||
@@ -39,14 +39,12 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
{
|
||||
Debug.Assert(inner != null, "Caller should verify inner != null");
|
||||
|
||||
CimException cimException = inner as CimException;
|
||||
if (cimException != null)
|
||||
if (inner is CimException cimException)
|
||||
{
|
||||
return CreateFromCimException(context, cimException, cimResultContext);
|
||||
}
|
||||
|
||||
var containsErrorRecord = inner as IContainsErrorRecord;
|
||||
if (containsErrorRecord != null)
|
||||
if (inner is IContainsErrorRecord containsErrorRecord)
|
||||
{
|
||||
return InitializeErrorRecord(context,
|
||||
exception: inner,
|
||||
|
||||
@@ -232,8 +232,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
|
||||
if (sendToPipeline is CimInstance)
|
||||
{
|
||||
CimSetCimInstanceContext setContext = context as CimSetCimInstanceContext;
|
||||
if (setContext != null)
|
||||
if (context is CimSetCimInstanceContext setContext)
|
||||
{
|
||||
if (string.Equals(setContext.ParameterSetName, CimBaseCommand.QueryComputerSet, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(setContext.ParameterSetName, CimBaseCommand.QuerySessionSet, StringComparison.OrdinalIgnoreCase))
|
||||
|
||||
@@ -234,8 +234,7 @@ namespace Microsoft.Management.Infrastructure.CimCmdlets
|
||||
outputCredential = null;
|
||||
if (options != null)
|
||||
{
|
||||
DComSessionOptions dcomOptions = options as DComSessionOptions;
|
||||
if (dcomOptions != null)
|
||||
if (options is DComSessionOptions dcomOptions)
|
||||
{
|
||||
bool conflict = false;
|
||||
string parameterName = string.Empty;
|
||||
|
||||
Reference in New Issue
Block a user