X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5c9d708
changed 10 files
CarloToso Dec 14, 2022
0dc86e7
changed 11 files
CarloToso Dec 14, 2022
6eff253
changed 9 files
CarloToso Dec 14, 2022
47c5609
fix copy-pasting error
CarloToso Dec 14, 2022
c9cbbd0
changed 10 files
CarloToso Dec 14, 2022
d89a304
changed 8 files
CarloToso Dec 14, 2022
243cdf6
fix GetCommandCommand.cs
CarloToso Dec 14, 2022
d49a699
removed space
CarloToso Dec 14, 2022
ae3795d
Update src/Microsoft.Management.UI.Internal/ManagementList/Common/Wpf…
CarloToso Dec 14, 2022
6466bfb
Update src/Microsoft.Management.UI.Internal/ManagementList/Common/Wpf…
CarloToso Dec 14, 2022
fd5fe0e
remove extra spaces
CarloToso Dec 14, 2022
899b322
comment out - ArgumentOutOfRangeException.ThrowIfZero()
CarloToso Dec 14, 2022
166b05f
ArgumentOutOfRangeException
CarloToso Dec 14, 2022
61d099d
revert ??
CarloToso Dec 14, 2022
1d2b15c
forgot if
CarloToso Dec 14, 2022
8252f13
replace throw new system.ArgumentNullException
CarloToso Dec 14, 2022
b834d37
Update src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdlet…
CarloToso Dec 14, 2022
febe972
fix test_FileSystemProvider.cs:line 87
CarloToso Dec 14, 2022
33e8fc2
Update with suggestion
CarloToso Dec 14, 2022
5904d7e
revert
CarloToso Dec 15, 2022
192c4ee
Merge branch 'master' into throw-new-ArgumentNullException(nameof())-2
CarloToso Dec 15, 2022
17dae3d
Update src/Microsoft.WSMan.Management/ConfigProvider.cs
CarloToso Dec 15, 2022
ecd907a
test_FileSystemProvider.cs
CarloToso Dec 15, 2022
0109312
FileSystemProvider.cs
CarloToso Dec 15, 2022
3347046
Update src/System.Management.Automation/namespaces/FileSystemProvider.cs
iSazonov Dec 15, 2022
60e2307
Update src/System.Management.Automation/utils/BackgroundDispatcher.cs
iSazonov Dec 16, 2022
2933e95
Update src/System.Management.Automation/engine/Utils.cs
iSazonov Dec 16, 2022
3a9d5b2
Apply suggestions from code review
iSazonov Dec 16, 2022
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,10 +149,8 @@ public void RegisterCimIndication(
uint operationTimeout)
{
DebugHelper.WriteLogEx("queryDialect = '{0}'; queryExpression = '{1}'", 0, queryDialect, queryExpression);
if (cimSession == null)
{
throw new ArgumentNullException(string.Format(CultureInfo.CurrentUICulture, CimCmdletStrings.NullArgument, nameof(cimSession)));
}

ArgumentNullException.ThrowIfNull(cimSession, 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 @@ -371,10 +371,7 @@ internal static class ValidationHelper
/// <param name="argumentName"></param>
public static void ValidateNoNullArgument(object obj, string argumentName)
{
if (obj == null)
{
throw new ArgumentNullException(argumentName);
}
ArgumentNullException.ThrowIfNull(obj, argumentName);
}

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xtqqczze The second parameter appears to be incorrect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iSazonov suggested this change #18792 (comment)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is frozen and we should keep its behavior unchanged.


ContentControl parentContentControl = parent as ContentControl;

Expand Down Expand Up @@ -370,10 +367,7 @@ 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
{
if (@object == null)
{
throw new ArgumentNullException("object");
}
ArgumentNullException.ThrowIfNull(@object, nameof(@object));

DependencyObject parent = VisualTreeHelper.GetParent(@object);

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

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

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

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

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

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

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

for (int i = 0; i < args.Length; i++)
{
if (args[i] is null)
{
throw new ArgumentNullException(nameof(args), CommandLineParameterParserStrings.NullElementInArgs);
}
ArgumentNullException.ThrowIfNull(args[i], 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,8 +41,7 @@ public string Delimiter
[SuppressMessage("Microsoft.Usage", "CA2208:InstantiateArgumentExceptionsCorrectly")]
set
{
if (value == null)
throw new ArgumentNullException(nameof(Delimiter));
ArgumentNullException.ThrowIfNull(value, 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) || (path.Length == 0))
if (string.IsNullOrEmpty(path))
{
throw new ArgumentNullException(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,9 @@ 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,10 +35,7 @@ internal static class Requires
[System.Diagnostics.Conditional("DEBUG")]
internal static void NotNull(object value, string paramName)
{
if (value == null)
{
throw new ArgumentNullException(paramName);
}
ArgumentNullException.ThrowIfNull(value, paramName);
}

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

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

set
{
_parameterNames = value ?? throw new ArgumentNullException(nameof(value));
ArgumentNullException.ThrowIfNull(value);

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

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

// 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 @@ -3918,11 +3914,7 @@ internal static Assembly LoadAssemblyFromFile(string fileName)

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

string assemblyPath = assembly.Location;
PSSnapInHelpers.AnalyzePSSnapInAssembly(
Expand Down
2 changes: 2 additions & 0 deletions src/System.Management.Automation/engine/PSClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ 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: 4 additions & 5 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,7 @@ internal static class Requires
{
internal static void NotNull(object value, string paramName)
{
if (value == null)
{
throw new ArgumentNullException(paramName);
}
ArgumentNullException.ThrowIfNull(value, paramName);
Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov Dec 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In follow PR we could replace all NotNull with the ArgumentNullException.ThrowIfNull.
Excluding ComInterop code - it should be in sync with .Net.

}

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

internal static void NotNullOrEmpty(ICollection value, string paramName)
{
if (value == null || value.Count == 0)
ArgumentNullException.ThrowIfNull(value, paramName);

if (value.Count == 0)
{
throw new ArgumentNullException(paramName);
}
Expand Down
7 changes: 3 additions & 4 deletions src/System.Management.Automation/engine/lang/scriptblock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,10 +1138,9 @@ 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)
{
if (command == null || command.MyInvocation == null)
{
throw new ArgumentNullException(nameof(command));
}
ArgumentNullException.ThrowIfNull(command);

ArgumentNullException.ThrowIfNull(command.MyInvocation, 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);
if (index == null || target == null)
{
throw new ArgumentNullException(nameof(indexExpressionAst));
}

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

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

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

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

lock (_syncObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7884,7 +7884,6 @@ 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,8 +1388,7 @@ public void SetValue(string name, object value)
[ComVisible(false)]
public unsafe void SetValue(string name, object value, RegistryValueKind valueKind)
{
if (value == null)
throw new ArgumentNullException(RegistryProviderStrings.Arg_Value);
ArgumentNullException.ThrowIfNull(value, RegistryProviderStrings.Arg_Value);

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

private static void ValidateKeyName(string name)
{
if (name == null)
{
throw new ArgumentNullException(RegistryProviderStrings.Arg_Name);
}
ArgumentNullException.ThrowIfNull(name, 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,7 +70,8 @@ public BackgroundDispatcher(EventProvider transferProvider, EventDescriptor tran
// internal for unit testing only. Otherwise, would be private.
internal BackgroundDispatcher(IMethodInvoker etwActivityMethodInvoker)
{
_etwActivityMethodInvoker = etwActivityMethodInvoker ?? throw new ArgumentNullException(nameof(etwActivityMethodInvoker));
ArgumentNullException.ThrowIfNull(etwActivityMethodInvoker);
_etwActivityMethodInvoker = etwActivityMethodInvoker;
_invokerWaitCallback = DoInvoker;
}

Expand Down
4 changes: 3 additions & 1 deletion src/System.Management.Automation/utils/ParserException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public ParseException(string message,
Justification = "ErrorRecord is not overridden in classes deriving from ParseException")]
public ParseException(Language.ParseError[] errors)
{
if ((errors == null) || (errors.Length == 0))
ArgumentNullException.ThrowIfNull(errors);

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

ArgumentNullException.ThrowIfNull(counterInfoArray);

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