Enable several more IDE analyzer warnings (#42692)
authorStephen Toub <stoub@microsoft.com>
Fri, 25 Sep 2020 10:33:07 +0000 (06:33 -0400)
committerGitHub <noreply@github.com>
Fri, 25 Sep 2020 10:33:07 +0000 (06:33 -0400)
* Enable IDE0062: Make local functions static

* Enable IDE0079: Remove unnecessary suppression

* Enable IDE0082: Convert typeof to nameof

* Enable IDE0043: Validate format string

* Enable IDE0041: Use is null check

54 files changed:
eng/CodeAnalysis.ruleset
src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs
src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderExtensions.cs
src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/WithType.cs
src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs
src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs
src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs
src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ImportDefinition.cs
src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Providers/CurrentScope/CurrentScopeExportDescriptorProvider.cs
src/libraries/System.Data.Common/src/System/Data/DataRowComparer.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs
src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs
src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaitable.cs
src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Address.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs
src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightCompiler.cs
src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs
src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs
src/libraries/System.Private.CoreLib/src/System/Lazy.cs
src/libraries/System.Private.CoreLib/src/System/Nullable.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/SerializationInfo.cs
src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs
src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs
src/libraries/System.Private.Uri/src/System/Uri.cs
src/libraries/System.Private.Uri/src/System/UriBuilder.cs
src/libraries/System.Private.Uri/src/System/UriExt.cs
src/libraries/System.Private.Uri/src/System/UriHelper.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs
src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs
src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/RoAssemblyName.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs
src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithm.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithmGroup.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKeyBlobFormat.cs
src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs
src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs
src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs

index 217abf5..6db1a74 100644 (file)
     <Rule Id="IDE0038" Action="Hidden" />  <!-- InlineIsTypeWithoutNameCheck -->
     <Rule Id="IDE0039" Action="Hidden" />  <!-- UseLocalFunction -->
     <Rule Id="IDE0040" Action="Hidden" />  <!-- AddAccessibilityModifiers -->
-    <Rule Id="IDE0041" Action="Hidden" />  <!-- UseIsNullCheck -->
+    <Rule Id="IDE0041" Action="Warning" /> <!-- UseIsNullCheck -->
     <Rule Id="IDE0042" Action="Hidden" />  <!-- UseDeconstruction -->
-    <Rule Id="IDE0043" Action="Hidden" />  <!-- ValidateFormatString -->
+    <Rule Id="IDE0043" Action="Warning" /> <!-- ValidateFormatString -->
     <Rule Id="IDE0044" Action="Hidden" />  <!-- MakeFieldReadonly -->
     <Rule Id="IDE0045" Action="Hidden" />  <!-- UseConditionalExpressionForAssignment -->
     <Rule Id="IDE0046" Action="Hidden" />  <!-- UseConditionalExpressionForReturn -->
     <Rule Id="IDE0059" Action="Hidden" />  <!-- ValueAssignedIsUnused -->
     <Rule Id="IDE0060" Action="Hidden" />  <!-- UnusedParameter -->
     <Rule Id="IDE0061" Action="Hidden" />  <!-- UseExpressionBodyForLocalFunctions -->
-    <Rule Id="IDE0062" Action="Hidden" />  <!-- MakeLocalFunctionStatic -->
+    <Rule Id="IDE0062" Action="Warning" /> <!-- MakeLocalFunctionStatic -->
     <Rule Id="IDE0063" Action="Hidden" />  <!-- UseSimpleUsingStatement -->
     <Rule Id="IDE0064" Action="Hidden" />  <!-- MakeStructFieldsWritable -->
     <Rule Id="IDE0065" Action="Hidden" />  <!-- MoveMisplacedUsingDirectives -->
     <Rule Id="IDE0076" Action="Hidden" />  <!-- InvalidSuppressMessageAttribute -->
     <Rule Id="IDE0077" Action="Hidden" />  <!-- LegacyFormatSuppressMessageAttribute -->
     <Rule Id="IDE0078" Action="Hidden" />  <!-- UsePatternCombinators -->
-    <Rule Id="IDE0079" Action="Hidden" />  <!-- RemoveUnnecessarySuppression -->
+    <Rule Id="IDE0079" Action="Warning" /> <!-- RemoveUnnecessarySuppression -->
     <Rule Id="IDE0080" Action="Hidden" />  <!-- RemoveConfusingSuppressionForIsExpression -->
     <Rule Id="IDE0081" Action="Hidden" />  <!-- RemoveUnnecessaryByVal -->
-    <Rule Id="IDE0082" Action="Hidden" />  <!-- ConvertTypeOfToNameOf -->
+    <Rule Id="IDE0082" Action="Warning" /> <!-- ConvertTypeOfToNameOf -->
     <Rule Id="IDE0083" Action="Hidden" />  <!-- UseNotPattern -->
     <Rule Id="IDE0084" Action="Hidden" />  <!-- UseIsNotExpression -->
     <Rule Id="IDE1001" Action="Hidden" />  <!-- AnalyzerChanged -->
index fc3ef65..1a4d993 100644 (file)
@@ -221,7 +221,7 @@ namespace System
         //    to form a new delegate.
         protected sealed override Delegate CombineImpl(Delegate? follow)
         {
-            if ((object?)follow == null) // cast to object for a more efficient test
+            if (follow is null)
                 return this;
 
             // Verify that the types are the same...
index ef1f82b..b7e6a58 100644 (file)
@@ -226,7 +226,7 @@ namespace System.Reflection
             if (Associates.IncludeAccessor(m_setterMethod, nonPublic))
                 accessorList.Add(m_setterMethod!);
 
-            if ((object?)m_otherMethod != null)
+            if (m_otherMethod is not null)
             {
                 for (int i = 0; i < m_otherMethod.Length; i++)
                 {
index 9aef6b1..85f2f68 100644 (file)
@@ -2203,7 +2203,7 @@ namespace System
         private static bool FilterApplyType(
             Type type, BindingFlags bindingFlags, string name, bool prefixLookup, string? ns)
         {
-            Debug.Assert((object)type != null);
+            Debug.Assert(type is not null);
             Debug.Assert(type is RuntimeType);
 
             bool isPublic = type.IsNestedPublic || type.IsPublic;
@@ -2341,7 +2341,7 @@ namespace System
                             for (int i = 0; i < parameterInfos.Length; i++)
                             {
                                 // a null argument type implies a null arg which is always a perfect match
-                                if ((object)argumentTypes[i] != null && !argumentTypes[i].MatchesParameterTypeExactly(parameterInfos[i]))
+                                if (argumentTypes[i] is Type t && !t.MatchesParameterTypeExactly(parameterInfos[i]))
                                     return false;
                             }
                         }
@@ -2834,7 +2834,7 @@ namespace System
                 {
                     PropertyInfo firstCandidate = candidates[0];
 
-                    if ((object?)returnType != null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
+                    if (returnType is not null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
                         return null;
 
                     return firstCandidate;
index e6f7cd3..2acfc83 100644 (file)
@@ -121,7 +121,7 @@ namespace System.Drawing
             }
             catch (Exception e)
             {
-                throw new ArgumentException(SR.Format(SR.ConvertInvalidPrimitive, text, typeof(int).Name), e);
+                throw new ArgumentException(SR.Format(SR.ConvertInvalidPrimitive, text, nameof(Int32)), e);
             }
         }
 
index 3e3307c..c2e01a3 100644 (file)
@@ -278,7 +278,7 @@ namespace Microsoft.CSharp.RuntimeBinder
                     // See if MetadataToken property is available.
                     PropertyInfo property = memberInfo.GetProperty("MetadataToken", typeof(int), Array.Empty<Type>());
 
-                    if ((object)property != null && property.CanRead)
+                    if (property is not null && property.CanRead)
                     {
                         // (parameter1, parameter2) => parameter1.MetadataToken == parameter2.MetadataToken
                         var parameter1 = Expression.Parameter(memberInfo);
index 11fff28..da74b33 100644 (file)
@@ -63,11 +63,11 @@ namespace Microsoft.CSharp.RuntimeBinder.Semantics
             {
                 return true;
             }
-            else if (ReferenceEquals(swt1, null))
+            else if (swt1 is null)
             {
                 return swt2._sym == null;
             }
-            else if (ReferenceEquals(swt2, null))
+            else if (swt2 is null)
             {
                 return swt1._sym == null;
             }
index e7e70c9..bf51c3a 100644 (file)
@@ -32,7 +32,7 @@ namespace Microsoft.Extensions.DependencyModel
 
         public override bool Equals(object obj)
         {
-            if (ReferenceEquals(null, obj)) return false;
+            if (obj is null) return false;
             return obj is Dependency && Equals((Dependency) obj);
         }
 
index a2230c2..5c7d7de 100644 (file)
@@ -79,7 +79,7 @@ namespace Microsoft.Extensions.Logging
         /// <inheritdoc />
         public override bool Equals(object obj)
         {
-            if (ReferenceEquals(null, obj))
+            if (obj is null)
             {
                 return false;
             }
index 288b0e7..0d5ddc6 100644 (file)
@@ -159,7 +159,7 @@ namespace Microsoft.Extensions.Primitives
         /// <inheritdoc />
         public override bool Equals(object obj)
         {
-            if (ReferenceEquals(null, obj))
+            if (obj is null)
             {
                 return false;
             }
index b18c6b7..7a3be92 100644 (file)
@@ -102,7 +102,7 @@ namespace System.ComponentModel.Composition.Primitives
                 (cardinality != ImportCardinality.ZeroOrOne)
                 )
             {
-                throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_InvalidEnum, nameof(cardinality), cardinality, typeof(ImportCardinality).Name), nameof(cardinality));
+                throw new ArgumentException(SR.Format(SR.ArgumentOutOfRange_InvalidEnum, nameof(cardinality), cardinality, nameof(ImportCardinality)), nameof(cardinality));
             }
 
             _contractName = contractName ?? EmptyContractName;
index 25b2c15..2faf7c2 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Composition.Hosting.Providers.CurrentScope
 
             return new[] { new ExportDescriptorPromise(
                 contract,
-                typeof(CompositionContext).Name,
+                nameof(CompositionContext),
                 true,
                 NoDependencies,
                 _ => ExportDescriptor.Create((c, o) => c, NoMetadata)) };
index 045f152..b3e042a 100644 (file)
@@ -24,8 +24,8 @@ namespace System.Data
                 // same reference or (null, null) or (DBNull.Value, DBNull.Value)
                 return true;
             }
-            if (ReferenceEquals(a, null) || ReferenceEquals(a, DBNull.Value) ||
-                ReferenceEquals(b, null) || ReferenceEquals(b, DBNull.Value))
+            if (a is null || ReferenceEquals(a, DBNull.Value) ||
+                b is null || ReferenceEquals(b, DBNull.Value))
             {
                 // (null, non-null) or (null, DBNull.Value) or vice versa
                 return false;
@@ -40,8 +40,8 @@ namespace System.Data
                 // same reference or (null, null) or (DBNull.Value, DBNull.Value)
                 return true;
             }
-            if (ReferenceEquals(a, null) || ReferenceEquals(a, DBNull.Value) ||
-                ReferenceEquals(b, null) || ReferenceEquals(b, DBNull.Value))
+            if (a is null || ReferenceEquals(a, DBNull.Value) ||
+                b is null || ReferenceEquals(b, DBNull.Value))
             {
                 // (null, non-null) or (null, DBNull.Value) or vice versa
                 return false;
@@ -143,8 +143,8 @@ namespace System.Data
                 return true;
             }
 
-            if (ReferenceEquals(leftRow, null) ||
-                ReferenceEquals(rightRow, null))
+            if (leftRow is null ||
+                rightRow is null)
             {
                 return false;
             }
index a0311f1..d837be3 100644 (file)
@@ -256,7 +256,7 @@ namespace System.Drawing
                     if (s_animationThread == null)
                     {
                         s_animationThread = new Thread(new ThreadStart(AnimateImages50ms));
-                        s_animationThread.Name = typeof(ImageAnimator).Name;
+                        s_animationThread.Name = nameof(ImageAnimator);
                         s_animationThread.IsBackground = true;
                         s_animationThread.Start();
                     }
index 7afd7b1..b5e97b2 100644 (file)
@@ -26,7 +26,7 @@ namespace System.IO.MemoryMappedFiles
             }
             if (memMappedFileHandle.IsClosed)
             {
-                throw new ObjectDisposedException(typeof(MemoryMappedFile).Name);
+                throw new ObjectDisposedException(nameof(MemoryMappedFile));
             }
 
             if (requestedSize == MemoryMappedFile.DefaultSize)
index e7dbad6..dab7064 100644 (file)
@@ -100,7 +100,7 @@ namespace System.IO.Pipelines
         public void OnCompleted(Action<object?> continuation, object? state, ValueTaskSourceOnCompletedFlags flags, out CompletionData completionData, out bool doubleCompletion)
         {
             completionData = default;
-            doubleCompletion = !ReferenceEquals(_completion, null);
+            doubleCompletion = _completion is not null;
 
             if (IsCompleted || doubleCompletion)
             {
index 7416d97..c31dc3b 100644 (file)
@@ -786,7 +786,7 @@ namespace System.Dynamic.Utils
 
         public static Type? FindGenericType(Type definition, Type? type)
         {
-            while ((object?)type != null && type != typeof(object))
+            while (type is not null && type != typeof(object))
             {
                 if (type.IsConstructedGenericType && AreEquivalent(type.GetGenericTypeDefinition(), definition))
                 {
index ea863c5..21e914f 100644 (file)
@@ -16,7 +16,7 @@ namespace System.Linq.Expressions.Compiler
             Debug.Assert(methodBase is MethodInfo || methodBase is ConstructorInfo);
 
             var ctor = methodBase as ConstructorInfo;
-            if ((object?)ctor != null)
+            if (ctor is not null)
             {
                 il.Emit(opcode, ctor);
             }
index be507c2..29b5b83 100644 (file)
@@ -131,7 +131,7 @@ namespace System.Linq.Expressions.Compiler
         private void EmitMemberAddress(MemberInfo member, Type? objectType)
         {
             FieldInfo? field = member as FieldInfo;
-            if ((object?)field != null)
+            if (field is not null)
             {
                 // Verifiable code may not take the address of an init-only field.
                 // If we are asked to do so then get the value out of the field, stuff it
@@ -260,7 +260,7 @@ namespace System.Linq.Expressions.Compiler
         private WriteBack? AddressOfWriteBack(MemberExpression node)
         {
             var property = node.Member as PropertyInfo;
-            if ((object?)property == null || !property.CanWrite)
+            if (property is null || !property.CanWrite)
             {
                 return null;
             }
index f29424e..aab1e74 100644 (file)
@@ -803,7 +803,7 @@ namespace System.Linq.Expressions.Compiler
             }
 
             var fld = member as FieldInfo;
-            if ((object?)fld != null)
+            if (fld is not null)
             {
                 _ilg.EmitFieldSet((FieldInfo)member);
             }
@@ -840,7 +840,7 @@ namespace System.Linq.Expressions.Compiler
         private void EmitMemberGet(MemberInfo member, Type? objectType)
         {
             var fi = member as FieldInfo;
-            if ((object?)fi != null)
+            if (fi is not null)
             {
                 if (fi.IsLiteral)
                 {
index f3b4b7c..c222f01 100644 (file)
@@ -149,7 +149,7 @@ namespace System.Linq.Expressions.Interpreter
                     break;
             }
 
-            if ((object?)alternativeMethod == null)
+            if (alternativeMethod is null)
             {
                 return new MethodInfoCallInstruction(info, argumentCount);
             }
@@ -261,10 +261,10 @@ namespace System.Linq.Expressions.Interpreter
         protected static bool TryGetLightLambdaTarget(object? instance, [NotNullWhen(true)] out LightLambda? lightLambda)
         {
             var del = instance as Delegate;
-            if ((object?)del != null)
+            if (del is not null)
             {
                 var thunk = del.Target as Func<object[], object>;
-                if ((object?)thunk != null)
+                if (thunk is not null)
                 {
                     lightLambda = thunk.Target as LightLambda;
                     if (lightLambda != null)
index 23de1e7..534a3f7 100644 (file)
@@ -1159,7 +1159,7 @@ namespace System.Linq.Expressions.Interpreter
 
                 if (from == to)
                 {
-                    if ((object?)enumTypeTo != null)
+                    if (enumTypeTo is not null)
                     {
                         // If casting between enums of the same underlying type or to enum from the underlying
                         // type, there's no need for the numeric conversion, so just include a null-check if
@@ -1189,7 +1189,7 @@ namespace System.Linq.Expressions.Interpreter
                     }
                 }
 
-                if ((object?)enumTypeTo != null)
+                if (enumTypeTo is not null)
                 {
                     // Convert from underlying to the enum
                     _instructions.EmitCastToEnum(enumTypeTo);
index 95fb864..ccbae0f 100644 (file)
@@ -120,7 +120,7 @@ namespace System.Net.Http
 
         public bool Equals(HttpMethod? other)
         {
-            if ((object?)other == null)
+            if (other is null)
             {
                 return false;
             }
@@ -159,7 +159,7 @@ namespace System.Net.Http
 
         public static bool operator ==(HttpMethod? left, HttpMethod? right)
         {
-            return (object?)left == null || (object?)right == null ?
+            return left is null || right is null ?
                 ReferenceEquals(left, right) :
                 left.Equals(right);
         }
index 2ade557..3b2e569 100644 (file)
@@ -63,7 +63,8 @@ namespace System.Net.Http
                         if (response.Headers.ConnectionClose.GetValueOrDefault())
                         {
                             // Server is closing the connection and asking us to authenticate on a new connection.
-#pragma warning disable CS8600 // expression returns null connection on error, was not able to use '!' for the expression
+                            // expression returns null connection on error, was not able to use '!' for the expression
+#pragma warning disable CS8600
                             (connection, response) = await connectionPool.CreateHttp11ConnectionAsync(request, async, cancellationToken).ConfigureAwait(false);
 #pragma warning restore CS8600
                             if (response != null)
index ed85913..3213e1e 100644 (file)
@@ -806,8 +806,8 @@ namespace System.Net.WebSockets
                         {
                             throw new WebSocketException(WebSocketError.InvalidMessageType,
                                 SR.Format(SR.net_WebSockets_InvalidMessageType,
-                                    typeof(WebSocket).Name + "." + nameof(CloseAsync),
-                                    typeof(WebSocket).Name + "." + nameof(CloseOutputAsync),
+                                    nameof(WebSocket) + "." + nameof(CloseAsync),
+                                    nameof(WebSocket) + "." + nameof(CloseOutputAsync),
                                     receiveResult.MessageType));
                         }
                     }
index ac676de..b0778f5 100644 (file)
@@ -380,7 +380,7 @@ namespace System
         private void PublicationOnlyWaitForOtherThreadToPublish()
         {
             SpinWait spinWait = default;
-            while (!ReferenceEquals(_state, null))
+            while (_state is not null)
             {
                 // We get here when PublicationOnly temporarily sets _state to LazyHelper.PublicationOnlyWaitForOtherThreadToPublish.
                 // This temporary state should be quickly followed by _state being set to null.
index 6c22ab3..0fa9141 100644 (file)
@@ -97,7 +97,7 @@ namespace System
         // Otherwise, returns the underlying type of the Nullable type
         public static Type? GetUnderlyingType(Type nullableType)
         {
-            if ((object)nullableType == null)
+            if (nullableType is null)
             {
                 throw new ArgumentNullException(nameof(nullableType));
             }
index ccc7bd6..b49250a 100644 (file)
@@ -26,7 +26,7 @@ namespace System.Runtime.Serialization
         [CLSCompliant(false)]
         public SerializationInfo(Type type, IFormatterConverter converter)
         {
-            if ((object)type == null)
+            if (type is null)
             {
                 throw new ArgumentNullException(nameof(type));
             }
@@ -91,7 +91,7 @@ namespace System.Runtime.Serialization
 
         public void SetType(Type type)
         {
-            if ((object)type == null)
+            if (type is null)
             {
                 throw new ArgumentNullException(nameof(type));
             }
@@ -145,12 +145,12 @@ namespace System.Runtime.Serialization
 
         public void AddValue(string name, object? value, Type type)
         {
-            if (null == name)
+            if (name is null)
             {
                 throw new ArgumentNullException(nameof(name));
             }
 
-            if ((object)type == null)
+            if (type is null)
             {
                 throw new ArgumentNullException(nameof(type));
             }
@@ -287,7 +287,7 @@ namespace System.Runtime.Serialization
         {
             Debug.Assert(null != name, "[SerializationInfo.UpdateValue]name!=null");
             Debug.Assert(null != value, "[SerializationInfo.UpdateValue]value!=null");
-            Debug.Assert(null != (object)type, "[SerializationInfo.UpdateValue]type!=null");
+            Debug.Assert(type is not null, "[SerializationInfo.UpdateValue]type!=null");
 
             int index = FindElement(name);
             if (index < 0)
@@ -334,7 +334,7 @@ namespace System.Runtime.Serialization
             Debug.Assert(index < _types.Length, "[SerializationInfo.GetElement]index<_types.Length");
 
             foundType = _types[index];
-            Debug.Assert((object)foundType != null, "[SerializationInfo.GetElement]foundType!=null");
+            Debug.Assert(foundType is not null, "[SerializationInfo.GetElement]foundType!=null");
             return _values[index];
         }
 
@@ -351,13 +351,13 @@ namespace System.Runtime.Serialization
             Debug.Assert(index < _types.Length, "[SerializationInfo.GetElement]index<_types.Length");
 
             foundType = _types[index];
-            Debug.Assert((object)foundType != null, "[SerializationInfo.GetElement]foundType!=null");
+            Debug.Assert(foundType is not null, "[SerializationInfo.GetElement]foundType!=null");
             return _values[index];
         }
 
         public object? GetValue(string name, Type type)
         {
-            if ((object)type == null)
+            if (type is null)
             {
                 throw new ArgumentNullException(nameof(type));
             }
@@ -378,7 +378,7 @@ namespace System.Runtime.Serialization
 
         internal object? GetValueNoThrow(string name, Type type)
         {
-            Debug.Assert((object)type != null, "[SerializationInfo.GetValue]type ==null");
+            Debug.Assert(type is not null, "[SerializationInfo.GetValue]type ==null");
             Debug.Assert(type.IsRuntimeImplemented(), "[SerializationInfo.GetValue]type is not a runtime type");
 
             object? value = GetElementNoThrow(name, out Type? foundType);
index c616ae9..44deea8 100644 (file)
@@ -538,7 +538,7 @@ namespace System
 
         public bool EndsWith(string value, StringComparison comparisonType)
         {
-            if ((object)value == null)
+            if (value is null)
             {
                 throw new ArgumentNullException(nameof(value));
             }
index 92d98ab..53580de 100644 (file)
@@ -179,7 +179,7 @@ namespace System.Xml
 
         public bool Equals(PrefixHandle? prefix2)
         {
-            if (ReferenceEquals(prefix2, null))
+            if (prefix2 is null)
                 return false;
             PrefixHandleType type1 = _type;
             PrefixHandleType type2 = prefix2._type;
index 3f8fa8b..fce097e 100644 (file)
@@ -228,7 +228,7 @@ namespace System.Xml
 
         public bool Equals(StringHandle? other)
         {
-            if (ReferenceEquals(other, null))
+            if (other is null)
                 return false;
             StringHandleType type = other._type;
             if (type == StringHandleType.Dictionary)
index 95f9aa9..662f245 100644 (file)
@@ -315,7 +315,7 @@ namespace System.Xml
             if (object.ReferenceEquals(id1, id2))
                 return true;
 
-            if (object.ReferenceEquals(id1, null) || object.ReferenceEquals(id2, null))
+            if (id1 is null || id2 is null)
                 return false;
 
 #pragma warning suppress 56506 // Microsoft, checks for whether id1 and id2 are null done above.
index 3b4cb45..f804daf 100644 (file)
@@ -248,7 +248,7 @@ namespace System
 
         private bool IsNotAbsoluteUri
         {
-            get { return (object)_syntax == null; }
+            get { return _syntax is null; }
         }
 
         //
@@ -351,7 +351,7 @@ namespace System
         //
         public Uri(string uriString)
         {
-            if ((object)uriString == null)
+            if (uriString is null)
                 throw new ArgumentNullException(nameof(uriString));
 
             CreateThis(uriString, false, UriKind.Absolute);
@@ -440,7 +440,7 @@ namespace System
             }
 
             uriString = serializationInfo.GetString("RelativeUri");  // Do not rename (binary serialization)
-            if ((object?)uriString == null)
+            if (uriString is null)
                 throw new ArgumentException(SR.Format(SR.InvalidNullArgument, "RelativeUri"), nameof(serializationInfo));
 
             CreateThis(uriString, false, UriKind.Relative);
@@ -1249,10 +1249,11 @@ namespace System
         //
         public static UriHostNameType CheckHostName(string? name)
         {
-            if ((object?)name == null || name.Length == 0 || name.Length > short.MaxValue)
+            if (string.IsNullOrEmpty(name) || name.Length > short.MaxValue)
             {
                 return UriHostNameType.Unknown;
             }
+
             int end = name.Length;
             unsafe
             {
@@ -1464,12 +1465,11 @@ namespace System
         //
         public static bool CheckSchemeName(string? schemeName)
         {
-            if (((object?)schemeName == null)
-                || (schemeName.Length == 0)
-                || !UriHelper.IsAsciiLetter(schemeName[0]))
+            if (string.IsNullOrEmpty(schemeName) || !UriHelper.IsAsciiLetter(schemeName[0]))
             {
                 return false;
             }
+
             for (int i = schemeName.Length - 1; i > 0; --i)
             {
                 if (!(UriHelper.IsAsciiLetterOrDigit(schemeName[i])
@@ -1480,6 +1480,7 @@ namespace System
                     return false;
                 }
             }
+
             return true;
         }
 
@@ -1742,7 +1743,7 @@ namespace System
 
         public Uri MakeRelativeUri(Uri uri)
         {
-            if ((object?)uri == null)
+            if (uri is null)
                 throw new ArgumentNullException(nameof(uri));
 
             if (IsNotAbsoluteUri || uri.IsNotAbsoluteUri)
@@ -2374,7 +2375,7 @@ namespace System
                 else if (NotAny(Flags.CanonicalDnsHost))
                 {
                     // Check to see if we can take the canonical host string out of _string
-                    if ((object?)_info.ScopeId != null)
+                    if (_info.ScopeId is not null)
                     {
                         // IPv6 ScopeId is included when serializing a Uri
                         flags |= (Flags.HostNotCanonical | Flags.E_HostNotCanonical);
@@ -2467,7 +2468,7 @@ namespace System
             string host = _syntax.InternalGetComponents(this, UriComponents.Host, UriFormat.UriEscaped);
 
             // ATTN: Check on whether recursion has not happened
-            if ((object?)_info.Host == null)
+            if (_info.Host is null)
             {
                 if (host.Length >= c_MaxUriBufferSize)
                     throw GetException(ParsingError.SizeLimit)!;
@@ -2511,7 +2512,7 @@ namespace System
             //
             string portStr = _syntax.InternalGetComponents(this, UriComponents.StrongPort, UriFormat.UriEscaped);
             int port = 0;
-            if ((object)portStr == null || portStr.Length == 0)
+            if (string.IsNullOrEmpty(portStr))
             {
                 // It's like no port
                 _flags &= ~Flags.NotDefaultPort;
@@ -2579,7 +2580,7 @@ namespace System
             if ((unchecked((ushort)uriParts) & nonCanonical) == 0)
             {
                 string? ret = GetUriPartsFromUserString(uriParts);
-                if ((object?)ret != null)
+                if (ret is not null)
                 {
                     return ret;
                 }
@@ -2614,7 +2615,7 @@ namespace System
             if ((unchecked((ushort)uriParts) & nonCanonical) == 0)
             {
                 string? ret = GetUriPartsFromUserString(uriParts);
-                if ((object?)ret != null)
+                if (ret is not null)
                 {
                     return ret;
                 }
@@ -2752,7 +2753,7 @@ namespace System
 
                 // A fix up only for SerializationInfo and IpV6 host with a scopeID
                 if ((parts & UriComponents.SerializationInfoString) != 0 && HostType == Flags.IPv6HostType &&
-                    (object?)_info.ScopeId != null)
+                    _info.ScopeId is not null)
                 {
                     _info.ScopeId.CopyTo(0, chars, count - 1, _info.ScopeId.Length);
                     count += _info.ScopeId.Length;
index 5b17d47..049d5d4 100644 (file)
@@ -45,7 +45,7 @@ namespace System
 
         public UriBuilder(Uri uri)
         {
-            if ((object?)uri == null)
+            if (uri is null)
                 throw new ArgumentNullException(nameof(uri));
 
             Init(uri);
index 1491d07..66552d0 100644 (file)
@@ -338,13 +338,14 @@ namespace System
         public static int Compare(Uri? uri1, Uri? uri2, UriComponents partsToCompare, UriFormat compareFormat,
             StringComparison comparisonType)
         {
-            if ((object?)uri1 == null)
+            if (uri1 is null)
             {
-                if (uri2 == null)
+                if (uri2 is null)
                     return 0; // Equal
                 return -1;    // null < non-null
             }
-            if ((object?)uri2 == null)
+
+            if (uri2 is null)
                 return 1;     // non-null > null
 
             // a relative uri is always less than an absolute one
@@ -523,7 +524,7 @@ namespace System
 
         public static string UnescapeDataString(string stringToUnescape)
         {
-            if ((object)stringToUnescape == null)
+            if (stringToUnescape is null)
                 throw new ArgumentNullException(nameof(stringToUnescape));
 
             if (stringToUnescape.Length == 0)
@@ -652,7 +653,7 @@ namespace System
 
             string relativeStr;
 
-            if ((object?)relativeUri != null)
+            if (relativeUri is not null)
             {
                 if (relativeUri.IsAbsoluteUri)
                     return relativeUri;
@@ -661,7 +662,9 @@ namespace System
                 userEscaped = relativeUri.UserEscaped;
             }
             else
+            {
                 relativeStr = string.Empty;
+            }
 
             // Here we can assert that passed "relativeUri" is indeed a relative one
 
@@ -821,7 +824,7 @@ namespace System
 
         public bool IsBaseOf(Uri uri)
         {
-            if ((object)uri == null)
+            if (uri is null)
                 throw new ArgumentNullException(nameof(uri));
 
             if (!IsAbsoluteUri)
index 5069acd..669ac56 100644 (file)
@@ -497,8 +497,7 @@ namespace System
 
                         int byteCount = 1;
                         // lazy initialization of max size, will reuse the array for next sequences
-                        if ((object?)bytes == null)
-                            bytes = new byte[end - next];
+                        bytes ??= new byte[end - next];
 
                         bytes[0] = (byte)ch;
                         next += 3;
index fb5e605..1a2c90c 100644 (file)
@@ -1224,7 +1224,7 @@ namespace System.Xml.Serialization
         {
             // CONSIDER: need the real type name
             if (args.Severity == XmlSeverityType.Error)
-                throw new InvalidOperationException(SR.Format(SR.XmlSerializableSchemaError, typeof(IXmlSerializable).Name, args.Message));
+                throw new InvalidOperationException(SR.Format(SR.XmlSerializableSchemaError, nameof(IXmlSerializable), args.Message));
         }
 
         internal void CheckDuplicateElement(XmlSchemaElement? element, string? elementNs)
@@ -1316,7 +1316,7 @@ namespace System.Xml.Serialization
                         }
                         else
                         {
-                            throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodReturnType, _type!.Name, _getSchemaMethod.Name, typeof(XmlSchemaProviderAttribute).Name, typeof(XmlQualifiedName).FullName));
+                            throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodReturnType, _type!.Name, _getSchemaMethod.Name, nameof(XmlSchemaProviderAttribute), typeof(XmlQualifiedName).FullName));
                         }
                     }
                     else
index 36bd95b..e5ac5ad 100644 (file)
@@ -299,7 +299,7 @@ namespace System.Xml.Serialization
 
         private void Write1_XmlSchemaAttribute(XmlSchemaAttribute? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("attribute");
             WriteAttribute(@"id", @"", ((string?)o.@Id));
             WriteAttributes((XmlAttribute[]?)o.@UnhandledAttributes, o);
@@ -335,7 +335,7 @@ namespace System.Xml.Serialization
 
         private void Write3_XmlSchemaObject(XmlSchemaObject? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             System.Type t = o.GetType();
 
             if (t == typeof(XmlSchemaComplexType))
@@ -492,7 +492,7 @@ namespace System.Xml.Serialization
 
         private void Write5_XmlSchemaAnnotation(XmlSchemaAnnotation? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("annotation");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -518,7 +518,7 @@ namespace System.Xml.Serialization
 
         private void Write6_XmlSchemaDocumentation(XmlSchemaDocumentation o)
         {
-            if ((object)o == null) return;
+            if (o is null) return;
             WriteStartElement("documentation");
 
             WriteAttribute(@"source", @"", ((string?)o.@Source));
@@ -538,7 +538,7 @@ namespace System.Xml.Serialization
 
         private void Write7_XmlSchemaAppInfo(XmlSchemaAppInfo? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("appinfo");
 
             WriteAttribute("source", "", o.Source);
@@ -557,7 +557,7 @@ namespace System.Xml.Serialization
 
         private void Write9_XmlSchemaSimpleType(XmlSchemaSimpleType? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("simpleType");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -587,7 +587,7 @@ namespace System.Xml.Serialization
 
         private void Write12_XmlSchemaSimpleTypeUnion(XmlSchemaSimpleTypeUnion? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("union");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -619,7 +619,7 @@ namespace System.Xml.Serialization
 
         private void Write14_XmlSchemaSimpleTypeList(XmlSchemaSimpleTypeList o)
         {
-            if ((object)o == null) return;
+            if (o is null) return;
             WriteStartElement("list");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -635,7 +635,7 @@ namespace System.Xml.Serialization
 
         private void Write15_XmlSchemaSimpleTypeRestriction(XmlSchemaSimpleTypeRestriction? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("restriction");
             WriteAttribute(@"id", @"", ((string?)o.@Id));
             WriteAttributes((XmlAttribute[]?)o.@UnhandledAttributes, o);
@@ -715,7 +715,7 @@ namespace System.Xml.Serialization
 
         private void Write_XmlSchemaFacet(string name, XmlSchemaFacet? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement(name);
 
             WriteAttribute("id", "", o.Id);
@@ -744,7 +744,7 @@ namespace System.Xml.Serialization
 
         private void Write31_XmlSchemaAttributeGroup(XmlSchemaAttributeGroup? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("attributeGroup");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -758,7 +758,7 @@ namespace System.Xml.Serialization
 
         private void Write32_XmlSchemaAttributeGroupRef(XmlSchemaAttributeGroupRef? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("attributeGroup");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -774,7 +774,7 @@ namespace System.Xml.Serialization
 
         private void Write33_XmlSchemaAnyAttribute(XmlSchemaAnyAttribute? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("anyAttribute");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -801,7 +801,7 @@ namespace System.Xml.Serialization
 
         private void Write35_XmlSchemaComplexType(XmlSchemaComplexType o)
         {
-            if ((object)o == null) return;
+            if (o is null) return;
             WriteStartElement("complexType");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -849,7 +849,7 @@ namespace System.Xml.Serialization
 
         private void Write36_XmlSchemaSimpleContent(XmlSchemaSimpleContent? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("simpleContent");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -868,7 +868,7 @@ namespace System.Xml.Serialization
 
         private void Write38_XmlSchemaSimpleContentExtension(XmlSchemaSimpleContentExtension o)
         {
-            if ((object)o == null) return;
+            if (o is null) return;
             WriteStartElement("extension");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -885,7 +885,7 @@ namespace System.Xml.Serialization
 
         private void Write40_XmlSchemaSimpleContentRestriction(XmlSchemaSimpleContentRestriction? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("restriction");
             WriteAttribute(@"id", @"", ((string?)o.@Id));
             WriteAttributes((XmlAttribute[]?)o.@UnhandledAttributes, o);
@@ -903,7 +903,7 @@ namespace System.Xml.Serialization
 
         private void Write41_XmlSchemaComplexContent(XmlSchemaComplexContent? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("complexContent");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -923,7 +923,7 @@ namespace System.Xml.Serialization
 
         private void Write42_XmlSchemaComplexContentExtension(XmlSchemaComplexContentExtension? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("extension");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -956,7 +956,7 @@ namespace System.Xml.Serialization
 
         private void Write43_XmlSchemaAll(XmlSchemaAll o)
         {
-            if ((object)o == null) return;
+            if (o is null) return;
             WriteStartElement("all");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -970,7 +970,7 @@ namespace System.Xml.Serialization
 
         private void Write46_XmlSchemaElement(XmlSchemaElement? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("element");
             WriteAttribute(@"id", @"", o.Id);
             WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs));
@@ -1031,7 +1031,7 @@ namespace System.Xml.Serialization
 
         private void Write47_XmlSchemaKey(XmlSchemaKey? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("key");
             WriteAttribute(@"id", @"", ((string?)o.@Id));
             WriteAttribute(@"name", @"", ((string?)o.@Name));
@@ -1053,7 +1053,7 @@ namespace System.Xml.Serialization
 
         private void Write48_XmlSchemaIdentityConstraint(XmlSchemaIdentityConstraint? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             System.Type t = o.GetType();
             if (t == typeof(XmlSchemaUnique))
             {
@@ -1074,7 +1074,7 @@ namespace System.Xml.Serialization
 
         private void Write49_XmlSchemaXPath(string name, string ns, XmlSchemaXPath? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement(name);
             WriteAttribute(@"id", @"", o.@Id);
             WriteAttribute(@"xpath", @"", o.@XPath);
@@ -1085,7 +1085,7 @@ namespace System.Xml.Serialization
 
         private void Write50_XmlSchemaKeyref(XmlSchemaKeyref? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("keyref");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1110,7 +1110,7 @@ namespace System.Xml.Serialization
 
         private void Write51_XmlSchemaUnique(XmlSchemaUnique? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("unique");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1131,7 +1131,7 @@ namespace System.Xml.Serialization
 
         private void Write52_XmlSchemaChoice(XmlSchemaChoice? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("choice");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1145,7 +1145,7 @@ namespace System.Xml.Serialization
 
         private void Write53_XmlSchemaAny(XmlSchemaAny? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("any");
 
             WriteAttribute(@"id", @"", o.@Id);
@@ -1161,7 +1161,7 @@ namespace System.Xml.Serialization
 
         private void Write54_XmlSchemaSequence(XmlSchemaSequence? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("sequence");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1202,7 +1202,7 @@ namespace System.Xml.Serialization
 
         private void Write55_XmlSchemaGroupRef(XmlSchemaGroupRef? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("group");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1220,7 +1220,7 @@ namespace System.Xml.Serialization
 
         private void Write56_XmlSchemaComplexContentRestriction(XmlSchemaComplexContentRestriction? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("restriction");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
@@ -1255,7 +1255,7 @@ namespace System.Xml.Serialization
 
         private void Write57_XmlSchemaGroup(XmlSchemaGroup? o)
         {
-            if ((object?)o == null) return;
+            if (o is null) return;
             WriteStartElement("group");
 
             WriteAttribute(@"id", @"", ((string?)o.@Id));
index 967218a..7b70029 100644 (file)
@@ -233,16 +233,16 @@ namespace System.Xml.Serialization
 
         public static bool operator !=(SourceInfo? a, SourceInfo? b)
         {
-            if ((object?)a != null)
+            if (a is not null)
                 return !a.Equals(b);
-            return (object?)b != null;
+            return b is not null;
         }
 
         public static bool operator ==(SourceInfo? a, SourceInfo? b)
         {
-            if ((object?)a != null)
+            if (a is not null)
                 return a.Equals(b);
-            return (object?)b == null;
+            return b is null;
         }
 
         public override bool Equals(object? obj)
index 30035fe..702388f 100644 (file)
@@ -438,7 +438,7 @@ namespace System.Xml.Serialization
                             // We allow XmlRoot attribute on IXmlSerializable, but not others
                             if ((a.XmlFlags & ~XmlAttributeFlags.Root) != 0)
                             {
-                                throw new InvalidOperationException(SR.Format(SR.XmlSerializableAttributes, model.TypeDesc.FullName, typeof(XmlSchemaProviderAttribute).Name));
+                                throw new InvalidOperationException(SR.Format(SR.XmlSerializableAttributes, model.TypeDesc.FullName, nameof(XmlSchemaProviderAttribute)));
                             }
                         }
                         else
@@ -476,10 +476,10 @@ namespace System.Xml.Serialization
 
             MethodInfo? getMethod = getMethod = type.GetMethod(provider.MethodName, /* BindingFlags.DeclaredOnly | */ BindingFlags.Static | BindingFlags.Public, new Type[] { typeof(XmlSchemaSet) });
             if (getMethod == null)
-                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodMissing, provider.MethodName, typeof(XmlSchemaSet).Name, type.FullName));
+                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodMissing, provider.MethodName, nameof(XmlSchemaSet), type.FullName));
 
             if (!(typeof(XmlQualifiedName).IsAssignableFrom(getMethod.ReturnType)) && !(typeof(XmlSchemaType).IsAssignableFrom(getMethod.ReturnType)))
-                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodReturnType, type.Name, provider.MethodName, typeof(XmlSchemaProviderAttribute).Name, typeof(XmlQualifiedName).FullName, typeof(XmlSchemaType).FullName));
+                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodReturnType, type.Name, provider.MethodName, nameof(XmlSchemaProviderAttribute), typeof(XmlQualifiedName).FullName, typeof(XmlSchemaType).FullName));
 
             return getMethod;
         }
@@ -574,7 +574,7 @@ namespace System.Xml.Serialization
             }
             if (srcSchemas.Count > 1)
             {
-                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaInclude, baseQname.Namespace, typeof(IXmlSerializable).Name, "GetSchema"));
+                throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaInclude, baseQname.Namespace, nameof(IXmlSerializable), "GetSchema"));
             }
             XmlSchema s = (XmlSchema)srcSchemas[0]!;
 
@@ -1540,7 +1540,7 @@ namespace System.Xml.Serialization
                     {
                         if (accessor.TypeDesc.ArrayElementTypeDesc.Kind == TypeKind.Serializable)
                         {
-                            throw new InvalidOperationException(SR.Format(SR.XmlIllegalAttrOrTextInterface, accessorName, accessor.TypeDesc.ArrayElementTypeDesc.FullName, typeof(IXmlSerializable).Name));
+                            throw new InvalidOperationException(SR.Format(SR.XmlIllegalAttrOrTextInterface, accessorName, accessor.TypeDesc.ArrayElementTypeDesc.FullName, nameof(IXmlSerializable)));
                         }
                         else
                         {
@@ -1834,7 +1834,7 @@ namespace System.Xml.Serialization
                     {
                         if (accessor.TypeDesc.Kind == TypeKind.Serializable)
                         {
-                            throw new InvalidOperationException(SR.Format(SR.XmlIllegalAttrOrTextInterface, accessorName, accessor.TypeDesc.FullName, typeof(IXmlSerializable).Name));
+                            throw new InvalidOperationException(SR.Format(SR.XmlIllegalAttrOrTextInterface, accessorName, accessor.TypeDesc.FullName, nameof(IXmlSerializable)));
                         }
                         else
                         {
@@ -2050,7 +2050,7 @@ namespace System.Xml.Serialization
                     if (choiceTypes.Contains(type))
                     {
                         // You need to add {0} to the '{1}'.
-                        throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMissing, typeof(XmlChoiceIdentifierAttribute).Name, accessorName));
+                        throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMissing, nameof(XmlChoiceIdentifierAttribute), accessorName));
                     }
                     else
                     {
@@ -2061,7 +2061,7 @@ namespace System.Xml.Serialization
             if (choiceTypes.Contains(typeof(XmlElement)) && a.XmlAnyElements.Count > 0)
             {
                 // You need to add {0} to the '{1}'.
-                throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMissing, typeof(XmlChoiceIdentifierAttribute).Name, accessorName));
+                throw new InvalidOperationException(SR.Format(SR.XmlChoiceIdentiferMissing, nameof(XmlChoiceIdentifierAttribute), accessorName));
             }
 
             XmlArrayItemAttributes items = a.XmlArrayItems;
@@ -2076,7 +2076,7 @@ namespace System.Xml.Serialization
                     XmlArrayItemAttribute? item = (XmlArrayItemAttribute?)arrayTypes[type.FullName, ns];
                     if (item != null)
                     {
-                        throw new InvalidOperationException(SR.Format(SR.XmlArrayItemAmbiguousTypes, accessorName, item.ElementName, items[i]!.ElementName, typeof(XmlElementAttribute).Name, typeof(XmlChoiceIdentifierAttribute).Name, accessorName));
+                        throw new InvalidOperationException(SR.Format(SR.XmlArrayItemAmbiguousTypes, accessorName, item.ElementName, items[i]!.ElementName, nameof(XmlElementAttribute), nameof(XmlChoiceIdentifierAttribute), accessorName));
                     }
                     else
                     {
index fa90a9a..471c668 100644 (file)
@@ -1346,7 +1346,7 @@ namespace System.Xml.Serialization
 
         protected Exception CreateMissingIXmlSerializableType(string? name, string? ns, string? clrType)
         {
-            return new InvalidOperationException(SR.Format(SR.XmlSerializableMissingClrType, name, ns, typeof(XmlIncludeAttribute).Name, clrType));
+            return new InvalidOperationException(SR.Format(SR.XmlSerializableMissingClrType, name, ns, nameof(XmlIncludeAttribute), clrType));
             //XmlSerializableMissingClrType= Type '{0}' from namespace '{1}' doesnot have corresponding IXmlSerializable type. Please consider adding {2} to '{3}'.
         }
 
index 6ff8642..3bfdd36 100644 (file)
@@ -110,7 +110,7 @@ namespace System.Xml
             if ((object?)a == (object?)b)
                 return true;
 
-            if ((object?)a == null || (object?)b == null)
+            if (a is null || b is null)
                 return false;
 
             return a.Name == b.Name && a.Namespace == b.Namespace;
index 413c51a..12bda6f 100644 (file)
@@ -111,7 +111,7 @@ namespace System.Xml.Xsl.Qil
             {
                 return true;
             }
-            if ((object?)a == null || (object?)b == null)
+            if (a is null || b is null)
             {
                 return false;
             }
index b8a9c6c..0883d4d 100644 (file)
@@ -229,8 +229,8 @@ namespace System.Xml.Xsl
         /// </summary>
         public static bool operator ==(XmlQueryType? left, XmlQueryType? right)
         {
-            if ((object?)left == null)
-                return ((object?)right == null);
+            if (left is null)
+                return right is null;
 
             return left.Equals(right);
         }
@@ -240,8 +240,8 @@ namespace System.Xml.Xsl
         /// </summary>
         public static bool operator !=(XmlQueryType? left, XmlQueryType? right)
         {
-            if ((object?)left == null)
-                return ((object?)right != null);
+            if (left is null)
+                return right is not null;
 
             return !left.Equals(right);
         }
index 3eb1385..46b3471 100644 (file)
@@ -51,7 +51,7 @@ namespace System.Reflection.TypeLoading
         // assembly binding unification rules.
         public bool Equals(RoAssemblyName? other)
         {
-            Debug.Assert(other is object);
+            Debug.Assert(other is not null);
             if (Name != other.Name)
                 return false;
             if (Version != other.Version)
index 3b79628..90ad6fe 100644 (file)
@@ -102,16 +102,16 @@ namespace System.Security.Cryptography
 
         public bool Equals(RSAEncryptionPadding? other)
         {
-            return !object.ReferenceEquals(other, null)
+            return other is not null
                 && _mode == other._mode
                 && _oaepHashAlgorithm == other._oaepHashAlgorithm;
         }
 
         public static bool operator ==(RSAEncryptionPadding? left, RSAEncryptionPadding? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return object.ReferenceEquals(right, null);
+                return right is null;
             }
 
             return left.Equals(right);
index b69062b..de0f413 100644 (file)
@@ -61,14 +61,14 @@ namespace System.Security.Cryptography
 
         public bool Equals(RSASignaturePadding? other)
         {
-            return !object.ReferenceEquals(other, null) && _mode == other._mode;
+            return other is not null && _mode == other._mode;
         }
 
         public static bool operator ==(RSASignaturePadding? left, RSASignaturePadding? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return object.ReferenceEquals(right, null);
+                return right is null;
             }
 
             return left.Equals(right);
index 8237d88..4b09c97 100644 (file)
@@ -37,9 +37,9 @@ namespace System.Security.Cryptography
 
         public static bool operator ==(CngAlgorithm? left, CngAlgorithm? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return object.ReferenceEquals(right, null);
+                return right is null;
             }
 
             return left.Equals(right);
@@ -47,9 +47,9 @@ namespace System.Security.Cryptography
 
         public static bool operator !=(CngAlgorithm? left, CngAlgorithm? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return !object.ReferenceEquals(right, null);
+                return right is not null;
             }
 
             return !left.Equals(right);
@@ -64,7 +64,7 @@ namespace System.Security.Cryptography
 
         public bool Equals(CngAlgorithm? other)
         {
-            if (object.ReferenceEquals(other, null))
+            if (other is null)
             {
                 return false;
             }
index e98a848..b5c4522 100644 (file)
@@ -38,9 +38,9 @@ namespace System.Security.Cryptography
 
         public static bool operator ==(CngAlgorithmGroup? left, CngAlgorithmGroup? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return object.ReferenceEquals(right, null);
+                return right is null;
             }
 
             return left.Equals(right);
@@ -48,9 +48,9 @@ namespace System.Security.Cryptography
 
         public static bool operator !=(CngAlgorithmGroup? left, CngAlgorithmGroup? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return !object.ReferenceEquals(right, null);
+                return right is not null;
             }
 
             return !left.Equals(right);
@@ -65,7 +65,7 @@ namespace System.Security.Cryptography
 
         public bool Equals(CngAlgorithmGroup? other)
         {
-            if (object.ReferenceEquals(other, null))
+            if (other is null)
             {
                 return false;
             }
index 126597a..3165a4d 100644 (file)
@@ -38,9 +38,9 @@ namespace System.Security.Cryptography
 
         public static bool operator ==(CngKeyBlobFormat? left, CngKeyBlobFormat? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return object.ReferenceEquals(right, null);
+                return right is null;
             }
 
             return left.Equals(right);
@@ -48,9 +48,9 @@ namespace System.Security.Cryptography
 
         public static bool operator !=(CngKeyBlobFormat? left, CngKeyBlobFormat? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return !object.ReferenceEquals(right, null);
+                return right is not null;
             }
 
             return !left.Equals(right);
@@ -65,7 +65,7 @@ namespace System.Security.Cryptography
 
         public bool Equals(CngKeyBlobFormat? other)
         {
-            if (object.ReferenceEquals(other, null))
+            if (other is null)
             {
                 return false;
             }
index e990a1c..3547b0f 100644 (file)
@@ -37,17 +37,17 @@ namespace System.Security.Cryptography
 
         public static bool operator ==(CngProvider? left, CngProvider? right)
         {
-            if (object.ReferenceEquals(left, null))
-                return object.ReferenceEquals(right, null);
+            if (left is null)
+                return right is null;
 
             return left.Equals(right);
         }
 
         public static bool operator !=(CngProvider? left, CngProvider? right)
         {
-            if (object.ReferenceEquals(left, null))
+            if (left is null)
             {
-                return !object.ReferenceEquals(right, null);
+                return right is not null;
             }
 
             return !left.Equals(right);
@@ -62,7 +62,7 @@ namespace System.Security.Cryptography
 
         public bool Equals(CngProvider? other)
         {
-            if (object.ReferenceEquals(other, null))
+            if (other is null)
             {
                 return false;
             }
index d724958..47d67ae 100644 (file)
@@ -1081,7 +1081,7 @@ namespace Internal.NativeCrypto
             else
             {
                 Type? hashAlgType = hashAlg as Type;
-                if ((object?)hashAlgType != null)
+                if (hashAlgType is not null)
                 {
                     if (typeof(MD5).IsAssignableFrom(hashAlgType))
                         return CapiHelper.CALG_MD5;
index 420b33f..779ef83 100644 (file)
@@ -403,7 +403,6 @@ namespace System
         private static bool FilterApplyType(
             Type type, BindingFlags bindingFlags, string? name, bool prefixLookup, string? ns)
         {
-            Debug.Assert((object)type != null);
             Debug.Assert(type is RuntimeType);
 
             bool isPublic = type.IsNestedPublic || type.IsPublic;
@@ -545,7 +544,7 @@ namespace System
                             for (int i = 0; i < parameterInfos.Length; i++)
                             {
                                 // a null argument type implies a null arg which is always a perfect match
-                                if ((object)argumentTypes[i] != null && !argumentTypes[i].MatchesParameterTypeExactly(parameterInfos[i]))
+                                if (argumentTypes[i] is not null && !argumentTypes[i].MatchesParameterTypeExactly(parameterInfos[i]))
                                     return false;
                             }
                         }
@@ -898,7 +897,7 @@ namespace System
                 {
                     PropertyInfo firstCandidate = candidates[0];
 
-                    if ((object?)returnType != null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
+                    if (returnType is not null && !returnType.IsEquivalentTo(firstCandidate.PropertyType))
                         return null;
 
                     return firstCandidate;
index 8b0cd0a..14c6dbe 100644 (file)
@@ -268,7 +268,7 @@ namespace Microsoft.WebAssembly.Diagnostics
 
         public override int GetHashCode() => assembly.GetHashCode() ^ document.GetHashCode();
 
-        public static bool operator ==(SourceId a, SourceId b) => ((object)a == null) ? (object)b == null : a.Equals(b);
+        public static bool operator ==(SourceId a, SourceId b) => a is null ? b is null : a.Equals(b);
 
         public static bool operator !=(SourceId a, SourceId b) => !a.Equals(b);
     }