Enable IDE0082: ConvertTypeOfToNameOf (#14042)

https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0082
This commit is contained in:
xtqqczze
2020-11-16 19:56:07 +05:00
committed by GitHub
parent fcd9e37341
commit 006fe4d2dd
11 changed files with 15 additions and 15 deletions
+1 -1
View File
@@ -971,7 +971,7 @@ dotnet_diagnostic.IDE0080.severity = silent
dotnet_diagnostic.IDE0081.severity = silent
# IDE0082: ConvertTypeOfToNameOf
dotnet_diagnostic.IDE0082.severity = silent
dotnet_diagnostic.IDE0082.severity = warning
# IDE0083: UseNotPattern
dotnet_diagnostic.IDE0083.severity = silent
@@ -2741,7 +2741,7 @@ namespace Microsoft.PowerShell
return false;
}
return remoteException.ErrorRecord.CategoryInfo.Reason == typeof(IncompleteParseException).Name;
return remoteException.ErrorRecord.CategoryInfo.Reason == nameof(IncompleteParseException);
}
private void EvaluateSuggestions(ConsoleHostUserInterface ui)
@@ -1092,7 +1092,7 @@ namespace System.Management.Automation
innerException: null,
Metadata.ValidateRangeElementType,
element.GetType().Name,
typeof(int).Name);
nameof(Int32));
}
object resultValue;
@@ -548,7 +548,7 @@ namespace System.Management.Automation
{
if (ImplementingType != null)
{
return (ImplementingType.GetInterface(typeof(IDynamicParameters).Name, true) != null);
return (ImplementingType.GetInterface(nameof(IDynamicParameters), true) != null);
}
else
{
@@ -680,7 +680,7 @@ namespace System.Management.Automation
// Determine if the cmdlet implements dynamic parameters by looking for the interface
Type dynamicParametersType = CommandType.GetInterface(typeof(IDynamicParameters).Name, true);
Type dynamicParametersType = CommandType.GetInterface(nameof(IDynamicParameters), true);
if (dynamicParametersType != null)
{
@@ -625,7 +625,7 @@ namespace System.Management.Automation
return;
}
bool implementsIList = (type.GetInterface(typeof(IList).Name) != null);
bool implementsIList = (type.GetInterface(nameof(IList)) != null);
// Look for class Collection<T>. Collection<T> implements IList, and also IList
// is more efficient to bind than ICollection<T>. This optimization
@@ -222,8 +222,8 @@ namespace System.Management.Automation
{
throw PSTraceSource.NewArgumentException(nameof(component), ExtendedTypeSystem.InvalidComponent,
"component",
typeof(PSObject).Name,
typeof(PSObjectTypeDescriptor).Name);
nameof(PSObject),
nameof(PSObjectTypeDescriptor));
}
mshObj = descriptor.Instance;
@@ -4138,7 +4138,7 @@ namespace System.Management.Automation
// because 'ToStringParser' would iterate through the enumerator to get the individual elements, which will
// make irreversible changes to the enumerator.
bool isValueAnIEnumerator = PSObject.Base(value) is IEnumerator;
string valAsString = isValueAnIEnumerator ? typeof(IEnumerator).Name : PSObject.ToStringParser(_context, value);
string valAsString = isValueAnIEnumerator ? nameof(IEnumerator) : PSObject.ToStringParser(_context, value);
int msgLength = 60 - varName.Length;
if (valAsString.Length > msgLength)
@@ -680,12 +680,12 @@ namespace System.Management.Automation.Internal.Host
internal static bool IsSecuritySensitiveType(string typeName)
{
if (typeName.Equals(typeof(PSCredential).Name, StringComparison.OrdinalIgnoreCase))
if (typeName.Equals(nameof(PSCredential), StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (typeName.Equals(typeof(SecureString).Name, StringComparison.OrdinalIgnoreCase))
if (typeName.Equals(nameof(SecureString), StringComparison.OrdinalIgnoreCase))
{
return true;
}
@@ -1936,7 +1936,7 @@ namespace System.Management.Automation
{
// Allow the IncompleteParseException to throw so that the console
// can handle here strings and continued parsing.
if (re.ErrorRecord.CategoryInfo.Reason == typeof(IncompleteParseException).Name)
if (re.ErrorRecord.CategoryInfo.Reason == nameof(IncompleteParseException))
{
throw new IncompleteParseException(
(re.ErrorRecord.Exception != null) ? re.ErrorRecord.Exception.Message : null,
@@ -1945,8 +1945,8 @@ namespace System.Management.Automation
// Allow the RemoteException and InvalidRunspacePoolStateException to propagate so that the host can
// clean up the debug session.
if ((re.ErrorRecord.CategoryInfo.Reason == typeof(InvalidRunspacePoolStateException).Name) ||
(re.ErrorRecord.CategoryInfo.Reason == typeof(RemoteException).Name))
if ((re.ErrorRecord.CategoryInfo.Reason == nameof(InvalidRunspacePoolStateException)) ||
(re.ErrorRecord.CategoryInfo.Reason == nameof(RemoteException)))
{
throw new PSRemotingTransportException(
(re.ErrorRecord.Exception != null) ? re.ErrorRecord.Exception.Message : string.Empty);
+1 -1
View File
@@ -44,7 +44,7 @@ namespace PSTests.Parallel
public static void TestCustomAstVisitor()
{
var ast = Parser.ParseInput("a | b", out _, out _);
var expected = typeof(NamedBlockAst).Name;
var expected = nameof(NamedBlockAst);
var myVisitor1 = new MyICustomAstVisitor2();
var result1 = ast.EndBlock.Accept(myVisitor1);