تخطَّ إلى المحتوى

Argument exception parameter (ARCH402)

هذا المحتوى غير متوفر بلغتك بعد.

Key dotnet.exception.argument-exception-parameter · Severity info · Category exception

ArgumentException and its derivatives should include the name of the parameter that is invalid. This makes error messages more useful.

public void Process(string name)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Name is required");
}
public void Process(string name)
{
if (string.IsNullOrEmpty(name))
throw new ArgumentException("Name is required", nameof(name));
}

Pass the parameter name via nameof(parameter) to the exception. If needed, suppress the rule per project/workspace via except/ignore.