X Tutup
Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ public void RegisterCimIndication(
uint operationTimeout)
{
DebugHelper.WriteLogEx("queryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression);

ArgumentNullException.ThrowIfNull(cimSession, string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
if (cimSession == null)
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
}

this.TargetComputerName = cimSession.ComputerName;
CimSessionProxy proxy = CreateSessionProxy(cimSession, operationTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ internal static class ValidationHelper
/// <param name="argumentName"></param>
public static void ValidateNoNullArgument(object obj, string argumentName)
{
ArgumentNullException.ThrowIfNull(obj, argumentName);
if (obj == null)
{
throw new ArgumentNullException(argumentName);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ public static void AddChild(FrameworkElement parent, FrameworkElement element)
{
ArgumentNullException.ThrowIfNull(element);

ArgumentNullException.ThrowIfNull(parent, nameof(element));
if (parent == null)
{
throw new ArgumentNullException("element");
}

ContentControl parentContentControl = parent as ContentControl;

Expand Down Expand Up @@ -367,7 +370,10 @@ public static T FindVisualAncestorData<T>(this DependencyObject obj)
/// <exception cref="ArgumentNullException">The specified value is a null reference.</exception>
public static T FindVisualAncestor<T>(this DependencyObject @object) where T : class
{
ArgumentNullException.ThrowIfNull(@object, nameof(@object));
if (@object == null)
{
throw new ArgumentNullException("object");
}

DependencyObject parent = VisualTreeHelper.GetParent(@object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public string DefaultValue
/// </remarks>
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
ArgumentNullException.ThrowIfNull(values);

if (values.Length != 1)
if (values == null || values.Length != 1)
{
throw new ArgumentNullException("values");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public class AllModulesViewModel : INotifyPropertyChanged
/// <param name="commands">Commands to show.</param>
public AllModulesViewModel(Dictionary<string, ShowCommandModuleInfo> importedModules, IEnumerable<ShowCommandCommandInfo> commands)
{
ArgumentNullException.ThrowIfNull(commands);

if (!commands.GetEnumerator().MoveNext())
if (commands == null || !commands.GetEnumerator().MoveNext())
{
throw new ArgumentNullException("commands");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ protected TSession[] Session

set
{
ArgumentNullException.ThrowIfNull(value);
_session = value;
_session = value ?? throw new ArgumentNullException(nameof(value));
_sessionWasSpecified = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,12 +575,10 @@ private void ProcessMTUSize(string targetNameOrAddress)
}
else
{
ArgumentNullException.ThrowIfNull(replyResult);

WriteObject(new PingMtuStatus(
Source,
resolvedTargetName,
replyResult,
replyResult ?? throw new ArgumentNullException(nameof(replyResult)),
CurrentMTUSize));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ internal override void ProcessResponse(HttpResponseMessage response)

private static RestReturnType CheckReturnType(HttpResponseMessage response)
{
ArgumentNullException.ThrowIfNull(response);
if (response == null) { throw new ArgumentNullException(nameof(response)); }

RestReturnType rt = RestReturnType.Detect;
string contentType = ContentHelper.GetContentType(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,10 @@ internal void Parse(string[] args)

for (int i = 0; i < args.Length; i++)
{
ArgumentNullException.ThrowIfNull(args[i], CommandLineParameterParserStrings.NullElementInArgs);
if (args[i] is null)
{
throw new ArgumentNullException(nameof(args), CommandLineParameterParserStrings.NullElementInArgs);
}
}

// Indicates that we've called this method on this instance, and that when it's done, the state variables
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public string Delimiter
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
set
{
ArgumentNullException.ThrowIfNull(value, nameof(Delimiter));
if (value == null)
throw new ArgumentNullException(nameof(Delimiter));

if (value.Length == 0)
throw new ArgumentException(DotNetEventingStrings.Argument_NeedNonemptyDelimiter);
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.WSMan.Management/ConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3413,7 +3413,7 @@ private static string NormalizePath(string path, string host)
/// </exception>
private PSObject GetItemValue(string path)
{
if (string.IsNullOrEmpty(path))
if (string.IsNullOrEmpty(path) || (path.Length == 0))
{
throw new ArgumentNullException(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,7 @@ public static class PowerShellAssemblyLoadContextInitializer
public static void SetPowerShellAssemblyLoadContext([MarshalAs(UnmanagedType.LPWStr)] string basePaths)
{
if (string.IsNullOrEmpty(basePaths))
{
throw new ArgumentNullException(nameof(basePaths));
}

PowerShellAssemblyLoadContext.InitializeSingleton(basePaths);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ internal static class Requires
[System.Diagnostics.Conditional("DEBUG")]
internal static void NotNull(object value, string paramName)
{
ArgumentNullException.ThrowIfNull(value, paramName);
if (value == null)
{
throw new ArgumentNullException(paramName);
}
}

[System.Diagnostics.Conditional("DEBUG")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ internal class DefaultCommandRuntime : ICommandRuntime2
/// </summary>
public DefaultCommandRuntime(List<object> outputList)
{
ArgumentNullException.ThrowIfNull(outputList);
if (outputList == null)
throw new System.ArgumentNullException(nameof(outputList));

_output = outputList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ public string[] ParameterName

set
{
ArgumentNullException.ThrowIfNull(value);

_parameterNames = value;
_parameterNames = value ?? throw new ArgumentNullException(nameof(value));
_parameterNameWildcards = SessionStateUtilities.CreateWildcardsFromStrings(
_parameterNames,
WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase);
Expand Down
12 changes: 10 additions & 2 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3805,7 +3805,11 @@ internal PSSnapInInfo ImportCorePSSnapIn()

internal PSSnapInInfo ImportPSSnapIn(PSSnapInInfo psSnapInInfo, out PSSnapInException warning)
{
ArgumentNullException.ThrowIfNull(psSnapInInfo);
if (psSnapInInfo == null)
{
ArgumentNullException e = new ArgumentNullException(nameof(psSnapInInfo));
throw e;
}

// See if the snapin is already loaded. If has been then there will be an entry in the
// Assemblies list for it already...
Expand Down Expand Up @@ -3981,7 +3985,11 @@ internal static Assembly LoadAssemblyFromFile(string fileName)

internal void ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
{
ArgumentNullException.ThrowIfNull(assembly);
if (assembly == null)
{
ArgumentNullException e = new ArgumentNullException(nameof(assembly));
throw e;
}

string assemblyPath = assembly.Location;
PSSnapInHelpers.AnalyzePSSnapInAssembly(
Expand Down
2 changes: 0 additions & 2 deletions src/System.Management.Automation/engine/PSClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public sealed class PSClassMemberInfo
internal PSClassMemberInfo(string name, string memberType, string defaultValue)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentNullException(nameof(name));
}

this.Name = name;
this.TypeName = memberType;
Expand Down
9 changes: 5 additions & 4 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,7 +1735,10 @@ internal static class Requires
{
internal static void NotNull(object value, string paramName)
{
ArgumentNullException.ThrowIfNull(value, paramName);
if (value == null)
{
throw new ArgumentNullException(paramName);
}
}

internal static void NotNullOrEmpty(string value, string paramName)
Expand All @@ -1748,9 +1751,7 @@ internal static void NotNullOrEmpty(string value, string paramName)

internal static void NotNullOrEmpty(ICollection value, string paramName)
{
ArgumentNullException.ThrowIfNull(value, paramName);

if (value.Count == 0)
if (value == null || value.Count == 0)
{
throw new ArgumentNullException(paramName);
}
Expand Down
7 changes: 4 additions & 3 deletions src/System.Management.Automation/engine/lang/scriptblock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,10 @@ public void Begin(bool expectInput, EngineIntrinsics contextToRedirectTo)
/// <param name="command">The command you're calling this from (i.e. instance of PSCmdlet or value of $PSCmdlet variable).</param>
public void Begin(InternalCommand command)
{
ArgumentNullException.ThrowIfNull(command);

ArgumentNullException.ThrowIfNull(command.MyInvocation, nameof(command));
if (command == null || command.MyInvocation == null)
{
throw new ArgumentNullException(nameof(command));
}

Begin(command.MyInvocation.ExpectingInput, command.commandRuntime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ public object VisitIndexExpression(IndexExpressionAst indexExpressionAst)
// Get the value of the index and value and call the compiler
var index = indexExpressionAst.Index.Accept(this);
var target = indexExpressionAst.Target.Accept(this);

ArgumentNullException.ThrowIfNull(index, nameof(indexExpressionAst));

ArgumentNullException.ThrowIfNull(target, nameof(indexExpressionAst));
if (index == null || target == null)
{
throw new ArgumentNullException(nameof(indexExpressionAst));
}

return GetIndexedValueFromTarget(target, index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public abstract class Repository<T> where T : class
/// <param name="item">Object to add.</param>
public void Add(T item)
{
ArgumentNullException.ThrowIfNull(item, _identifier);
if (item == null)
{
throw new ArgumentNullException(_identifier);
}

lock (_syncObject)
{
Expand All @@ -42,7 +45,10 @@ public void Add(T item)
/// <param name="item">Object to remove.</param>
public void Remove(T item)
{
ArgumentNullException.ThrowIfNull(item, _identifier);
if (item == null)
{
throw new ArgumentNullException(_identifier);
}

lock (_syncObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7969,6 +7969,7 @@ internal static bool CreateJunction(string path, string target)
{
throw new ArgumentNullException(nameof(target));
}

using (SafeHandle handle = WinOpenReparsePoint(path, FileAccess.Write))
{
byte[] mountPointBytes = Encoding.Unicode.GetBytes(NonInterpretedPathPrefix + Path.GetFullPath(target));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,8 @@ public void SetValue(string name, object value)
[ComVisible(false)]
public unsafe void SetValue(string name, object value, RegistryValueKind valueKind)
{
ArgumentNullException.ThrowIfNull(value, RegistryProviderStrings.Arg_Value);
if (value == null)
throw new ArgumentNullException(RegistryProviderStrings.Arg_Value);

if (name != null && name.Length > MaxValueNameLength)
{
Expand Down Expand Up @@ -2030,7 +2031,10 @@ private RegistryKeyPermissionCheck GetSubKeyPermissionCheck(bool subkeyWritable)

private static void ValidateKeyName(string name)
{
ArgumentNullException.ThrowIfNull(name, RegistryProviderStrings.Arg_Name);
if (name == null)
{
throw new ArgumentNullException(RegistryProviderStrings.Arg_Name);
}

int nextSlash = name.IndexOf('\\');
int current = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public BackgroundDispatcher(EventProvider transferProvider, EventDescriptor tran
// internal for unit testing only. Otherwise, would be private.
internal BackgroundDispatcher(IMethodInvoker etwActivityMethodInvoker)
{
ArgumentNullException.ThrowIfNull(etwActivityMethodInvoker);
_etwActivityMethodInvoker = etwActivityMethodInvoker;
_etwActivityMethodInvoker = etwActivityMethodInvoker ?? throw new ArgumentNullException(nameof(etwActivityMethodInvoker));
_invokerWaitCallback = DoInvoker;
}

Expand Down
4 changes: 1 addition & 3 deletions src/System.Management.Automation/utils/ParserException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public ParseException(string message,
/// <param name="errors">The collection of error messages.</param>
public ParseException(ParseError[] errors)
{
ArgumentNullException.ThrowIfNull(errors);

if (errors.Length == 0)
if ((errors == null) || (errors.Length == 0))
{
throw new ArgumentNullException(nameof(errors));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,8 @@ protected CounterSetRegistrarBase(
CounterSetId = counterSetId;
CounterSetInstType = counterSetInstType;
CounterSetName = counterSetName;

ArgumentNullException.ThrowIfNull(counterInfoArray);

if (counterInfoArray.Length == 0)
if ((counterInfoArray == null)
|| (counterInfoArray.Length == 0))
{
throw new ArgumentNullException(nameof(counterInfoArray));
}
Expand Down
X Tutup