From 6b5b9f724209ce1a185c3713b5cc8a05eae3a4ba Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 25 Sep 2020 06:33:07 -0400 Subject: [PATCH] Enable several more IDE analyzer warnings (#42692) * 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 --- eng/CodeAnalysis.ruleset | 10 +-- .../src/System/MulticastDelegate.cs | 2 +- .../System/Reflection/RuntimePropertyInfo.cs | 2 +- .../src/System/RuntimeType.CoreCLR.cs | 6 +- .../System/Drawing/ColorConverterCommon.cs | 2 +- .../RuntimeBinder/RuntimeBinderExtensions.cs | 2 +- .../RuntimeBinder/Semantics/WithType.cs | 4 +- .../src/Dependency.cs | 2 +- .../src/EventId.cs | 2 +- .../src/StringSegment.cs | 2 +- .../Primitives/ImportDefinition.cs | 2 +- .../CurrentScopeExportDescriptorProvider.cs | 2 +- .../src/System/Data/DataRowComparer.cs | 12 ++-- .../System/Drawing/ImageAnimator.Windows.cs | 2 +- .../MemoryMappedView.Unix.cs | 2 +- .../src/System/IO/Pipelines/PipeAwaitable.cs | 2 +- .../src/System/Dynamic/Utils/TypeUtils.cs | 2 +- .../System/Linq/Expressions/Compiler/ILGen.cs | 2 +- .../Compiler/LambdaCompiler.Address.cs | 4 +- .../Compiler/LambdaCompiler.Expressions.cs | 4 +- .../Interpreter/CallInstruction.cs | 6 +- .../Expressions/Interpreter/LightCompiler.cs | 4 +- .../src/System/Net/Http/HttpMethod.cs | 4 +- .../AuthenticationHelper.NtAuth.cs | 3 +- .../Net/Windows/WebSockets/WebSocketBase.cs | 4 +- .../System.Private.CoreLib/src/System/Lazy.cs | 2 +- .../src/System/Nullable.cs | 2 +- .../Serialization/SerializationInfo.cs | 18 +++--- .../src/System/String.Comparison.cs | 2 +- .../src/System/Xml/PrefixHandle.cs | 2 +- .../src/System/Xml/StringHandle.cs | 2 +- .../src/System/Xml/UniqueId.cs | 2 +- .../System.Private.Uri/src/System/Uri.cs | 29 +++++---- .../src/System/UriBuilder.cs | 2 +- .../System.Private.Uri/src/System/UriExt.cs | 15 +++-- .../src/System/UriHelper.cs | 3 +- .../src/System/Xml/Serialization/Mappings.cs | 4 +- .../Xml/Serialization/SchemaObjectWriter.cs | 64 +++++++++---------- .../System/Xml/Serialization/SourceInfo.cs | 8 +-- .../Serialization/XmlReflectionImporter.cs | 18 +++--- .../Serialization/XmlSerializationReader.cs | 2 +- .../src/System/Xml/XmlQualifiedName.cs | 2 +- .../src/System/Xml/Xsl/QIL/QilName.cs | 2 +- .../src/System/Xml/Xsl/XmlQueryType.cs | 8 +-- .../TypeLoading/General/RoAssemblyName.cs | 2 +- .../Cryptography/RSAEncryptionPadding.cs | 6 +- .../Cryptography/RSASignaturePadding.cs | 6 +- .../Security/Cryptography/CngAlgorithm.cs | 10 +-- .../Cryptography/CngAlgorithmGroup.cs | 10 +-- .../Security/Cryptography/CngKeyBlobFormat.cs | 10 +-- .../Security/Cryptography/CngProvider.cs | 10 +-- .../Cryptography/CapiHelper.Windows.cs | 2 +- .../src/System/RuntimeType.Mono.cs | 5 +- .../debugger/BrowserDebugProxy/DebugStore.cs | 2 +- 54 files changed, 171 insertions(+), 168 deletions(-) diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index 217abf54b3a18..6db1a743391dd 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -416,9 +416,9 @@ - + - + @@ -437,7 +437,7 @@ - + @@ -454,10 +454,10 @@ - + - + diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs index fc3ef65f74b52..1a4d993e58f04 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -221,7 +221,7 @@ internal void StoreDynamicMethod(MethodInfo dynamicMethod) // 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... diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index ef1f82b58f362..b7e6a58f1fe4b 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -226,7 +226,7 @@ public override MethodInfo[] GetAccessors(bool nonPublic) 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++) { diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs index 9aef6b1aa583c..85f2f68b6c2e1 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs @@ -2203,7 +2203,7 @@ private static bool FilterApplyBase( 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 @@ private static bool FilterApplyMethodBase( 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 @@ public override InterfaceMapping GetInterfaceMap(Type ifaceType) { 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; diff --git a/src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs b/src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs index e6f7cd3f2adb3..2acfc836c5bea 100644 --- a/src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs +++ b/src/libraries/Common/src/System/Drawing/ColorConverterCommon.cs @@ -121,7 +121,7 @@ private static int IntFromString(string text, CultureInfo culture) } 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); } } diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderExtensions.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderExtensions.cs index 3e3307c998342..c2e01a3e58d6f 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderExtensions.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/RuntimeBinderExtensions.cs @@ -278,7 +278,7 @@ private static bool IsTypeParameterEquivalentToTypeInst(this Type typeParam, Typ // See if MetadataToken property is available. PropertyInfo property = memberInfo.GetProperty("MetadataToken", typeof(int), Array.Empty()); - if ((object)property != null && property.CanRead) + if (property is not null && property.CanRead) { // (parameter1, parameter2) => parameter1.MetadataToken == parameter2.MetadataToken var parameter1 = Expression.Parameter(memberInfo); diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/WithType.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/WithType.cs index 11fff28791c74..da74b334621ec 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/WithType.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Semantics/WithType.cs @@ -63,11 +63,11 @@ public Symbol Sym { 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; } diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs b/src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs index e7e70c944df9b..bf51c3a414a42 100644 --- a/src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs +++ b/src/libraries/Microsoft.Extensions.DependencyModel/src/Dependency.cs @@ -32,7 +32,7 @@ public bool Equals(Dependency other) 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); } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs index a2230c29cab68..5c7d7de2b9d36 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/EventId.cs @@ -79,7 +79,7 @@ public bool Equals(EventId other) /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) + if (obj is null) { return false; } diff --git a/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs b/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs index 288b0e773b317..0d5ddc6931a13 100644 --- a/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs +++ b/src/libraries/Microsoft.Extensions.Primitives/src/StringSegment.cs @@ -159,7 +159,7 @@ public static int Compare(StringSegment a, StringSegment b, StringComparison com /// public override bool Equals(object obj) { - if (ReferenceEquals(null, obj)) + if (obj is null) { return false; } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ImportDefinition.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ImportDefinition.cs index b18c6b76bded5..7a3be926e316f 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ImportDefinition.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Primitives/ImportDefinition.cs @@ -102,7 +102,7 @@ internal ImportDefinition(string? contractName, ImportCardinality cardinality, b (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; diff --git a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Providers/CurrentScope/CurrentScopeExportDescriptorProvider.cs b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Providers/CurrentScope/CurrentScopeExportDescriptorProvider.cs index 25b2c15686935..2faf7c232be2d 100644 --- a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Providers/CurrentScope/CurrentScopeExportDescriptorProvider.cs +++ b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Providers/CurrentScope/CurrentScopeExportDescriptorProvider.cs @@ -17,7 +17,7 @@ public override IEnumerable GetExportDescriptors(Compos return new[] { new ExportDescriptorPromise( contract, - typeof(CompositionContext).Name, + nameof(CompositionContext), true, NoDependencies, _ => ExportDescriptor.Create((c, o) => c, NoMetadata)) }; diff --git a/src/libraries/System.Data.Common/src/System/Data/DataRowComparer.cs b/src/libraries/System.Data.Common/src/System/Data/DataRowComparer.cs index 045f1526f632f..b3e042a701076 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataRowComparer.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataRowComparer.cs @@ -24,8 +24,8 @@ internal static bool AreEqual(object? a, object? b) // 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 @@ private static bool AreElementEqual(object? a, object? b) // 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 @@ public bool Equals(TRow? leftRow, TRow? rightRow) return true; } - if (ReferenceEquals(leftRow, null) || - ReferenceEquals(rightRow, null)) + if (leftRow is null || + rightRow is null) { return false; } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs index a0311f1990a21..d837be3d508f6 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/ImageAnimator.Windows.cs @@ -256,7 +256,7 @@ public static void Animate(Image image, EventHandler onFrameChangedHandler) 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(); } diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs index 7afd7b143aacd..b5e97b23518b4 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Unix.cs @@ -26,7 +26,7 @@ public static unsafe MemoryMappedView CreateView( } if (memMappedFileHandle.IsClosed) { - throw new ObjectDisposedException(typeof(MemoryMappedFile).Name); + throw new ObjectDisposedException(nameof(MemoryMappedFile)); } if (requestedSize == MemoryMappedFile.DefaultSize) diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaitable.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaitable.cs index e7dbad6311144..dab70646c1df4 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaitable.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/PipeAwaitable.cs @@ -100,7 +100,7 @@ public void SetUncompleted() public void OnCompleted(Action 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) { diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs index 7416d97a47a11..c31dc3b7454d0 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs @@ -786,7 +786,7 @@ private static bool IsImplicitNullableConversion(Type source, Type destination) 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)) { diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs index ea863c5bcb4ee..21e914fd7e72b 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/ILGen.cs @@ -16,7 +16,7 @@ internal static void Emit(this ILGenerator il, OpCode opcode, MethodBase methodB 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); } diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Address.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Address.cs index be507c2a2ad14..29b5b83228662 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Address.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Address.cs @@ -131,7 +131,7 @@ private void AddressOf(MemberExpression node, Type type) 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 @@ private void EmitExpressionAddress(Expression node, Type type) 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; } diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs index f29424ef0291c..aab1e749747cc 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/LambdaCompiler.Expressions.cs @@ -803,7 +803,7 @@ private void EmitMemberAssignment(AssignBinaryExpression node, CompilationFlags } var fld = member as FieldInfo; - if ((object?)fld != null) + if (fld is not null) { _ilg.EmitFieldSet((FieldInfo)member); } @@ -840,7 +840,7 @@ private void EmitMemberExpression(Expression expr) private void EmitMemberGet(MemberInfo member, Type? objectType) { var fi = member as FieldInfo; - if ((object?)fi != null) + if (fi is not null) { if (fi.IsLiteral) { diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs index f3b4b7c58be63..c222f01151c40 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs @@ -149,7 +149,7 @@ private static CallInstruction GetArrayAccessor(MethodInfo info, int argumentCou break; } - if ((object?)alternativeMethod == null) + if (alternativeMethod is null) { return new MethodInfoCallInstruction(info, argumentCount); } @@ -261,10 +261,10 @@ private static CallInstruction SlowCreate(MethodInfo info, ParameterInfo[] pis) 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; - if ((object?)thunk != null) + if (thunk is not null) { lightLambda = thunk.Target as LightLambda; if (lightLambda != null) diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightCompiler.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightCompiler.cs index 23de1e75c1b74..534a3f7369887 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightCompiler.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/LightCompiler.cs @@ -1159,7 +1159,7 @@ private void CompileConvertToType(Type typeFrom, Type typeTo, bool isChecked, bo 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 @@ private void CompileConvertToType(Type typeFrom, Type typeTo, bool isChecked, bo } } - if ((object?)enumTypeTo != null) + if (enumTypeTo is not null) { // Convert from underlying to the enum _instructions.EmitCastToEnum(enumTypeTo); diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs index 95fb86420f7d4..ccbae0f866706 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpMethod.cs @@ -120,7 +120,7 @@ private HttpMethod(string method, int? http3StaticTableIndex) public bool Equals(HttpMethod? other) { - if ((object?)other == null) + if (other is null) { return false; } @@ -159,7 +159,7 @@ public override string ToString() 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); } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs index 2ade557ce3329..3b2e569445105 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/AuthenticationHelper.NtAuth.cs @@ -63,7 +63,8 @@ private static async Task SendWithNtAuthAsync(HttpRequestMe 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) diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs index ed859137e21dc..3213e1eb8d71a 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketBase.cs @@ -806,8 +806,8 @@ private async Task CloseAsyncCore(WebSocketCloseStatus closeStatus, { 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)); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Lazy.cs b/src/libraries/System.Private.CoreLib/src/System/Lazy.cs index ac676de6c4c56..b0778f5b71c21 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Lazy.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Lazy.cs @@ -380,7 +380,7 @@ private void PublicationOnlyViaFactory(LazyHelper initializer) 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. diff --git a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs index 6c22ab305b8b2..0fa9141483ee2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Nullable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Nullable.cs @@ -97,7 +97,7 @@ public static bool Equals(Nullable n1, Nullable n2) where T : struct // 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)); } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/SerializationInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/SerializationInfo.cs index ccc7bd66a05df..b49250a36db23 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/SerializationInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Serialization/SerializationInfo.cs @@ -26,7 +26,7 @@ public sealed partial class SerializationInfo [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 @@ public string AssemblyName public void SetType(Type type) { - if ((object)type == null) + if (type is null) { throw new ArgumentNullException(nameof(type)); } @@ -145,12 +145,12 @@ private void ExpandArrays() 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 @@ public void UpdateValue(string name, object value, Type type) { 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 @@ private int FindElement(string name) 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 @@ private int FindElement(string name) 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 @@ private int FindElement(string name) 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); diff --git a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs index c616ae9e28a8e..44deea83bf005 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.Comparison.cs @@ -538,7 +538,7 @@ public bool EndsWith(string value) public bool EndsWith(string value, StringComparison comparisonType) { - if ((object)value == null) + if (value is null) { throw new ArgumentNullException(nameof(value)); } diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs index 92d98ab4276f3..53580ded68bbc 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/PrefixHandle.cs @@ -179,7 +179,7 @@ public int CompareTo(PrefixHandle that) public bool Equals(PrefixHandle? prefix2) { - if (ReferenceEquals(prefix2, null)) + if (prefix2 is null) return false; PrefixHandleType type1 = _type; PrefixHandleType type2 = prefix2._type; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs index 3f8fa8b1bf389..fce097e9e1820 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/StringHandle.cs @@ -228,7 +228,7 @@ private bool Equals2(int offset2, int length2, XmlBufferReader bufferReader2) public bool Equals(StringHandle? other) { - if (ReferenceEquals(other, null)) + if (other is null) return false; StringHandleType type = other._type; if (type == StringHandleType.Dictionary) diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs index 95f9aa904ee1a..662f2454c5146 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Xml/UniqueId.cs @@ -315,7 +315,7 @@ public unsafe override string ToString() 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. diff --git a/src/libraries/System.Private.Uri/src/System/Uri.cs b/src/libraries/System.Private.Uri/src/System/Uri.cs index 3b4cb45812757..f804daf360dfa 100644 --- a/src/libraries/System.Private.Uri/src/System/Uri.cs +++ b/src/libraries/System.Private.Uri/src/System/Uri.cs @@ -248,7 +248,7 @@ private UriParser Syntax private bool IsNotAbsoluteUri { - get { return (object)_syntax == null; } + get { return _syntax is null; } } // @@ -351,7 +351,7 @@ private void EnsureHostString(bool allowDnsOptimization) // 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 @@ protected Uri(SerializationInfo serializationInfo, StreamingContext streamingCon } 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 @@ public string UserInfo // 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 @@ public static bool IsHexEncoding(string pattern, int index) // 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 @@ public static bool CheckSchemeName(string? schemeName) return false; } } + return true; } @@ -1742,7 +1743,7 @@ public override bool Equals(object? comparand) 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 @@ private unsafe void CreateHostString() 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 @@ private unsafe void GetHostViaCustomSyntax() 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 @@ private unsafe void GetHostViaCustomSyntax() // 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 @@ private string GetEscapedParts(UriComponents uriParts) 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 @@ private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs) 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 @@ private string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat // 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; diff --git a/src/libraries/System.Private.Uri/src/System/UriBuilder.cs b/src/libraries/System.Private.Uri/src/System/UriBuilder.cs index 5b17d47f8d2a1..049d5d44f84ee 100644 --- a/src/libraries/System.Private.Uri/src/System/UriBuilder.cs +++ b/src/libraries/System.Private.Uri/src/System/UriBuilder.cs @@ -45,7 +45,7 @@ public UriBuilder(string uri) public UriBuilder(Uri uri) { - if ((object?)uri == null) + if (uri is null) throw new ArgumentNullException(nameof(uri)); Init(uri); diff --git a/src/libraries/System.Private.Uri/src/System/UriExt.cs b/src/libraries/System.Private.Uri/src/System/UriExt.cs index 1491d0715c98e..66552d086da08 100644 --- a/src/libraries/System.Private.Uri/src/System/UriExt.cs +++ b/src/libraries/System.Private.Uri/src/System/UriExt.cs @@ -338,13 +338,14 @@ public string GetComponents(UriComponents components, UriFormat format) 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 @@ internal unsafe bool InternalIsWellFormedOriginalString() 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 @@ private Uri(Flags flags, UriParser? uriParser, string uri) string relativeStr; - if ((object?)relativeUri != null) + if (relativeUri is not null) { if (relativeUri.IsAbsoluteUri) return relativeUri; @@ -661,7 +662,9 @@ private Uri(Flags flags, UriParser? uriParser, string uri) userEscaped = relativeUri.UserEscaped; } else + { relativeStr = string.Empty; + } // Here we can assert that passed "relativeUri" is indeed a relative one @@ -821,7 +824,7 @@ internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFo public bool IsBaseOf(Uri uri) { - if ((object)uri == null) + if (uri is null) throw new ArgumentNullException(nameof(uri)); if (!IsAbsoluteUri) diff --git a/src/libraries/System.Private.Uri/src/System/UriHelper.cs b/src/libraries/System.Private.Uri/src/System/UriHelper.cs index 5069acd553a88..669ac56f6a881 100644 --- a/src/libraries/System.Private.Uri/src/System/UriHelper.cs +++ b/src/libraries/System.Private.Uri/src/System/UriHelper.cs @@ -497,8 +497,7 @@ internal static unsafe void UnescapeString(char* pStr, int start, int end, ref V 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; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs index fb5e6054d95aa..1a2c90c9457e7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/Mappings.cs @@ -1224,7 +1224,7 @@ internal static void ValidationCallbackWithErrorCode(object? sender, ValidationE { // 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 @@ private void RetrieveSerializableSchema() } 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 diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs index 36bd95b2c4e15..e5ac5adefa025 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SchemaObjectWriter.cs @@ -299,7 +299,7 @@ private void WriteSortedItems(XmlSchemaObjectCollection? items) 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 @@ private void Write1_XmlSchemaAttribute(XmlSchemaAttribute? o) 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 @@ private void Write3_XmlSchemaObject(XmlSchemaObject? o) 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 @@ private void Write5_XmlSchemaAnnotation(XmlSchemaAnnotation? o) 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 @@ private void Write6_XmlSchemaDocumentation(XmlSchemaDocumentation o) 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 @@ private void Write7_XmlSchemaAppInfo(XmlSchemaAppInfo? o) 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 @@ private string Write11_XmlSchemaDerivationMethod(XmlSchemaDerivationMethod v) 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 @@ private void Write12_XmlSchemaSimpleTypeUnion(XmlSchemaSimpleTypeUnion? o) 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 @@ private void Write14_XmlSchemaSimpleTypeList(XmlSchemaSimpleTypeList o) 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 @@ private void WriteFacets(XmlSchemaObjectCollection? facets) 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 @@ private void Write_XmlSchemaFacet(string name, XmlSchemaFacet? o) 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 @@ private void Write31_XmlSchemaAttributeGroup(XmlSchemaAttributeGroup? o) 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 @@ private void Write32_XmlSchemaAttributeGroupRef(XmlSchemaAttributeGroupRef? o) 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 @@ private void Write33_XmlSchemaAnyAttribute(XmlSchemaAnyAttribute? o) 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 @@ private void Write35_XmlSchemaComplexType(XmlSchemaComplexType o) 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 @@ private void Write36_XmlSchemaSimpleContent(XmlSchemaSimpleContent? o) 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 @@ private void Write38_XmlSchemaSimpleContentExtension(XmlSchemaSimpleContentExten 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 @@ private void Write40_XmlSchemaSimpleContentRestriction(XmlSchemaSimpleContentRes 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 @@ private void Write41_XmlSchemaComplexContent(XmlSchemaComplexContent? o) 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 @@ private void Write42_XmlSchemaComplexContentExtension(XmlSchemaComplexContentExt 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 @@ private void Write43_XmlSchemaAll(XmlSchemaAll o) 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 @@ private void Write46_XmlSchemaElement(XmlSchemaElement? o) 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 @@ private void Write47_XmlSchemaKey(XmlSchemaKey? o) 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 @@ private void Write48_XmlSchemaIdentityConstraint(XmlSchemaIdentityConstraint? o) 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 @@ private void Write49_XmlSchemaXPath(string name, string ns, XmlSchemaXPath? o) 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 @@ private void Write50_XmlSchemaKeyref(XmlSchemaKeyref? o) 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 @@ private void Write51_XmlSchemaUnique(XmlSchemaUnique? o) 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 @@ private void Write52_XmlSchemaChoice(XmlSchemaChoice? o) 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 @@ private void Write53_XmlSchemaAny(XmlSchemaAny? o) 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 @@ private void Write54_XmlSchemaSequence(XmlSchemaSequence? o) 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 @@ private void Write55_XmlSchemaGroupRef(XmlSchemaGroupRef? o) 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 @@ private void Write56_XmlSchemaComplexContentRestriction(XmlSchemaComplexContentR private void Write57_XmlSchemaGroup(XmlSchemaGroup? o) { - if ((object?)o == null) return; + if (o is null) return; WriteStartElement("group"); WriteAttribute(@"id", @"", ((string?)o.@Id)); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs index 967218a452deb..7b70029ddcbee 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/SourceInfo.cs @@ -233,16 +233,16 @@ public static implicit operator string(SourceInfo source) 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) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs index 30035fe8b4aa2..702388f4581f4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlReflectionImporter.cs @@ -438,7 +438,7 @@ private TypeMapping ImportTypeMapping(TypeModel model, string? ns, ImportContext // 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 @@ private TypeMapping ImportTypeMapping(TypeModel model, string? ns, ImportContext 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 @@ internal void SetBase(SerializableMapping mapping, XmlQualifiedName baseQname) } 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 @@ private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, Xml { 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 @@ private void ImportAccessorMapping(MemberMapping accessor, FieldModel model, Xml { 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 @@ private void CheckAmbiguousChoice(XmlAttributes a, Type accessorType, string acc 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 @@ private void CheckAmbiguousChoice(XmlAttributes a, Type accessorType, string acc 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 @@ private void CheckAmbiguousChoice(XmlAttributes a, Type accessorType, string acc 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 { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs index fa90a9afe0b66..471c66877244d 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationReader.cs @@ -1346,7 +1346,7 @@ protected Exception CreateBadDerivationException(string? xsdDerived, string? nsD 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}'. } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs index 6ff8642c2d5c4..3bfdd36d5005c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlQualifiedName.cs @@ -110,7 +110,7 @@ public override bool Equals(object? other) 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; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs index 413c51abab936..12bda6fd43356 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/QIL/QilName.cs @@ -111,7 +111,7 @@ public override bool Equals(object? other) { return true; } - if ((object?)a == null || (object?)b == null) + if (a is null || b is null) { return false; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs index b8a9c6c51d2ea..0883d4d5846aa 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XmlQueryType.cs @@ -229,8 +229,8 @@ public bool Equals(XmlQueryType? that) /// 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 @@ public bool Equals(XmlQueryType? that) /// 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); } diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/RoAssemblyName.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/RoAssemblyName.cs index 3eb13856a1633..46b34719d6f44 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/RoAssemblyName.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/RoAssemblyName.cs @@ -51,7 +51,7 @@ public RoAssemblyName(string? name, Version? version, string? cultureName, byte[ // 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) diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs index 3b796281f5090..90ad6fe9a48ce 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSAEncryptionPadding.cs @@ -102,16 +102,16 @@ public override bool Equals(object? obj) 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); diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs index b69062b8f54cd..de0f413440d25 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSASignaturePadding.cs @@ -61,14 +61,14 @@ public override bool Equals(object? obj) 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); diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithm.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithm.cs index 8237d88dc860f..4b09c9756d5a1 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithm.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithm.cs @@ -37,9 +37,9 @@ public string Algorithm 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 @@ public string Algorithm 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 @@ public override bool Equals(object? obj) public bool Equals(CngAlgorithm? other) { - if (object.ReferenceEquals(other, null)) + if (other is null) { return false; } diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithmGroup.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithmGroup.cs index e98a8485704d6..b5c45227b9010 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithmGroup.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngAlgorithmGroup.cs @@ -38,9 +38,9 @@ public string AlgorithmGroup 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 @@ public string AlgorithmGroup 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 @@ public override bool Equals(object? obj) public bool Equals(CngAlgorithmGroup? other) { - if (object.ReferenceEquals(other, null)) + if (other is null) { return false; } diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKeyBlobFormat.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKeyBlobFormat.cs index 126597a0095a3..3165a4d9820a3 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKeyBlobFormat.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKeyBlobFormat.cs @@ -38,9 +38,9 @@ public string Format 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 @@ public string Format 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 @@ public override bool Equals(object? obj) public bool Equals(CngKeyBlobFormat? other) { - if (object.ReferenceEquals(other, null)) + if (other is null) { return false; } diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs index e990a1cbd9b97..3547b0f429ae9 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngProvider.cs @@ -37,17 +37,17 @@ public string Provider 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 @@ public override bool Equals(object? obj) public bool Equals(CngProvider? other) { - if (object.ReferenceEquals(other, null)) + if (other is null) { return false; } diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs index d724958c2c163..47d67ae2ae6b0 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs @@ -1081,7 +1081,7 @@ public static int ObjToHashAlgId(object hashAlg) else { Type? hashAlgType = hashAlg as Type; - if ((object?)hashAlgType != null) + if (hashAlgType is not null) { if (typeof(MD5).IsAssignableFrom(hashAlgType)) return CapiHelper.CALG_MD5; diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs index 420b33f4f4f0d..779ef830f6f47 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs @@ -403,7 +403,6 @@ private static bool FilterApplyBase( 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 @@ private static bool FilterApplyMethodBase( 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 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr) { 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; diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 8b0cd0a42480d..14c6dbefb1f7e 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -268,7 +268,7 @@ public override bool Equals(object obj) 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); }