From 9524bb599ea231fee1f9e233cb1a71850289ea57 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Mon, 11 Nov 2019 18:49:48 -0500 Subject: [PATCH] Fix StyleCop rule SA1129 ("Do not use default value type constructor") (dotnet/corefx#42531) Commit migrated from https://github.com/dotnet/corefx/commit/88f40addc220c73794f962f10d288c20c416ede1 --- .../Common/src/Interop/FreeBSD/Interop.Process.cs | 2 +- .../Common/src/Interop/OSX/Interop.libproc.cs | 2 +- .../Interop.EcDsa.ImportExport.cs | 4 +-- .../Windows/Advapi32/Interop.LsaOpenPolicy.cs | 2 +- .../src/Interop/Windows/BCrypt/Interop.Blobs.cs | 2 +- .../NCrypt/Interop.NCryptDeriveKeyMaterial.cs | 14 ++++---- .../Interop/Windows/NtDll/Interop.RtlGetVersion.cs | 2 +- .../SChannel/Interop.Sec_Application_Protocols.cs | 2 +- .../Windows/SspiCli/SSPISecureChannelType.cs | 2 +- .../Interop/Windows/SspiCli/SafeDeleteContext.cs | 2 +- .../Interop/Windows/SspiCli/SecuritySafeHandles.cs | 2 +- .../src/System/IO/FileSystem.Attributes.Windows.cs | 6 ++-- .../Common/src/System/Net/LazyAsyncResult.cs | 2 +- .../HostInformationPal.Windows.cs | 2 +- .../src/System/Net/WebSockets/ManagedWebSocket.cs | 2 +- .../Security/Cryptography/DSACng.ImportExport.cs | 2 +- .../Security/Cryptography/ECCng.ImportExport.cs | 6 ++-- .../ECDiffieHellmanCng.ImportExport.cs | 4 +-- .../Security/Cryptography/ECDsaCng.ImportExport.cs | 4 +-- .../Security/Cryptography/RSACng.ImportExport.cs | 2 +- .../CSharp/RuntimeBinder/Errors/ErrorHandling.cs | 2 +- .../src/Microsoft/Win32/SystemEvents.cs | 4 +-- .../Collections/Concurrent/BlockingCollection.cs | 12 +++---- .../System/Collections/Concurrent/ConcurrentBag.cs | 4 +-- .../Collections/Concurrent/ConcurrentStack.cs | 4 +-- .../Collections/Concurrent/PartitionerStatic.cs | 2 +- .../Immutable/ImmutableDictionary_2.HashBucket.cs | 2 +- .../Immutable/ImmutableHashSet_1.HashBucket.cs | 2 +- .../Composition/CompositionException.cs | 2 +- .../Composition/CompositionResult.cs | 2 +- .../Serialization/MemberRelationshipService.cs | 2 +- .../System/ComponentModel/MaskedTextProvider.cs | 2 +- .../Configuration/BaseConfigurationRecord.cs | 2 +- .../System/Configuration/OverrideModeSetting.cs | 4 +-- .../src/System/Configuration/SectionInformation.cs | 4 +-- .../src/System/ConsolePal.Windows.cs | 22 ++++++------ .../src/System/Data/Common/DbCommand.cs | 6 ++-- .../src/System/Data/Common/DbEnumerator.cs | 2 +- .../Data/Common/SQLTypes/SQLBinaryStorage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLByteStorage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLBytesStorage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLCharsStorage.cs | 2 +- .../Data/Common/SQLTypes/SQLDateTimeStorage.cs | 2 +- .../Data/Common/SQLTypes/SQLDecimalStorage.cs | 2 +- .../Data/Common/SQLTypes/SQLDoubleStorage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLGuidStorage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLInt16Storage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLInt32Storage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLInt64Storage.cs | 2 +- .../System/Data/Common/SQLTypes/SQLMoneyStorage.cs | 2 +- .../Data/Common/SQLTypes/SQLSingleStorage.cs | 2 +- .../Data/Common/SQLTypes/SQLStringStorage.cs | 2 +- .../Data/Common/SQLTypes/SQlBooleanStorage.cs | 2 +- .../System.Data.Common/src/System/Data/DataSet.cs | 4 +-- .../src/System/Data/DataTable.cs | 4 +-- .../System.Data.Common/src/System/Data/Select.cs | 2 +- .../src/System/Data/Selection.cs | 2 +- .../src/Interop/SNINativeMethodWrapper.Windows.cs | 4 +-- .../SqlServer/Server/SmiMetaDataProperty.cs | 2 +- .../src/System/Data/SqlClient/SqlBulkCopy.cs | 2 +- .../src/System/Data/SqlClient/SqlCommand.cs | 6 ++-- .../src/System/Data/SqlClient/SqlConnection.cs | 2 +- .../src/System/Data/SqlClient/SqlEnums.cs | 2 +- .../src/System/Data/SqlClient/TdsParser.Windows.cs | 2 +- .../src/System/Data/SqlClient/TdsParser.cs | 2 +- .../System/Data/SqlClient/TdsParserStateObject.cs | 2 +- .../Data/SqlClient/TdsParserStateObjectNative.cs | 2 +- .../src/System/Diagnostics/EventLogInternal.cs | 2 +- .../System/Diagnostics/Reader/EventLogSession.cs | 2 +- .../src/System/Diagnostics/Reader/NativeWrapper.cs | 2 +- .../System/Diagnostics/FileVersionInfo.Windows.cs | 2 +- .../System/Diagnostics/CounterSampleCalculator.cs | 6 ++-- .../System/Diagnostics/SharedPerformanceCounter.cs | 4 +-- .../src/System/Diagnostics/Process.Windows.cs | 8 ++--- .../src/System/Diagnostics/ProcessManager.Win32.cs | 2 +- .../System/Diagnostics/ProcessManager.Windows.cs | 2 +- .../AccountManagement/AuthZSet.cs | 2 +- .../DirectoryServices/AccountManagement/Context.cs | 2 +- .../AccountManagement/interopt.cs | 4 +-- .../Protocols/ldap/LdapSessionOptions.cs | 2 +- .../ActiveDirectory/UnsafeNativeMethods.cs | 2 +- .../src/System/DirectoryServices/DirectoryEntry.cs | 2 +- .../System/DirectoryServices/DirectorySearcher.cs | 40 +++++++++++----------- .../DirectoryServices/SearchResultCollection.cs | 6 ++-- .../Drawing/BufferedGraphicsContext.Windows.cs | 2 +- .../System/Drawing/Drawing2D/GraphicsPath.Unix.cs | 4 +-- .../src/System/Drawing/Font.Unix.cs | 2 +- .../src/System/Drawing/Font.Windows.cs | 4 +-- .../src/System/Drawing/Font.cs | 2 +- .../src/System/Drawing/GdiplusNative.cs | 2 +- .../src/System/Drawing/Graphics.Unix.cs | 2 +- .../src/System/Drawing/Graphics.cs | 6 ++-- .../src/System/Drawing/Icon.Unix.cs | 4 +-- .../src/System/Drawing/Icon.Windows.cs | 8 ++--- .../src/System/Drawing/Image.Unix.cs | 6 ++-- .../src/System/Drawing/Image.cs | 2 +- .../src/System/Drawing/ImageAnimator.Windows.cs | 4 +-- .../src/System/Drawing/Imaging/ColorMap.cs | 2 -- .../src/System/Drawing/Imaging/ImageAttributes.cs | 2 +- .../src/System/Drawing/Imaging/Metafile.Unix.cs | 6 ++-- .../System/Drawing/Imaging/MetafileHeader.Unix.cs | 2 +- .../Drawing/Printing/PageSettings.Windows.cs | 2 +- .../Drawing/Printing/PrintingServices.Unix.cs | 2 +- .../src/System/Drawing/SystemFonts.Windows.cs | 2 +- .../src/System/Drawing/macFunctions.cs | 6 ++-- .../src/misc/GDI/DeviceContext.cs | 2 +- .../src/misc/GDI/WindowsRegion.cs | 2 +- .../src/System/Drawing/Color.cs | 2 +- .../src/System/Drawing/Point.cs | 2 +- .../src/System/Drawing/PointF.cs | 2 +- .../src/System/Drawing/Rectangle.cs | 2 +- .../src/System/Drawing/RectangleF.cs | 2 +- .../src/System/Drawing/Size.cs | 2 +- .../src/System/Drawing/SizeF.cs | 2 +- .../IO/Compression/DeflateZLib/ZLibNative.cs | 1 - .../src/System/IO/Compression/ZipArchiveEntry.cs | 4 +-- .../src/System/IO/Compression/ZipBlocks.cs | 16 ++++----- .../IO/Enumeration/FileSystemEnumerator.Windows.cs | 2 +- .../src/System/IO/FileSystem.Windows.cs | 10 +++--- .../src/System/IO/FileSystemInfo.Windows.cs | 2 +- .../MemoryMappedFiles/MemoryMappedFile.Windows.cs | 2 +- .../MemoryMappedFiles/MemoryMappedView.Windows.cs | 6 ++-- .../src/System/IO/Pipelines/Pipe.cs | 2 +- .../src/System/IO/Pipelines/StreamPipeReader.cs | 4 +-- .../src/System/IO/Pipelines/StreamPipeWriter.cs | 2 +- .../IO/Pipes/AnonymousPipeServerStream.Windows.cs | 2 +- .../src/System/IO/Pipes/NamedPipeClientStream.cs | 2 +- .../IO/Pipes/NamedPipeServerStream.Windows.cs | 2 +- .../src/System/IO/Pipes/PipeStream.Windows.cs | 2 +- .../src/System/IO/Ports/SerialStream.Unix.cs | 2 +- .../src/System/IO/Ports/SerialStream.Windows.cs | 6 ++-- .../Linq/Expressions/Interpreter/Utilities.cs | 2 +- .../Linq/Parallel/QueryOperators/QuerySettings.cs | 2 +- .../System/Linq/Parallel/Scheduling/QueryTask.cs | 2 +- .../System.Linq/src/System/Linq/Concat.SpeedOpt.cs | 2 +- .../src/System/Linq/SelectMany.SpeedOpt.cs | 2 +- .../System/Net/Http/WinHttpCertificateHelper.cs | 6 ++-- .../src/System/Net/Http/WinHttpHandler.cs | 2 +- .../src/System/Net/Http/WinInetProxyHelper.cs | 2 +- .../Net/Http/SocketsHttpHandler/ConnectHelper.cs | 2 +- .../Http/SocketsHttpHandler/FailedProxyCache.cs | 2 +- .../Http/SocketsHttpHandler/HttpWindowsProxy.cs | 2 +- .../System/Net/Http/SocketsHttpHandler/MacProxy.cs | 2 +- .../src/System/Net/Windows/HttpListener.Windows.cs | 17 +++++---- .../Net/Windows/HttpListenerRequest.Windows.cs | 2 +- .../Net/Windows/HttpListenerResponse.Windows.cs | 4 +-- .../Net/Windows/HttpResponseStream.Windows.cs | 4 +-- .../Net/Windows/HttpResponseStreamAsyncResult.cs | 8 ++--- .../System/Net/Windows/WebSockets/WebSocketBase.cs | 4 +-- .../WebSocketHttpListenerDuplexStream.cs | 12 +++---- .../src/System/Net/Mail/SmtpReplyReaderFactory.cs | 4 +-- .../NetworkInformation/NetworkAddressChange.OSX.cs | 2 +- .../NetworkInformation/SystemIPGlobalStatistics.cs | 2 +- .../SystemIPInterfaceStatistics.cs | 2 +- .../System/Net/CertificateValidationPal.Windows.cs | 2 +- .../ReceiveMessageOverlappedAsyncResult.Windows.cs | 2 +- .../src/System/Net/Sockets/SafeSocketHandle.cs | 2 +- .../System/Net/Sockets/SocketAsyncContext.Unix.cs | 2 +- .../Net/Sockets/SocketAsyncEventArgs.Windows.cs | 4 +-- .../src/System/Net/Sockets/SocketPal.Unix.cs | 2 +- .../src/System/Net/Sockets/SocketPal.Windows.cs | 16 ++++----- .../XmlObjectSerializerReadContextComplexJson.cs | 4 +-- .../XmlObjectSerializerWriteContextComplexJson.cs | 4 +-- .../Serialization/XmlObjectSerializerContext.cs | 4 +-- .../XmlObjectSerializerWriteContext.cs | 2 +- src/libraries/System.Private.Uri/src/System/Uri.cs | 2 +- .../src/System/Xml/Linq/XContainer.cs | 4 +-- .../src/System/Xml/Linq/XElement.cs | 2 +- .../src/System/Xml/Linq/XLinq.cs | 4 +-- .../src/System/Xml/XPath/XNodeNavigator.cs | 4 +-- .../src/System/Xml/Schema/ContentValidator.cs | 6 ++-- .../src/System/Xml/Schema/XmlSchemaSet.cs | 2 +- .../src/System/Xml/Schema/XsdDateTime.cs | 6 ++-- .../src/System/Xml/Schema/XsdDuration.cs | 2 +- .../Xml/Serialization/XmlSerializationReader.cs | 4 +-- .../src/System/Xml/Serialization/XmlSerializer.cs | 2 +- .../src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs | 12 +++---- .../System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs | 2 +- .../src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs | 8 ++--- .../src/System/Xml/Xsl/Runtime/TreeIterators.cs | 4 +-- .../src/System/Xml/Xsl/Runtime/XmlCollation.cs | 2 +- .../src/System/Xml/Xsl/Xslt/QilGenerator.cs | 2 +- .../src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs | 4 +-- .../src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs | 2 +- .../src/System/Xml/Xsl/Xslt/XsltInput.cs | 2 +- .../Utilities/ImmutableByteArrayInterop.cs | 4 +-- .../Modules/Ecma/EcmaModule.ManifestResources.cs | 2 +- .../TypeLoading/RuntimeTypeInfo.BindingFlags.cs | 6 ++-- .../Globalization/FormatProvider.BigInteger.cs | 4 +-- .../src/System/Numerics/BigNumber.cs | 2 +- .../src/System/Windows/Duration.cs | 4 +-- .../src/System/Windows/Media/Animation/KeyTime.cs | 2 +- .../Windows/Media/Animation/RepeatBehavior.cs | 2 +- .../src/System/Windows/Media/Matrix.cs | 2 +- .../src/System/Windows/Media/Media3D/Matrix3D.cs | 4 +-- .../src/System/Windows/Rect.cs | 2 +- .../src/System/Windows/Size.cs | 2 +- .../src/System/Windows/UI/Color.cs | 2 +- .../src/System/Security/AccessControl/Privilege.cs | 2 +- .../src/System/Security/Cryptography/CngKeyLite.cs | 2 +- .../src/System/Security/Cryptography/ECCurve.cs | 2 +- .../Cryptography/ECDiffieHellmanCngPublicKey.cs | 4 +-- .../System/Security/Cryptography/CngKey.Export.cs | 2 +- .../Cryptography/ECDiffieHellmanCngPublicKey.cs | 4 +-- .../Security/Cryptography/CapiHelper.DSA.Shared.cs | 2 +- .../Security/Cryptography/CapiHelper.Shared.cs | 2 +- .../Cryptography/Pal/AnyOS/ManagedPal.KeyTrans.cs | 2 +- .../System/Security/Cryptography/Pkcs/CmsSigner.cs | 4 +-- .../Pal.Unix/ManagedX509ExtensionProcessor.cs | 4 +-- .../Pal.Windows/CertificatePal.PrivateKey.cs | 4 +-- .../Cryptography/Pal.Windows/CertificatePal.cs | 2 +- .../Pal.Windows/ChainPal.BuildChain.cs | 4 +-- .../Internal/Cryptography/Pal.Windows/ChainPal.cs | 4 +-- .../Cryptography/Pal.Windows/X509Pal.PublicKey.cs | 2 +- .../Pkcs10CertificationRequestInfo.cs | 2 +- .../src/System/Security/Principal/Win32.cs | 2 +- .../ServiceModel/Syndication/CategoriesDocument.cs | 2 +- .../Syndication/ResourceCollectionInfo.cs | 2 +- .../ServiceModel/Syndication/ServiceDocument.cs | 2 +- .../Syndication/SyndicationCategory.cs | 2 +- .../ServiceModel/Syndication/SyndicationFeed.cs | 2 +- .../ServiceModel/Syndication/SyndicationItem.cs | 2 +- .../ServiceModel/Syndication/SyndicationLink.cs | 2 +- .../ServiceModel/Syndication/SyndicationPerson.cs | 2 +- .../System/ServiceModel/Syndication/Workspace.cs | 2 +- .../src/System/ServiceProcess/ServiceBase.cs | 2 +- .../src/System/ServiceProcess/ServiceController.cs | 12 +++---- .../src/System/Text/Json/JsonHelpers.Date.cs | 5 ++- .../src/Internal/ConcurrentQueue.cs | 18 +++++----- .../src/System/Threading/Tasks/Parallel.cs | 6 ++-- .../System/Threading/Tasks/ParallelLoopState.cs | 6 ++-- .../src/System/Threading/Barrier.cs | 14 ++++---- .../src/System/Threading/CountdownEvent.cs | 10 +++--- .../src/System/Threading/ReaderWriterLock.cs | 4 +-- .../Transactions/EnlistmentTraceIdentifier.cs | 2 +- .../src/System/Transactions/TransactionState.cs | 2 +- .../Transactions/TransactionTraceIdentifier.cs | 2 +- .../src/System/Drawing/FontConverter.cs | 2 +- 238 files changed, 428 insertions(+), 433 deletions(-) diff --git a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs index 5713ab2..056a893 100644 --- a/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs +++ b/src/libraries/Common/src/Interop/FreeBSD/Interop.Process.cs @@ -396,7 +396,7 @@ internal static partial class Interop /// public static unsafe proc_stats GetThreadInfo(int pid, int tid) { - proc_stats ret = new proc_stats(); + proc_stats ret = default; kinfo_proc* info = null; int count; diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs index e3b9376..6775b4d 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.libproc.cs @@ -473,7 +473,7 @@ internal static partial class Interop throw new ArgumentOutOfRangeException(nameof(pid), SR.NegativePidNotSupported); } - rusage_info_v3 info = new rusage_info_v3(); + rusage_info_v3 info = default; // Get the PIDs rusage info int result = proc_pid_rusage(pid, RUSAGE_INFO_V3, &info); diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs index bf24309..5780184 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.EcDsa.ImportExport.cs @@ -113,7 +113,7 @@ internal static partial class Interop SafeBignumHandle qx_bn, qy_bn, d_bn; IntPtr d_bn_not_owned; int qx_cb, qy_cb, d_cb; - ECParameters parameters = new ECParameters(); + ECParameters parameters = default; bool refAdded = false; try @@ -254,7 +254,7 @@ internal static partial class Interop int cbSubgroupOrder = GetMax(order_cb, d_cb); // Copy values to ECParameters - ECParameters parameters = new ECParameters(); + ECParameters parameters = default; parameters.Q = new ECPoint { X = Crypto.ExtractBignum(qx_bn, cbFieldLength), diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaOpenPolicy.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaOpenPolicy.cs index 4360f33..de5da0c 100644 --- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaOpenPolicy.cs +++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaOpenPolicy.cs @@ -24,7 +24,7 @@ internal static partial class Interop int AccessMask, out SafeLsaPolicyHandle PolicyHandle) { - var systemNameUnicode = new UNICODE_STRING(); + UNICODE_STRING systemNameUnicode = default; if (SystemName != null) { fixed (char* c = SystemName) diff --git a/src/libraries/Common/src/Interop/Windows/BCrypt/Interop.Blobs.cs b/src/libraries/Common/src/Interop/Windows/BCrypt/Interop.Blobs.cs index 90981ab..dc688b0 100644 --- a/src/libraries/Common/src/Interop/Windows/BCrypt/Interop.Blobs.cs +++ b/src/libraries/Common/src/Interop/Windows/BCrypt/Interop.Blobs.cs @@ -302,7 +302,7 @@ internal partial class Interop public static BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO Create() { - BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO ret = new BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO(); + BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO ret = default; ret.cbSize = sizeof(BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO); diff --git a/src/libraries/Common/src/Interop/Windows/NCrypt/Interop.NCryptDeriveKeyMaterial.cs b/src/libraries/Common/src/Interop/Windows/NCrypt/Interop.NCryptDeriveKeyMaterial.cs index 2485e1d..1aebafb 100644 --- a/src/libraries/Common/src/Interop/Windows/NCrypt/Interop.NCryptDeriveKeyMaterial.cs +++ b/src/libraries/Common/src/Interop/Windows/NCrypt/Interop.NCryptDeriveKeyMaterial.cs @@ -49,7 +49,7 @@ internal static partial class Interop Span parameters = stackalloc NCryptBuffer[4]; int parameterCount = 0; // We always need to marshal the hashing function - NCryptBuffer hashAlgorithmBuffer = new NCryptBuffer(); + NCryptBuffer hashAlgorithmBuffer = default; hashAlgorithmBuffer.cbBuffer = (hashAlgorithm.Length + 1) * sizeof(char); hashAlgorithmBuffer.BufferType = BufferType.KdfHashAlgorithm; hashAlgorithmBuffer.pvBuffer = hashAlgorithmString; @@ -67,7 +67,7 @@ internal static partial class Interop if (pHmacKey != null) { - NCryptBuffer hmacKeyBuffer = new NCryptBuffer(); + NCryptBuffer hmacKeyBuffer = default; hmacKeyBuffer.cbBuffer = hmacKey.Length; hmacKeyBuffer.BufferType = BufferType.KdfHmacKey; hmacKeyBuffer.pvBuffer = new IntPtr(pHmacKey); @@ -78,7 +78,7 @@ internal static partial class Interop if (pSecretPrepend != null) { - NCryptBuffer secretPrependBuffer = new NCryptBuffer(); + NCryptBuffer secretPrependBuffer = default; secretPrependBuffer.cbBuffer = secretPrepend.Length; secretPrependBuffer.BufferType = BufferType.KdfSecretPrepend; secretPrependBuffer.pvBuffer = new IntPtr(pSecretPrepend); @@ -89,7 +89,7 @@ internal static partial class Interop if (pSecretAppend != null) { - NCryptBuffer secretAppendBuffer = new NCryptBuffer(); + NCryptBuffer secretAppendBuffer = default; secretAppendBuffer.cbBuffer = secretAppend.Length; secretAppendBuffer.BufferType = BufferType.KdfSecretAppend; secretAppendBuffer.pvBuffer = new IntPtr(pSecretAppend); @@ -126,7 +126,7 @@ internal static partial class Interop { fixed (NCryptBuffer* pParameters = &MemoryMarshal.GetReference(parameters)) { - NCryptBufferDesc parameterDesc = new NCryptBufferDesc(); + NCryptBufferDesc parameterDesc = default; parameterDesc.ulVersion = 0; parameterDesc.cBuffers = parameters.Length; parameterDesc.pBuffers = new IntPtr(pParameters); @@ -225,13 +225,13 @@ internal static partial class Interop { fixed (byte* pLabel = label, pSeed = seed) { - NCryptBuffer labelBuffer = new NCryptBuffer(); + NCryptBuffer labelBuffer = default; labelBuffer.cbBuffer = label.Length; labelBuffer.BufferType = BufferType.KdfTlsLabel; labelBuffer.pvBuffer = new IntPtr(pLabel); buffers[0] = labelBuffer; - NCryptBuffer seedBuffer = new NCryptBuffer(); + NCryptBuffer seedBuffer = default; seedBuffer.cbBuffer = seed.Length; seedBuffer.BufferType = BufferType.KdfTlsSeed; seedBuffer.pvBuffer = new IntPtr(pSeed); diff --git a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.RtlGetVersion.cs b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.RtlGetVersion.cs index e3e5209..17f0521 100644 --- a/src/libraries/Common/src/Interop/Windows/NtDll/Interop.RtlGetVersion.cs +++ b/src/libraries/Common/src/Interop/Windows/NtDll/Interop.RtlGetVersion.cs @@ -13,7 +13,7 @@ internal partial class Interop internal static unsafe int RtlGetVersionEx(out RTL_OSVERSIONINFOEX osvi) { - osvi = new RTL_OSVERSIONINFOEX(); + osvi = default; osvi.dwOSVersionInfoSize = (uint)sizeof(RTL_OSVERSIONINFOEX); return RtlGetVersion(ref osvi); } diff --git a/src/libraries/Common/src/Interop/Windows/SChannel/Interop.Sec_Application_Protocols.cs b/src/libraries/Common/src/Interop/Windows/SChannel/Interop.Sec_Application_Protocols.cs index ff2aec1..08407d6 100644 --- a/src/libraries/Common/src/Interop/Windows/SChannel/Interop.Sec_Application_Protocols.cs +++ b/src/libraries/Common/src/Interop/Windows/SChannel/Interop.Sec_Application_Protocols.cs @@ -37,7 +37,7 @@ internal static partial class Interop } } - Sec_Application_Protocols protocols = new Sec_Application_Protocols(); + Sec_Application_Protocols protocols = default; int protocolListConstSize = sizeof(Sec_Application_Protocols) - sizeof(uint) /* offsetof(Sec_Application_Protocols, ProtocolExtensionType) */; protocols.ProtocolListsSize = (uint)(protocolListConstSize + protocolListSize); diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.cs index 134f736..13e32d4 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/SSPISecureChannelType.cs @@ -99,7 +99,7 @@ namespace System.Net refHandle = SafeFreeContextBufferChannelBinding.CreateEmptyHandle(); // Bindings is on the stack, so there's no need for a fixed block. - SecPkgContext_Bindings bindings = new SecPkgContext_Bindings(); + SecPkgContext_Bindings bindings = default; return SafeFreeContextBufferChannelBinding.QueryContextChannelBinding(phContext, attribute, &bindings, refHandle); } diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/SafeDeleteContext.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/SafeDeleteContext.cs index fd49dbe..d593155 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/SafeDeleteContext.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/SafeDeleteContext.cs @@ -29,7 +29,7 @@ namespace System.Net.Security protected SafeDeleteContext() : base(IntPtr.Zero, true) { - _handle = new Interop.SspiCli.CredHandle(); + _handle = default; } public override bool IsInvalid diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs index 8182e41..a32c0d4 100644 --- a/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs +++ b/src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs @@ -178,7 +178,7 @@ namespace System.Net.Security protected SafeFreeCredentials() : base(IntPtr.Zero, true) { - _handle = new Interop.SspiCli.CredHandle(); + _handle = default; } #if TRACE_VERBOSE diff --git a/src/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs b/src/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs index 4167fc5..be7ddee 100644 --- a/src/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs +++ b/src/libraries/Common/src/System/IO/FileSystem.Attributes.Windows.cs @@ -25,7 +25,7 @@ namespace System.IO private static bool DirectoryExists(string path, out int lastError) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; lastError = FillAttributeInfo(path, ref data, returnErrorOnNotFound: true); return @@ -36,7 +36,7 @@ namespace System.IO public static bool FileExists(string fullPath) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: true); return @@ -96,7 +96,7 @@ namespace System.IO // pagefile.sys case. As such we're probably stuck filtering out specific // cases that we know we don't want to retry on. - var findData = new Interop.Kernel32.WIN32_FIND_DATA(); + Interop.Kernel32.WIN32_FIND_DATA findData = default; using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(path, ref findData)) { if (handle.IsInvalid) diff --git a/src/libraries/Common/src/System/Net/LazyAsyncResult.cs b/src/libraries/Common/src/System/Net/LazyAsyncResult.cs index 17b6af0..54847f7 100644 --- a/src/libraries/Common/src/System/Net/LazyAsyncResult.cs +++ b/src/libraries/Common/src/System/Net/LazyAsyncResult.cs @@ -491,7 +491,7 @@ namespace System.Net // can benefit from the synchronization of _intCompleted). That means you can get here before _result got // set (although rarely - once every eight hours of stress). Handle that case with a spin-lock. - SpinWait sw = new SpinWait(); + SpinWait sw = default; while (_result == DBNull.Value) { sw.SpinOnce(); diff --git a/src/libraries/Common/src/System/Net/NetworkInformation/HostInformationPal.Windows.cs b/src/libraries/Common/src/System/Net/NetworkInformation/HostInformationPal.Windows.cs index 1e7b308..b81de34 100644 --- a/src/libraries/Common/src/System/Net/NetworkInformation/HostInformationPal.Windows.cs +++ b/src/libraries/Common/src/System/Net/NetworkInformation/HostInformationPal.Windows.cs @@ -34,7 +34,7 @@ namespace System.Net.NetworkInformation { uint size = 0; SafeLocalAllocHandle buffer = null; - Interop.IpHlpApi.FIXED_INFO fixedInfo = new Interop.IpHlpApi.FIXED_INFO(); + Interop.IpHlpApi.FIXED_INFO fixedInfo = default; // First we need to get the size of the buffer uint result = Interop.IpHlpApi.GetNetworkParams(SafeLocalAllocHandle.InvalidHandle, ref size); diff --git a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs index a900ed9..1e9485b 100644 --- a/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs +++ b/src/libraries/Common/src/System/Net/WebSockets/ManagedWebSocket.cs @@ -972,7 +972,7 @@ namespace System.Net.WebSockets { Debug.Assert(_receiveBufferCount >= 2, $"Expected to at least have the first two bytes of the header."); - var header = new MessageHeader(); + MessageHeader header = default; Span receiveBufferSpan = _receiveBuffer.Span; header.Fin = (receiveBufferSpan[_receiveBufferOffset] & 0x80) != 0; diff --git a/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs b/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs index 2147bb4..3f7a4ac 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/DSACng.ImportExport.cs @@ -337,7 +337,7 @@ namespace System.Security.Cryptography unsafe { - DSAParameters dsaParams = new DSAParameters(); + DSAParameters dsaParams = default; fixed (byte* pDsaBlob = dsaBlob) { diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECCng.ImportExport.cs b/src/libraries/Common/src/System/Security/Cryptography/ECCng.ImportExport.cs index 8f61160..f1e98f9 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECCng.ImportExport.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECCng.ImportExport.cs @@ -226,7 +226,7 @@ namespace System.Security.Cryptography { BCRYPT_ECCFULLKEY_BLOB* pBcryptBlob = (BCRYPT_ECCFULLKEY_BLOB*)pEcBlob; - var primeCurve = new ECCurve(); + ECCurve primeCurve = default; primeCurve.CurveType = ConvertToCurveTypeEnum(pBcryptBlob->CurveType); primeCurve.Hash = GetHashAlgorithmName(pBcryptBlob->CurveGenerationAlgId); @@ -467,8 +467,8 @@ namespace System.Security.Cryptography using (SafeUnicodeStringHandle safeCurveName = new SafeUnicodeStringHandle(curveName)) { - var desc = new Interop.BCrypt.BCryptBufferDesc(); - var buff = new Interop.BCrypt.BCryptBuffer(); + Interop.BCrypt.BCryptBufferDesc desc = default; + Interop.BCrypt.BCryptBuffer buff = default; IntPtr descPtr = IntPtr.Zero; IntPtr buffPtr = IntPtr.Zero; diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.ImportExport.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.ImportExport.cs index 8f0e745..ce4dae3 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.ImportExport.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanCng.ImportExport.cs @@ -50,7 +50,7 @@ namespace System.Security.Cryptography try { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters); return ecparams; } @@ -62,7 +62,7 @@ namespace System.Security.Cryptography public override ECParameters ExportParameters(bool includePrivateParameters) { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; string curveName = GetCurveName(out string oidValue); byte[] blob = null; diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.ImportExport.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.ImportExport.cs index 0e4c31a..03814d8 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.ImportExport.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECDsaCng.ImportExport.cs @@ -68,7 +68,7 @@ namespace System.Security.Cryptography public override ECParameters ExportExplicitParameters(bool includePrivateParameters) { byte[] blob = ExportFullKeyBlob(includePrivateParameters); - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters); return ecparams; } @@ -83,7 +83,7 @@ namespace System.Security.Cryptography /// The key and named curve parameters used by the ECC object. public override ECParameters ExportParameters(bool includePrivateParameters) { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; string curveName = GetCurveName(out string oidValue); diff --git a/src/libraries/Common/src/System/Security/Cryptography/RSACng.ImportExport.cs b/src/libraries/Common/src/System/Security/Cryptography/RSACng.ImportExport.cs index 4d72d68..79fe528 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/RSACng.ImportExport.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/RSACng.ImportExport.cs @@ -294,7 +294,7 @@ namespace System.Security.Cryptography public override RSAParameters ExportParameters(bool includePrivateParameters) { byte[] rsaBlob = ExportKeyBlob(includePrivateParameters); - RSAParameters rsaParams = new RSAParameters(); + RSAParameters rsaParams = default; ExportParameters(ref rsaParams, rsaBlob, includePrivateParameters); return rsaParams; } diff --git a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs index 2e9a9c6..e06cbc4 100644 --- a/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs +++ b/src/libraries/Microsoft.CSharp/src/Microsoft/CSharp/RuntimeBinder/Errors/ErrorHandling.cs @@ -21,7 +21,7 @@ namespace Microsoft.CSharp.RuntimeBinder.Errors int piarg = 0; int cargUnique = 0; - UserStringBuilder builder = new UserStringBuilder(); + UserStringBuilder builder = default; for (int iarg = 0; iarg < args.Length; iarg++) { diff --git a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs index a94dd3d..0dbec2d 100644 --- a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs +++ b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs @@ -87,7 +87,7 @@ namespace Microsoft.Win32 s_isUserInteractive = true; int lengthNeeded = 0; - Interop.User32.USEROBJECTFLAGS flags = new Interop.User32.USEROBJECTFLAGS(); + Interop.User32.USEROBJECTFLAGS flags = default; if (Interop.User32.GetUserObjectInformationW(hwinsta, Interop.User32.UOI_FLAGS, ref flags, sizeof(Interop.User32.USEROBJECTFLAGS), ref lengthNeeded)) { @@ -1267,7 +1267,7 @@ namespace Microsoft.Win32 if (_windowHandle != IntPtr.Zero) { - Interop.User32.MSG msg = new Interop.User32.MSG(); + Interop.User32.MSG msg = default(Interop.User32.MSG); bool keepRunning = true; diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs index 858fac6..6bebdc3 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/BlockingCollection.cs @@ -256,7 +256,7 @@ nameof(boundedCapacity), boundedCapacity, #if DEBUG bool tryAddReturnValue = #endif - TryAddWithNoTimeValidation(item, Timeout.Infinite, new CancellationToken()); + TryAddWithNoTimeValidation(item, Timeout.Infinite, CancellationToken.None); #if DEBUG Debug.Assert(tryAddReturnValue, "TryAdd() was expected to return true."); #endif @@ -305,7 +305,7 @@ nameof(boundedCapacity), boundedCapacity, /// The underlying collection didn't accept the item. public bool TryAdd(T item) { - return TryAddWithNoTimeValidation(item, 0, new CancellationToken()); + return TryAddWithNoTimeValidation(item, 0, CancellationToken.None); } /// @@ -329,7 +329,7 @@ nameof(boundedCapacity), boundedCapacity, public bool TryAdd(T item, TimeSpan timeout) { ValidateTimeout(timeout); - return TryAddWithNoTimeValidation(item, (int)timeout.TotalMilliseconds, new CancellationToken()); + return TryAddWithNoTimeValidation(item, (int)timeout.TotalMilliseconds, CancellationToken.None); } /// @@ -351,7 +351,7 @@ nameof(boundedCapacity), boundedCapacity, public bool TryAdd(T item, int millisecondsTimeout) { ValidateMillisecondsTimeout(millisecondsTimeout); - return TryAddWithNoTimeValidation(item, millisecondsTimeout, new CancellationToken()); + return TryAddWithNoTimeValidation(item, millisecondsTimeout, CancellationToken.None); } /// @@ -450,7 +450,7 @@ nameof(boundedCapacity), boundedCapacity, // spins until all adders finish then throw IOE // The idea behind to spin until all adders finish, is to avoid to return to the caller with IOE while there are still some adders have // not been finished yet - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (true) { int observedAdders = _currentAdders; @@ -1475,7 +1475,7 @@ nameof(boundedCapacity), boundedCapacity, if (IsAddingCompleted) return; - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (true) { int observedAdders = _currentAdders; diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs index c7549f6..430b955 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentBag.cs @@ -634,7 +634,7 @@ namespace System.Collections.Concurrent { if (queue._currentOp != (int)Operation.None) { - var spinner = new SpinWait(); + SpinWait spinner = default; do { spinner.SpinOnce(); } while (queue._currentOp != (int)Operation.None); } @@ -975,7 +975,7 @@ namespace System.Collections.Concurrent // steal operations happening at the time. if ((head - (_tailIndex - 2) >= 0) && _currentOp == (int)Operation.Add) { - var spinner = new SpinWait(); + SpinWait spinner = default; do { spinner.SpinOnce(); diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs index ceb5ad7..6d5ca3a 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/ConcurrentStack.cs @@ -379,7 +379,7 @@ namespace System.Collections.Concurrent /// The tail pointer to the new list private void PushCore(Node head, Node tail) { - SpinWait spin = new SpinWait(); + SpinWait spin = default; // Keep trying to CAS the existing head with the new node until we succeed. do @@ -600,7 +600,7 @@ namespace System.Collections.Concurrent /// the . private int TryPopCore(int count, out Node? poppedHead) { - SpinWait spin = new SpinWait(); + SpinWait spin = default; // Try to CAS the head with its current next. We stop when we succeed or // when we notice that the stack is empty, whichever comes first. diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs index fcf60ad..b6f9115 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs @@ -791,7 +791,7 @@ namespace System.Collections.Concurrent // we need to make sure all array copiers are finished if (_activeCopiers > 0) { - SpinWait sw = new SpinWait(); + SpinWait sw = default; while (_activeCopiers > 0) sw.SpinOnce(); } diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs index c3612ff..e5603ec 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableDictionary_2.HashBucket.cs @@ -227,7 +227,7 @@ namespace System.Collections.Immutable if (_additionalElements.IsEmpty) { result = OperationResult.SizeChanged; - return new HashBucket(); + return default; } else { diff --git a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs index d830c06..d4dd830 100644 --- a/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs +++ b/src/libraries/System.Collections.Immutable/src/System/Collections/Immutable/ImmutableHashSet_1.HashBucket.cs @@ -215,7 +215,7 @@ namespace System.Collections.Immutable if (_additionalElements.IsEmpty) { result = OperationResult.SizeChanged; - return new HashBucket(); + return default; } else { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs index cf5105c..aef115d 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionException.cs @@ -264,7 +264,7 @@ namespace System.ComponentModel.Composition { List> paths = new List>(); - VisitContext context = new VisitContext(); + VisitContext context = default; context.Path = new Stack(); context.LeafVisitor = path => { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResult.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResult.cs index b855f21..7f06572 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResult.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/CompositionResult.cs @@ -11,7 +11,7 @@ namespace System.ComponentModel.Composition { internal struct CompositionResult { - public static readonly CompositionResult SucceededResult = new CompositionResult(); + public static readonly CompositionResult SucceededResult; private readonly IEnumerable _errors; public CompositionResult(params CompositionError[] errors) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/MemberRelationshipService.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/MemberRelationshipService.cs index 98a4b87..3ea1fac 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/MemberRelationshipService.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/MemberRelationshipService.cs @@ -189,7 +189,7 @@ namespace System.ComponentModel.Design.Serialization /// public readonly struct MemberRelationship { - public static readonly MemberRelationship Empty = new MemberRelationship(); + public static readonly MemberRelationship Empty; /// /// Creates a new member relationship. diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs index 38c426b..bdfdfaa 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/MaskedTextProvider.cs @@ -244,7 +244,7 @@ namespace System.ComponentModel culture = CultureInfo.CurrentCulture; } - _flagState = new BitVector32(); + _flagState = default; // read only property-backend fields. diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs index 4a4013b..f6cc2e1 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/BaseConfigurationRecord.cs @@ -163,7 +163,7 @@ namespace System.Configuration internal BaseConfigurationRecord() { // not strictly necessary, but compiler spits out a warning without this initiailization - _flags = new SafeBitVector32(); + _flags = default; } protected abstract SimpleBitVector32 ClassFlags { get; } diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/OverrideModeSetting.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/OverrideModeSetting.cs index 79cb7bd..5f75185 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/OverrideModeSetting.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/OverrideModeSetting.cs @@ -38,7 +38,7 @@ namespace System.Configuration // The conversion is true -> OverrideMode.Inherit // The conversion is false -> OverrideMode.Deny // This is consistent with Whidbey where true means true unless there is a false somewhere above - OverrideModeSetting result = new OverrideModeSetting(); + OverrideModeSetting result = default; result.SetMode(allowOverride ? OverrideMode.Inherit : OverrideMode.Deny); result._mode |= XmlDefinedLegacy; @@ -48,7 +48,7 @@ namespace System.Configuration internal static OverrideModeSetting CreateFromXmlReadValue(OverrideMode mode) { - OverrideModeSetting result = new OverrideModeSetting(); + OverrideModeSetting result = default; result.SetMode(mode); result._mode |= XmlDefinedNewMode; diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SectionInformation.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SectionInformation.cs index ba72c52..a1a4f21 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SectionInformation.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/SectionInformation.cs @@ -62,7 +62,7 @@ namespace System.Configuration _flags[FlagInheritInChildApps] = true; _flags[FlagForceSave] = false; - _modifiedFlags = new SimpleBitVector32(); + _modifiedFlags = default; } private bool IsRuntime => _flags[FlagAttached] && @@ -403,7 +403,7 @@ namespace System.Configuration internal void ResetModifiedFlags() { - _modifiedFlags = new SimpleBitVector32(); + _modifiedFlags = default; } internal bool IsModifiedFlags() diff --git a/src/libraries/System.Console/src/System/ConsolePal.Windows.cs b/src/libraries/System.Console/src/System/ConsolePal.Windows.cs index ae87341..2097d22 100644 --- a/src/libraries/System.Console/src/System/ConsolePal.Windows.cs +++ b/src/libraries/System.Console/src/System/ConsolePal.Windows.cs @@ -263,7 +263,7 @@ namespace System if (_cachedInputRecord.eventType == Interop.KEY_EVENT) return true; - Interop.InputRecord ir = new Interop.InputRecord(); + Interop.InputRecord ir = default; int numEventsRead = 0; while (true) { @@ -706,8 +706,8 @@ namespace System Interop.Kernel32.CHAR_INFO[] data = new Interop.Kernel32.CHAR_INFO[sourceWidth * sourceHeight]; bufferSize.X = (short)sourceWidth; bufferSize.Y = (short)sourceHeight; - Interop.Kernel32.COORD bufferCoord = new Interop.Kernel32.COORD(); - Interop.Kernel32.SMALL_RECT readRegion = new Interop.Kernel32.SMALL_RECT(); + Interop.Kernel32.COORD bufferCoord = default; + Interop.Kernel32.SMALL_RECT readRegion = default; readRegion.Left = (short)sourceLeft; readRegion.Right = (short)(sourceLeft + sourceWidth - 1); readRegion.Top = (short)sourceTop; @@ -720,7 +720,7 @@ namespace System throw Win32Marshal.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); // Overwrite old section - Interop.Kernel32.COORD writeCoord = new Interop.Kernel32.COORD(); + Interop.Kernel32.COORD writeCoord = default; writeCoord.X = (short)sourceLeft; Interop.Kernel32.Color c = ConsoleColorToColorAttribute(sourceBackColor, true); c |= ConsoleColorToColorAttribute(sourceForeColor, false); @@ -740,7 +740,7 @@ namespace System } // Write text to new location - Interop.Kernel32.SMALL_RECT writeRegion = new Interop.Kernel32.SMALL_RECT(); + Interop.Kernel32.SMALL_RECT writeRegion = default; writeRegion.Left = (short)targetLeft; writeRegion.Right = (short)(targetLeft + sourceWidth); writeRegion.Top = (short)targetTop; @@ -752,7 +752,7 @@ namespace System public static void Clear() { - Interop.Kernel32.COORD coordScreen = new Interop.Kernel32.COORD(); + Interop.Kernel32.COORD coordScreen = default; Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO csbi; bool success; int conSize; @@ -793,7 +793,7 @@ namespace System public static void SetCursorPosition(int left, int top) { IntPtr hConsole = OutputHandle; - Interop.Kernel32.COORD coords = new Interop.Kernel32.COORD(); + Interop.Kernel32.COORD coords = default; coords.X = (short)left; coords.Y = (short)top; if (!Interop.Kernel32.SetConsoleCursorPosition(hConsole, coords)) @@ -846,7 +846,7 @@ namespace System if (height < srWindow.Bottom + 1 || height >= short.MaxValue) throw new ArgumentOutOfRangeException(nameof(height), height, SR.ArgumentOutOfRange_ConsoleBufferLessThanWindowSize); - Interop.Kernel32.COORD size = new Interop.Kernel32.COORD(); + Interop.Kernel32.COORD size = default; size.X = (short)width; size.Y = (short)height; if (!Interop.Kernel32.SetConsoleScreenBufferSize(OutputHandle, size)) @@ -969,7 +969,7 @@ namespace System // If the buffer is smaller than this new window size, resize the // buffer to be large enough. Include window position. bool resizeBuffer = false; - Interop.Kernel32.COORD size = new Interop.Kernel32.COORD(); + Interop.Kernel32.COORD size = default; size.X = csbi.dwSize.X; size.Y = csbi.dwSize.Y; if (csbi.dwSize.X < csbi.srWindow.Left + width) @@ -1062,7 +1062,7 @@ namespace System { throw new IOException(SR.IO_NoConsole); } - return new Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO(); + return default; } // Note that if stdout is redirected to a file, the console handle may be a file. @@ -1074,7 +1074,7 @@ namespace System { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Interop.Errors.ERROR_INVALID_HANDLE && !throwOnNoConsole) - return new Interop.Kernel32.CONSOLE_SCREEN_BUFFER_INFO(); + return default; throw Win32Marshal.GetExceptionForWin32Error(errorCode); } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbCommand.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbCommand.cs index 5dbaf7e..8aaf84a 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbCommand.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbCommand.cs @@ -125,7 +125,7 @@ namespace System.Data.Common } else { - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this); @@ -166,7 +166,7 @@ namespace System.Data.Common } else { - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this); @@ -198,7 +198,7 @@ namespace System.Data.Common } else { - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(s => ((DbCommand)s).CancelIgnoreFailure(), this); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbEnumerator.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbEnumerator.cs index 0d449c1..4974b15 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbEnumerator.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbEnumerator.cs @@ -95,7 +95,7 @@ namespace System.Data.Common PropertyDescriptor[] props = new PropertyDescriptor[_reader.FieldCount]; for (int i = 0; i < si.Length; i++) { - SchemaInfo s = new SchemaInfo(); + SchemaInfo s = default; s.name = _reader.GetName(i); s.type = _reader.GetFieldType(i); s.typeName = _reader.GetDataTypeName(i); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBinaryStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBinaryStorage.cs index c893cfc..41b02ac 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBinaryStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBinaryStorage.cs @@ -100,7 +100,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlBinary newValue = new SqlBinary(); + SqlBinary newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLByteStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLByteStorage.cs index 17f7eea..7855a0c 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLByteStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLByteStorage.cs @@ -210,7 +210,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlByte newValue = new SqlByte(); + SqlByte newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBytesStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBytesStorage.cs index 8a64b95..44914df 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBytesStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLBytesStorage.cs @@ -99,7 +99,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlBinary newValue = new SqlBinary(); + SqlBinary newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLCharsStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLCharsStorage.cs index 893c948..d318ab1 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLCharsStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLCharsStorage.cs @@ -101,7 +101,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlString newValue = new SqlString(); + SqlString newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDateTimeStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDateTimeStorage.cs index 692114a..857b416 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDateTimeStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDateTimeStorage.cs @@ -136,7 +136,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlDateTime newValue = new SqlDateTime(); + SqlDateTime newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDecimalStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDecimalStorage.cs index 3d624d9..c431374 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDecimalStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDecimalStorage.cs @@ -208,7 +208,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlDecimal newValue = new SqlDecimal(); + SqlDecimal newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDoubleStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDoubleStorage.cs index 36311be..bf3f6e0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDoubleStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLDoubleStorage.cs @@ -209,7 +209,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlDouble newValue = new SqlDouble(); + SqlDouble newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLGuidStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLGuidStorage.cs index be24e79..782528f 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLGuidStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLGuidStorage.cs @@ -101,7 +101,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlGuid newValue = new SqlGuid(); + SqlGuid newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt16Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt16Storage.cs index 3d7cabb..788cb6b 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt16Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt16Storage.cs @@ -209,7 +209,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlInt16 newValue = new SqlInt16(); + SqlInt16 newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt32Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt32Storage.cs index 57660c3..ec30347 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt32Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt32Storage.cs @@ -209,7 +209,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlInt32 newValue = new SqlInt32(); + SqlInt32 newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs index d31a7ee..b1f25f0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLInt64Storage.cs @@ -210,7 +210,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlInt64 newValue = new SqlInt64(); + SqlInt64 newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLMoneyStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLMoneyStorage.cs index 51fa06e..6572eed 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLMoneyStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLMoneyStorage.cs @@ -209,7 +209,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlMoney newValue = new SqlMoney(); + SqlMoney newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLSingleStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLSingleStorage.cs index 72e4fb0..b95c2ee 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLSingleStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLSingleStorage.cs @@ -207,7 +207,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlSingle newValue = new SqlSingle(); + SqlSingle newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLStringStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLStringStorage.cs index 8b7673f..985f825 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLStringStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQLStringStorage.cs @@ -162,7 +162,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlString newValue = new SqlString(); + SqlString newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQlBooleanStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQlBooleanStorage.cs index f3cd98a..d579310 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQlBooleanStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SQLTypes/SQlBooleanStorage.cs @@ -134,7 +134,7 @@ namespace System.Data.Common public override object ConvertXmlToObject(string s) { - SqlBoolean newValue = new SqlBoolean(); + SqlBoolean newValue = default; string tempStr = string.Concat("", s, ""); // this is done since you can give fragmet to reader StringReader strReader = new StringReader(tempStr); diff --git a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs index 99f7c60..f4d6ad8 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataSet.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataSet.cs @@ -1964,7 +1964,7 @@ namespace System.Data long logScopeId = DataCommonEventSource.Log.EnterScope(" {0}, denyResolving={1}", ObjectID, denyResolving); try { - DataTable.DSRowDiffIdUsageSection rowDiffIdUsage = new DataTable.DSRowDiffIdUsageSection(); + DataTable.DSRowDiffIdUsageSection rowDiffIdUsage = default; try { bool fDataFound = false; @@ -2483,7 +2483,7 @@ namespace System.Data return ReadXml(reader); } - DataTable.DSRowDiffIdUsageSection rowDiffIdUsage = new DataTable.DSRowDiffIdUsageSection(); + DataTable.DSRowDiffIdUsageSection rowDiffIdUsage = default; try { bool fSchemaFound = false; diff --git a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs index 3bafed8..035169a 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataTable.cs @@ -5664,7 +5664,7 @@ namespace System.Data long logScopeId = DataCommonEventSource.Log.EnterScope(" {0}, denyResolving={1}", ObjectID, denyResolving); try { - RowDiffIdUsageSection rowDiffIdUsage = new RowDiffIdUsageSection(); + RowDiffIdUsageSection rowDiffIdUsage = default; try { bool fDataFound = false; @@ -5904,7 +5904,7 @@ namespace System.Data internal XmlReadMode ReadXml(XmlReader reader, XmlReadMode mode, bool denyResolving) { - RowDiffIdUsageSection rowDiffIdUsage = new RowDiffIdUsageSection(); + RowDiffIdUsageSection rowDiffIdUsage = default; try { bool fSchemaFound = false; diff --git a/src/libraries/System.Data.Common/src/System/Data/Select.cs b/src/libraries/System.Data.Common/src/System/Data/Select.cs index 5c273d1..0c90184 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Select.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Select.cs @@ -773,7 +773,7 @@ namespace System.Data int lo = FindFirstMatchingRecord(); if (lo == -1) { - return new Range(); + return default; } int hi = FindLastMatchingRecord(lo); Debug.Assert(lo <= hi, "GetBinaryFilteredRecords : Invalid Search Results"); diff --git a/src/libraries/System.Data.Common/src/System/Data/Selection.cs b/src/libraries/System.Data.Common/src/System/Data/Selection.cs index 7158884..27f2168 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Selection.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Selection.cs @@ -644,7 +644,7 @@ namespace System.Data if (IndexTree.NIL == nodeId) { - return new Range(); + return default; } int recordIndex = _records.GetIndexByNode(nodeId); diff --git a/src/libraries/System.Data.SqlClient/src/Interop/SNINativeMethodWrapper.Windows.cs b/src/libraries/System.Data.SqlClient/src/Interop/SNINativeMethodWrapper.Windows.cs index 1902b70..65fea05 100644 --- a/src/libraries/System.Data.SqlClient/src/Interop/SNINativeMethodWrapper.Windows.cs +++ b/src/libraries/System.Data.SqlClient/src/Interop/SNINativeMethodWrapper.Windows.cs @@ -291,7 +291,7 @@ namespace System.Data.SqlClient internal static unsafe uint SNIOpenMarsSession(ConsumerInfo consumerInfo, SNIHandle parent, ref IntPtr pConn, bool fSync) { // initialize consumer info for MARS - Sni_Consumer_Info native_consumerInfo = new Sni_Consumer_Info(); + Sni_Consumer_Info native_consumerInfo = default; MarshalConsumerInfo(consumerInfo, ref native_consumerInfo); return SNIOpenWrapper(ref native_consumerInfo, "session:", parent, out pConn, fSync); @@ -301,7 +301,7 @@ namespace System.Data.SqlClient { fixed (byte* pin_instanceName = &instanceName[0]) { - SNI_CLIENT_CONSUMER_INFO clientConsumerInfo = new SNI_CLIENT_CONSUMER_INFO(); + SNI_CLIENT_CONSUMER_INFO clientConsumerInfo = default; // initialize client ConsumerInfo part first MarshalConsumerInfo(consumerInfo, ref clientConsumerInfo.ConsumerInfo); diff --git a/src/libraries/System.Data.SqlClient/src/Microsoft/SqlServer/Server/SmiMetaDataProperty.cs b/src/libraries/System.Data.SqlClient/src/Microsoft/SqlServer/Server/SmiMetaDataProperty.cs index 01a519c..6c778ba 100644 --- a/src/libraries/System.Data.SqlClient/src/Microsoft/SqlServer/Server/SmiMetaDataProperty.cs +++ b/src/libraries/System.Data.SqlClient/src/Microsoft/SqlServer/Server/SmiMetaDataProperty.cs @@ -163,7 +163,7 @@ namespace Microsoft.SqlServer.Server { if (_columns.Count <= ordinal) { - SmiColumnOrder order = new SmiColumnOrder(); + SmiColumnOrder order = default; order.Order = SortOrder.Unspecified; order.SortOrdinal = -1; return order; diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlBulkCopy.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlBulkCopy.cs index b317c66..2b2167f 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlBulkCopy.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlBulkCopy.cs @@ -2773,7 +2773,7 @@ namespace System.Data.SqlClient { if (_isAsyncBulkCopy) { - CancellationTokenRegistration regReconnectCancel = new CancellationTokenRegistration(); + CancellationTokenRegistration regReconnectCancel = default; TaskCompletionSource cancellableReconnectTS = new TaskCompletionSource(); if (cts.CanBeCanceled) { diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs index 5ac2f13..cdbaaa2 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs @@ -1644,7 +1644,7 @@ namespace System.Data.SqlClient TaskCompletionSource source = new TaskCompletionSource(); - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { if (cancellationToken.IsCancellationRequested) @@ -1727,7 +1727,7 @@ namespace System.Data.SqlClient TaskCompletionSource source = new TaskCompletionSource(); - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { if (cancellationToken.IsCancellationRequested) @@ -1872,7 +1872,7 @@ namespace System.Data.SqlClient TaskCompletionSource source = new TaskCompletionSource(); - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { if (cancellationToken.IsCancellationRequested) diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs index 899ac79..7913850 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs @@ -1043,7 +1043,7 @@ namespace System.Data.SqlClient } else { - CancellationTokenRegistration registration = new CancellationTokenRegistration(); + CancellationTokenRegistration registration = default; if (cancellationToken.CanBeCanceled) { registration = cancellationToken.Register(s => ((TaskCompletionSource)s).TrySetCanceled(), completion); diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs index 5b3aa72..d828468 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs @@ -801,7 +801,7 @@ namespace System.Data.SqlClient public static TdsDateTime FromDateTime(DateTime dateTime, byte cb) { SqlDateTime sqlDateTime; - TdsDateTime tdsDateTime = new TdsDateTime(); + TdsDateTime tdsDateTime = default; Debug.Assert(cb == 8 || cb == 4, "Invalid date time size!"); diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.Windows.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.Windows.cs index c26a62c..cf28575 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.Windows.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.Windows.cs @@ -93,7 +93,7 @@ namespace System.Data.SqlClient private SNIErrorDetails GetSniErrorDetails() { - SNIErrorDetails details = new SNIErrorDetails(); + SNIErrorDetails details = default; if (TdsParserStateObjectFactory.UseManagedSNI) { diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs index ee154b3..892c7c0 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs @@ -3914,7 +3914,7 @@ namespace System.Data.SqlClient multiPartTableName = default(MultiPartTableName); - mpt = new MultiPartTableName(); + mpt = default; byte nParts; // Find out how many parts in the TDS stream diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs index 94b3fe5..284a404 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObject.cs @@ -533,7 +533,7 @@ namespace System.Data.SqlClient internal NullBitmap Clone() { - NullBitmap newBitmap = new NullBitmap(); + NullBitmap newBitmap = default; newBitmap._nullBitmap = _nullBitmap == null ? null : (byte[])_nullBitmap.Clone(); newBitmap._columnsCount = _columnsCount; return newBitmap; diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectNative.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectNative.cs index 898d531..a6c8688 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectNative.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParserStateObjectNative.cs @@ -45,7 +45,7 @@ namespace System.Data.SqlClient private SNINativeMethodWrapper.ConsumerInfo CreateConsumerInfo(bool async) { - SNINativeMethodWrapper.ConsumerInfo myInfo = new SNINativeMethodWrapper.ConsumerInfo(); + SNINativeMethodWrapper.ConsumerInfo myInfo = default; Debug.Assert(_outBuff.Length == _inBuff.Length, "Unexpected unequal buffers."); diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs index 77d1f6a..e413d90 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs +++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/EventLogInternal.cs @@ -67,7 +67,7 @@ namespace System.Diagnostics private const int Flag_disposed = 0x100; private const int Flag_sourceVerified = 0x200; - private BitVector32 boolFlags = new BitVector32(); + private BitVector32 boolFlags; private Hashtable messageLibraries; private static readonly Hashtable listenerInfos = new Hashtable(StringComparer.OrdinalIgnoreCase); diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogSession.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogSession.cs index f747c29..2c278b0 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogSession.cs +++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/EventLogSession.cs @@ -105,7 +105,7 @@ namespace System.Diagnostics.Eventing.Reader _user = user; _logOnType = logOnType; - UnsafeNativeMethods.EvtRpcLogin erLogin = new UnsafeNativeMethods.EvtRpcLogin(); + UnsafeNativeMethods.EvtRpcLogin erLogin = default; erLogin.Server = _server; erLogin.User = _user; erLogin.Domain = _domain; diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs index a7d1069..2761073 100644 --- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs +++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/NativeWrapper.cs @@ -591,7 +591,7 @@ namespace System.Diagnostics.Eventing.Reader public static void EvtSetChannelConfigProperty(EventLogHandle handle, UnsafeNativeMethods.EvtChannelConfigPropertyId enumType, object val) { - UnsafeNativeMethods.EvtVariant varVal = new UnsafeNativeMethods.EvtVariant(); + UnsafeNativeMethods.EvtVariant varVal = default; CoTaskMemSafeHandle taskMem = new CoTaskMemSafeHandle(); diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs index 8f89623..1b6cd03 100644 --- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs +++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System/Diagnostics/FileVersionInfo.Windows.cs @@ -84,7 +84,7 @@ namespace System.Diagnostics return (Interop.Version.VS_FIXEDFILEINFO)Marshal.PtrToStructure(memRef); } - return new Interop.Version.VS_FIXEDFILEINFO(); + return default; } private static unsafe string GetFileVersionLanguage(IntPtr memPtr) diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/CounterSampleCalculator.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/CounterSampleCalculator.cs index 8f33c8e..0798e63 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/CounterSampleCalculator.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/CounterSampleCalculator.cs @@ -85,14 +85,14 @@ namespace System.Diagnostics if (newCounterType == Interop.Kernel32.PerformanceCounterOptions.PERF_ELAPSED_TIME) return (float)GetElapsedTime(oldSample, newSample); - Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER newPdhValue = new Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER(); - Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER oldPdhValue = new Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER(); + Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER newPdhValue = default; + Interop.Kernel32.PerformanceCounterOptions.PDH_RAW_COUNTER oldPdhValue = default; FillInValues(oldSample, newSample, ref oldPdhValue, ref newPdhValue); LoadPerfCounterDll(); - Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_COUNTERVALUE pdhFormattedValue = new Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_COUNTERVALUE(); + Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_COUNTERVALUE pdhFormattedValue = default; long timeBase = newSample.SystemFrequency; int result = Interop.PerfCounter.FormatFromRawValue((uint)newCounterType, Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_DOUBLE | Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_NOSCALE | Interop.Kernel32.PerformanceCounterOptions.PDH_FMT_NOCAP100, ref timeBase, ref newPdhValue, ref oldPdhValue, ref pdhFormattedValue); diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs index 8d9e452..8345b9a 100644 --- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs +++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System/Diagnostics/SharedPerformanceCounter.cs @@ -1690,7 +1690,7 @@ namespace System.Diagnostics out securityDescriptorPointer, IntPtr.Zero)) throw new InvalidOperationException(SR.SetSecurityDescriptorFailed); - Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes = new Interop.Kernel32.SECURITY_ATTRIBUTES(); + Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributes = default; securityAttributes.bInheritHandle = Interop.BOOL.FALSE; // @@ -1752,7 +1752,7 @@ namespace System.Diagnostics throw new InvalidOperationException(SR.CantMapFileView); // figure out what size the share memory really is. - Interop.Kernel32.MEMORY_BASIC_INFORMATION meminfo = new Interop.Kernel32.MEMORY_BASIC_INFORMATION(); + Interop.Kernel32.MEMORY_BASIC_INFORMATION meminfo = default; if (Interop.Kernel32.VirtualQuery(_fileViewAddress, ref meminfo, (UIntPtr)sizeof(Interop.Kernel32.MEMORY_BASIC_INFORMATION)) == UIntPtr.Zero) throw new InvalidOperationException(SR.CantGetMappingSize); diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs index 7e511d2..6adee94 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs @@ -462,9 +462,9 @@ namespace System.Diagnostics StringBuilder commandLine = BuildCommandLine(startInfo.FileName, StartInfo.Arguments); Process.AppendArguments(commandLine, StartInfo.ArgumentList); - Interop.Kernel32.STARTUPINFO startupInfo = new Interop.Kernel32.STARTUPINFO(); - Interop.Kernel32.PROCESS_INFORMATION processInfo = new Interop.Kernel32.PROCESS_INFORMATION(); - Interop.Kernel32.SECURITY_ATTRIBUTES unused_SecAttrs = new Interop.Kernel32.SECURITY_ATTRIBUTES(); + Interop.Kernel32.STARTUPINFO startupInfo = default; + Interop.Kernel32.PROCESS_INFORMATION processInfo = default; + Interop.Kernel32.SECURITY_ATTRIBUTES unused_SecAttrs = default; SafeProcessHandle procSH = new SafeProcessHandle(); SafeThreadHandle threadSH = new SafeThreadHandle(); @@ -836,7 +836,7 @@ namespace System.Diagnostics // for synchronous I/O and hence they can work fine with ReadFile/WriteFile synchronously! private void CreatePipe(out SafeFileHandle parentHandle, out SafeFileHandle childHandle, bool parentInputs) { - Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributesParent = new Interop.Kernel32.SECURITY_ATTRIBUTES(); + Interop.Kernel32.SECURITY_ATTRIBUTES securityAttributesParent = default; securityAttributesParent.bInheritHandle = Interop.BOOL.TRUE; SafeFileHandle hTmp = null; diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs index b2a1775..a3f3794 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs @@ -80,7 +80,7 @@ namespace System.Diagnostics processHandle = ProcessManager.OpenProcess(processId, Interop.Advapi32.ProcessOptions.PROCESS_QUERY_INFORMATION | Interop.Advapi32.ProcessOptions.PROCESS_VM_READ, true); IntPtr[] moduleHandles = new IntPtr[64]; - GCHandle moduleHandlesArrayHandle = new GCHandle(); + GCHandle moduleHandlesArrayHandle = default; int moduleCount = 0; while (true) { diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs index 34fb819..011776d 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs @@ -144,7 +144,7 @@ namespace System.Diagnostics // So we will try to get the privilege here. // We could fail if the user account doesn't have right to do this, but that's fair. - Interop.Advapi32.LUID luid = new Interop.Advapi32.LUID(); + Interop.Advapi32.LUID luid = default; if (!Interop.Advapi32.LookupPrivilegeValue(null, Interop.Advapi32.SeDebugPrivilege, out luid)) { return; diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AuthZSet.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AuthZSet.cs index 6eecd2a..6ec5eef 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AuthZSet.cs +++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/AuthZSet.cs @@ -56,7 +56,7 @@ namespace System.DirectoryServices.AccountManagement try { - UnsafeNativeMethods.LUID luid = new UnsafeNativeMethods.LUID(); + UnsafeNativeMethods.LUID luid = default; luid.low = 0; luid.high = 0; diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs index b0eaebf..b009456 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs +++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/Context.cs @@ -682,7 +682,7 @@ namespace System.DirectoryServices.AccountManagement private void DoServerVerifyAndPropRetrieval() { - _serverProperties = new ServerProperties(); + _serverProperties = default; if (_contextType == ContextType.ApplicationDirectory || _contextType == ContextType.Domain) { ReadServerConfig(_name, ref _serverProperties); diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs index 0fc22dc..81c9ee4 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs +++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs @@ -429,7 +429,7 @@ namespace System.DirectoryServices.AccountManagement public string DomainNameDns; [MarshalAs(UnmanagedType.LPWStr)] public string DomainForestName; - public Guid DomainGuid = new Guid(); + public Guid DomainGuid; } /* @@ -462,7 +462,7 @@ namespace System.DirectoryServices.AccountManagement public string DomainControllerName = null; public string DomainControllerAddress = null; public int DomainControllerAddressType = 0; - public Guid DomainGuid = new Guid(); + public Guid DomainGuid; public string DomainName = null; public string DnsForestName = null; public int Flags = 0; diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs index fdf6529..614f5d0 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs @@ -335,7 +335,7 @@ namespace System.DirectoryServices.Protocols throw new ObjectDisposedException(GetType().Name); } - var tempHandle = new SecurityHandle(); + SecurityHandle tempHandle = default; int error = Wldap32.ldap_get_option_sechandle(_connection._ldapHandle, LdapOption.LDAP_OPT_SECURITY_CONTEXT, ref tempHandle); ErrorChecking.CheckAndSetLdapError(error); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs index 7d9fd79..207d61f 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/UnsafeNativeMethods.cs @@ -592,7 +592,7 @@ namespace System.DirectoryServices.ActiveDirectory public string DomainNameDns; [MarshalAs(UnmanagedType.LPWStr)] public string DomainForestName; - public Guid DomainGuid = new Guid(); + public Guid DomainGuid = default; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs index 5878a7a..f1af856 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectoryEntry.cs @@ -502,7 +502,7 @@ namespace System.DirectoryServices } // the new option is available, set it so we get the new PutEx behavior that will allow multiple changes - Variant value = new Variant(); + Variant value = default; value.varType = 11; //VT_BOOL value.boolvalue = -1; ((UnsafeNativeMethods.IAdsObjectOptions2)_adsObject).SetOption(8, value); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs index 65dd718..117aab6 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/DirectorySearcher.cs @@ -675,7 +675,7 @@ namespace System.DirectoryServices AdsSearchPreferenceInfo info; // search scope - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.SEARCH_SCOPE; info.vValue = new AdsValueHelper((int)SearchScope).GetStruct(); prefList.Add(info); @@ -683,7 +683,7 @@ namespace System.DirectoryServices // size limit if (_sizeLimit != 0 || !findMoreThanOne) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.SIZE_LIMIT; info.vValue = new AdsValueHelper(findMoreThanOne ? SizeLimit : 1).GetStruct(); prefList.Add(info); @@ -692,14 +692,14 @@ namespace System.DirectoryServices // time limit if (ServerTimeLimit >= new TimeSpan(0)) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.TIME_LIMIT; info.vValue = new AdsValueHelper((int)ServerTimeLimit.TotalSeconds).GetStruct(); prefList.Add(info); } // propertyNamesOnly - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.ATTRIBTYPES_ONLY; info.vValue = new AdsValueHelper(PropertyNamesOnly).GetStruct(); prefList.Add(info); @@ -707,7 +707,7 @@ namespace System.DirectoryServices // Timeout if (ClientTimeout >= new TimeSpan(0)) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.TIMEOUT; info.vValue = new AdsValueHelper((int)ClientTimeout.TotalSeconds).GetStruct(); prefList.Add(info); @@ -716,7 +716,7 @@ namespace System.DirectoryServices // page size if (PageSize != 0) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.PAGESIZE; info.vValue = new AdsValueHelper(PageSize).GetStruct(); prefList.Add(info); @@ -725,14 +725,14 @@ namespace System.DirectoryServices // page time limit if (ServerPageTimeLimit >= new TimeSpan(0)) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.PAGED_TIME_LIMIT; info.vValue = new AdsValueHelper((int)ServerPageTimeLimit.TotalSeconds).GetStruct(); prefList.Add(info); } // chase referrals - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.CHASE_REFERRALS; info.vValue = new AdsValueHelper((int)ReferralChasing).GetStruct(); prefList.Add(info); @@ -740,7 +740,7 @@ namespace System.DirectoryServices // asynchronous if (Asynchronous == true) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.ASYNCHRONOUS; info.vValue = new AdsValueHelper(Asynchronous).GetStruct(); prefList.Add(info); @@ -749,7 +749,7 @@ namespace System.DirectoryServices // tombstone if (Tombstone == true) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.TOMBSTONE; info.vValue = new AdsValueHelper(Tombstone).GetStruct(); prefList.Add(info); @@ -758,7 +758,7 @@ namespace System.DirectoryServices // attributescopequery if (_attributeScopeQuerySpecified) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.ATTRIBUTE_QUERY; info.vValue = new AdsValueHelper(AttributeScopeQuery, AdsType.ADSTYPE_CASE_IGNORE_STRING).GetStruct(); prefList.Add(info); @@ -767,7 +767,7 @@ namespace System.DirectoryServices // derefalias if (DerefAlias != DereferenceAlias.Never) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.DEREF_ALIASES; info.vValue = new AdsValueHelper((int)DerefAlias).GetStruct(); prefList.Add(info); @@ -776,7 +776,7 @@ namespace System.DirectoryServices // securitymask if (SecurityMasks != SecurityMasks.None) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.SECURITY_MASK; info.vValue = new AdsValueHelper((int)SecurityMasks).GetStruct(); prefList.Add(info); @@ -785,7 +785,7 @@ namespace System.DirectoryServices // extendeddn if (ExtendedDN != ExtendedDN.None) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.EXTENDED_DN; info.vValue = new AdsValueHelper((int)ExtendedDN).GetStruct(); prefList.Add(info); @@ -794,14 +794,14 @@ namespace System.DirectoryServices // dirsync if (directorySynchronizationSpecified) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.DIRSYNC; info.vValue = new AdsValueHelper(DirectorySynchronization.GetDirectorySynchronizationCookie(), AdsType.ADSTYPE_PROV_SPECIFIC).GetStruct(); prefList.Add(info); if (DirectorySynchronization.Option != DirectorySynchronizationOptions.None) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.DIRSYNC_FLAG; info.vValue = new AdsValueHelper((int)DirectorySynchronization.Option).GetStruct(); prefList.Add(info); @@ -817,9 +817,9 @@ namespace System.DirectoryServices // sort if (Sort.PropertyName != null && Sort.PropertyName.Length > 0) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.SORT_ON; - AdsSortKey sortKey = new AdsSortKey(); + AdsSortKey sortKey = default; sortKey.pszAttrType = Marshal.StringToCoTaskMemUni(Sort.PropertyName); ptrToFree = sortKey.pszAttrType; // so we can free it later. sortKey.pszReserved = (IntPtr)0; @@ -833,7 +833,7 @@ namespace System.DirectoryServices // vlv if (directoryVirtualListViewSpecified) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.VLV; AdsVLV vlvValue = new AdsVLV(); vlvValue.beforeCount = _vlv.BeforeCount; @@ -875,7 +875,7 @@ namespace System.DirectoryServices // cacheResults if (_cacheResultsSpecified) { - info = new AdsSearchPreferenceInfo(); + info = default; info.dwSearchPref = (int)AdsSearchPreferences.CACHE_RESULTS; info.vValue = new AdsValueHelper(CacheResults).GetStruct(); prefList.Add(info); diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs index 0c9e734..6a35ed1 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/SearchResultCollection.cs @@ -107,7 +107,7 @@ namespace System.DirectoryServices throw new ObjectDisposedException(GetType().Name); // get the dirsync cookie back - AdsSearchColumn column = new AdsSearchColumn(); + AdsSearchColumn column = default; AdsSearchColumn* pColumn = &column; SearchObject.GetColumn(Handle, _adsDirsynCookieName, (INTPTR_INTPTRCAST)pColumn); try @@ -135,7 +135,7 @@ namespace System.DirectoryServices throw new ObjectDisposedException(GetType().Name); // get the vlv response back - AdsSearchColumn column = new AdsSearchColumn(); + AdsSearchColumn column = default; AdsSearchColumn* pColumn = &column; SearchObject.GetColumn(Handle, _adsVLVResponseName, (INTPTR_INTPTRCAST)pColumn); try @@ -274,7 +274,7 @@ namespace System.DirectoryServices { try { - AdsSearchColumn column = new AdsSearchColumn(); + AdsSearchColumn column = default; AdsSearchColumn* pColumn = &column; _results.SearchObject.GetColumn(_results.Handle, pszColumnName, (INTPTR_INTPTRCAST)pColumn); try diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Windows.cs index 106865f..9177013 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/BufferedGraphicsContext.Windows.cs @@ -259,7 +259,7 @@ namespace System.Drawing } IntPtr hbmRet = IntPtr.Zero; - var pbmi = new NativeMethods.BITMAPINFO_FLAT(); + NativeMethods.BITMAPINFO_FLAT pbmi = default; // Validate hdc. Interop.Gdi32.ObjectType objType = Interop.Gdi32.GetObjectType(hdc); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Unix.cs index b7862e5..5413d28 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Drawing2D/GraphicsPath.Unix.cs @@ -625,7 +625,7 @@ namespace System.Drawing.Drawing2D public void AddString(string s, FontFamily family, int style, float emSize, Point origin, StringFormat format) { - Rectangle layout = new Rectangle(); + Rectangle layout = default; layout.X = origin.X; layout.Y = origin.Y; AddString(s, family, style, emSize, layout, format); @@ -633,7 +633,7 @@ namespace System.Drawing.Drawing2D public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format) { - RectangleF layout = new RectangleF(); + RectangleF layout = default; layout.X = origin.X; layout.Y = origin.Y; AddString(s, family, style, emSize, layout, format); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Unix.cs index 000c1bc..399733b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Unix.cs @@ -162,7 +162,7 @@ namespace System.Drawing IntPtr newObject; FontStyle newStyle = FontStyle.Regular; float newSize; - Interop.User32.LOGFONT lf = new Interop.User32.LOGFONT(); + Interop.User32.LOGFONT lf = default; // Sanity. Should we throw an exception? if (hfont == IntPtr.Zero) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs index 1d25e3c..687676b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.Windows.cs @@ -226,7 +226,7 @@ namespace System.Drawing /// public static Font FromHfont(IntPtr hfont) { - var logFont = new Interop.User32.LOGFONT(); + Interop.User32.LOGFONT logFont = default; SafeNativeMethods.GetObject(new HandleRef(null, hfont), ref logFont); using (ScreenDC dc = ScreenDC.Create()) @@ -309,7 +309,7 @@ namespace System.Drawing } // Now that we know the marshalled size is the same as LOGFONT, copy in the data - logFont = new Interop.User32.LOGFONT(); + logFont = default; Marshal.StructureToPtr(lf, new IntPtr(&logFont), fDeleteOld: false); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs index ccf9442..6231cfe 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Font.cs @@ -310,7 +310,7 @@ namespace System.Drawing throw new ArgumentNullException(nameof(graphics)); } - Interop.User32.LOGFONT logFont = new Interop.User32.LOGFONT(); + Interop.User32.LOGFONT logFont = default; Gdip.CheckStatus(Gdip.GdipGetLogFontW( new HandleRef(this, NativeFont), new HandleRef(graphics, graphics.NativeGraphics), ref logFont)); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs index 1862a48..83d1534 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs @@ -1374,7 +1374,7 @@ namespace System.Drawing public static StartupInput GetDefault() { - StartupInput result = new StartupInput(); + StartupInput result = default; result.GdiplusVersion = 1; // result.DebugEventCallback = null; result.SuppressBackgroundThread = false; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs index 902f505..0fbaa90 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs @@ -151,7 +151,7 @@ namespace System.Drawing window = LibX11Functions.XRootWindow(Gdip.Display, 0); defvisual = LibX11Functions.XDefaultVisual(Gdip.Display, 0); - XVisualInfo visual = new XVisualInfo(); + XVisualInfo visual = default; /* Get XVisualInfo for this visual */ visual.visualid = LibX11Functions.XVisualIDFromVisual(defvisual); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index 7d0871c..dbd458a 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -1463,7 +1463,7 @@ namespace System.Drawing throw new ArgumentNullException(nameof(font)); RectangleF layout = new RectangleF(0, 0, layoutArea.Width, layoutArea.Height); - RectangleF boundingBox = new RectangleF(); + RectangleF boundingBox = default; Gdip.CheckStatus(Gdip.GdipMeasureString( new HandleRef(this, NativeGraphics), @@ -1487,7 +1487,7 @@ namespace System.Drawing throw new ArgumentNullException(nameof(font)); RectangleF layout = new RectangleF(origin.X, origin.Y, 0, 0); - RectangleF boundingBox = new RectangleF(); + RectangleF boundingBox = default; Gdip.CheckStatus(Gdip.GdipMeasureString( new HandleRef(this, NativeGraphics), @@ -1513,7 +1513,7 @@ namespace System.Drawing throw new ArgumentNullException(nameof(font)); RectangleF layout = new RectangleF(0, 0, layoutArea.Width, layoutArea.Height); - RectangleF boundingBox = new RectangleF(); + RectangleF boundingBox = default; Gdip.CheckStatus(Gdip.GdipMeasureString( new HandleRef(this, NativeGraphics), diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs index 74abe56..fee5856 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs @@ -456,7 +456,7 @@ namespace System.Drawing writer.Write((ushort)1); // only one icon // when transformed into a bitmap only a single image exists - IconDirEntry ide = new IconDirEntry(); + IconDirEntry ide = default; ide.width = (byte)bitmap.Width; ide.height = (byte)bitmap.Height; ide.colorCount = 0; // 32 bbp == 0, for palette size @@ -465,7 +465,7 @@ namespace System.Drawing ide.bitCount = 32; ide.imageOffset = 22; // 22 is the first icon position (for single icon files) - BitmapInfoHeader bih = new BitmapInfoHeader(); + BitmapInfoHeader bih = default; bih.biSize = (uint)Marshal.SizeOf(typeof(BitmapInfoHeader)); bih.biWidth = bitmap.Width; bih.biHeight = 2 * bitmap.Height; // include both XOR and AND images diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs index 32c87d9..5d5c054 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.cs @@ -217,9 +217,9 @@ namespace System.Drawing { if (_iconSize.IsEmpty) { - var info = new SafeNativeMethods.ICONINFO(); + SafeNativeMethods.ICONINFO info = default; SafeNativeMethods.GetIconInfo(new HandleRef(this, Handle), ref info); - var bitmap = new SafeNativeMethods.BITMAP(); + SafeNativeMethods.BITMAP bitmap = default; if (info.hbmColor != IntPtr.Zero) { @@ -760,9 +760,9 @@ namespace System.Drawing else if (_bestBitDepth == 0 || _bestBitDepth == 32) { // This may be a 32bpp icon or an icon without any data. - var info = new SafeNativeMethods.ICONINFO(); + SafeNativeMethods.ICONINFO info = default; SafeNativeMethods.GetIconInfo(new HandleRef(this, _handle), ref info); - var bmp = new SafeNativeMethods.BITMAP(); + SafeNativeMethods.BITMAP bmp = default; try { if (info.hbmColor != IntPtr.Zero) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.Unix.cs index f844c9a..2d0b83e 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.Unix.cs @@ -102,7 +102,7 @@ namespace System.Drawing int propSize; IntPtr property; PropertyItem item = new PropertyItem(); - GdipPropertyItem gdipProperty = new GdipPropertyItem(); + GdipPropertyItem gdipProperty = default; int status; status = Gdip.GdipGetPropertyItemSize(nativeImage, propid, @@ -289,7 +289,7 @@ namespace System.Drawing IntPtr dest = Marshal.AllocHGlobal(size); try { - GdipPropertyItem pi = new GdipPropertyItem(); + GdipPropertyItem pi = default; pi.id = propitem.Id; pi.len = propitem.Len; pi.type = propitem.Type; @@ -397,7 +397,7 @@ namespace System.Drawing int propNums, propsSize, propSize; IntPtr properties, propPtr; PropertyItem[] items; - GdipPropertyItem gdipProperty = new GdipPropertyItem(); + GdipPropertyItem gdipProperty = default; int status; status = Gdip.GdipGetPropertySize(nativeImage, out propsSize, out propNums); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs index 5490032..37765ce 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs @@ -269,7 +269,7 @@ namespace System.Drawing { get { - Guid guid = new Guid(); + Guid guid = default; int status = Gdip.GdipGetImageRawFormat(new HandleRef(this, nativeImage), ref guid); Gdip.CheckStatus(status); 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 de1e516..eae3070 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 @@ -221,7 +221,7 @@ namespace System.Drawing // writer queue. See ReaderWriterLock.AcquireWriterLock method in the MSDN. bool readerLockHeld = s_rwImgListLock.IsReaderLockHeld; - LockCookie lockDowngradeCookie = new LockCookie(); + LockCookie lockDowngradeCookie = default; t_threadWriterLockWaitCount++; @@ -326,7 +326,7 @@ namespace System.Drawing // Acquire a writer lock to modify the image info list - See comments on Animate() about this locking. bool readerLockHeld = s_rwImgListLock.IsReaderLockHeld; - LockCookie lockDowngradeCookie = new LockCookie(); + LockCookie lockDowngradeCookie = default; t_threadWriterLockWaitCount++; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMap.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMap.cs index 654b920..cd470e3 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMap.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMap.cs @@ -17,8 +17,6 @@ namespace System.Drawing.Imaging /// public ColorMap() { - _oldColor = new Color(); - _newColor = new Color(); } /// diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageAttributes.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageAttributes.cs index 969a139..da56dce 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageAttributes.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ImageAttributes.cs @@ -497,7 +497,7 @@ namespace System.Drawing.Imaging public void SetWrapMode(WrapMode mode) { - SetWrapMode(mode, new Color(), false); + SetWrapMode(mode, default(Color), false); } public void SetWrapMode(WrapMode mode, Color color) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs index 39f55ae..46d7e4c 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/Metafile.Unix.cs @@ -71,17 +71,17 @@ namespace System.Drawing.Imaging } public Metafile(IntPtr referenceHdc, EmfType emfType, string description) : - this(referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, emfType, description) + this(referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, emfType, description) { } public Metafile(Stream stream, IntPtr referenceHdc, EmfType type, string description) : - this(stream, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, description) + this(stream, referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, type, description) { } public Metafile(string fileName, IntPtr referenceHdc, EmfType type, string description) : - this(fileName, referenceHdc, new RectangleF(), MetafileFrameUnit.GdiCompatible, type, description) + this(fileName, referenceHdc, default(RectangleF), MetafileFrameUnit.GdiCompatible, type, description) { } diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs index 777779a..d524a44 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeader.Unix.cs @@ -156,7 +156,7 @@ namespace System.Drawing.Imaging if (this.MetafileSize == 0) { // GDI+ compatibility; - return new Rectangle(); + return default; } return new Rectangle(header.x, header.y, header.width, header.height); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Windows.cs index e46f67a..4279a50 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PageSettings.Windows.cs @@ -186,7 +186,7 @@ namespace System.Drawing.Printing { get { - RectangleF printableArea = new RectangleF(); + RectangleF printableArea = default; DeviceContext dc = printerSettings.CreateInformationContext(this); HandleRef hdc = new HandleRef(dc, dc.Hdc); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs index 1ee2344..a769d3cb 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs @@ -902,7 +902,7 @@ namespace System.Drawing.Printing default_page_settings.PrinterResolution.X, default_page_settings.PrinterResolution.Y, ref graphics); - DOCINFO doc = new DOCINFO(); + DOCINFO doc = default; doc.filename = name; doc.settings = settings; doc.default_page_settings = default_page_settings; diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.Windows.cs index 2c099e3..f8252f1 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/SystemFonts.Windows.cs @@ -117,7 +117,7 @@ namespace System.Drawing { Font iconTitleFont = null; - var itfont = new Interop.User32.LOGFONT(); + Interop.User32.LOGFONT itfont = default; if (Interop.User32.SystemParametersInfoW(Interop.User32.SystemParametersAction.SPI_GETICONTITLELOGFONT, (uint)sizeof(Interop.User32.LOGFONT), &itfont, 0)) { iconTitleFont = GetFontFromData(itfont); diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs index d8b20b3..7626221 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs @@ -70,7 +70,7 @@ namespace System.Drawing { IntPtr graphicsContext = objc_msgSend(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext")); IntPtr ctx = objc_msgSend(graphicsContext, sel_registerName("graphicsPort")); - Rect bounds = new Rect(); + Rect bounds = default; CGContextSaveGState(ctx); @@ -105,8 +105,8 @@ namespace System.Drawing return new CarbonContext(port, context, (int)desktop_bounds.size.width, (int)desktop_bounds.size.height); } - QDRect window_bounds = new QDRect(); - Rect view_bounds = new Rect(); + QDRect window_bounds = default(QDRect); + Rect view_bounds = default(Rect); port = GetWindowPort(window); diff --git a/src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContext.cs b/src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContext.cs index a15e1c2..48cbb93 100644 --- a/src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContext.cs +++ b/src/libraries/System.Drawing.Common/src/misc/GDI/DeviceContext.cs @@ -431,7 +431,7 @@ namespace System.Drawing.Internal /// public void TranslateTransform(int dx, int dy) { - var origin = new Point(); + Point origin = default; Interop.Gdi32.OffsetViewportOrgEx(new HandleRef(this, _hDC), dx, dy, ref origin); } diff --git a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsRegion.cs b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsRegion.cs index 7133753..08a8336 100644 --- a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsRegion.cs +++ b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsRegion.cs @@ -143,7 +143,7 @@ namespace System.Drawing.Internal return new Rectangle(-int.MaxValue, -int.MaxValue, int.MaxValue, int.MaxValue); } - var rect = new Interop.Gdi32.RECT(); + Interop.Gdi32.RECT rect = default; Interop.Gdi32.GetRgnBox(new HandleRef(this, _nativeHandle), ref rect); return new Rectangle(new Point(rect.left, rect.top), rect.Size); } diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs index 37b4cba..e0c853b 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Color.cs @@ -14,7 +14,7 @@ namespace System.Drawing [TypeForwardedFrom("System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public readonly struct Color : IEquatable { - public static readonly Color Empty = new Color(); + public static readonly Color Empty; // ------------------------------------------------------------------- // static list of "web" colors... diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs index 1ae45c8..c8fe4e8 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Point.cs @@ -17,7 +17,7 @@ namespace System.Drawing /// /// Creates a new instance of the class with member data left uninitialized. /// - public static readonly Point Empty = new Point(); + public static readonly Point Empty; private int x; // Do not rename (binary serialization) private int y; // Do not rename (binary serialization) diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs index 4f3f0e4..0dfa991 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/PointF.cs @@ -16,7 +16,7 @@ namespace System.Drawing /// /// Creates a new instance of the class with member data left uninitialized. /// - public static readonly PointF Empty = new PointF(); + public static readonly PointF Empty; private float x; // Do not rename (binary serialization) private float y; // Do not rename (binary serialization) diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs index c689428..2cfc93b 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs @@ -14,7 +14,7 @@ namespace System.Drawing [TypeConverter("System.Drawing.RectangleConverter, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public struct Rectangle : IEquatable { - public static readonly Rectangle Empty = new Rectangle(); + public static readonly Rectangle Empty; private int x; // Do not rename (binary serialization) private int y; // Do not rename (binary serialization) diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs index b611665..c5a7afb 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs @@ -16,7 +16,7 @@ namespace System.Drawing /// /// Initializes a new instance of the class. /// - public static readonly RectangleF Empty = new RectangleF(); + public static readonly RectangleF Empty; private float x; // Do not rename (binary serialization) private float y; // Do not rename (binary serialization) diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs index f0c5b1e..e393551 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/Size.cs @@ -17,7 +17,7 @@ namespace System.Drawing /// /// Initializes a new instance of the class. /// - public static readonly Size Empty = new Size(); + public static readonly Size Empty; private int width; // Do not rename (binary serialization) private int height; // Do not rename (binary serialization) diff --git a/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs b/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs index 9b0761c..c771a21 100644 --- a/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs +++ b/src/libraries/System.Drawing.Primitives/src/System/Drawing/SizeF.cs @@ -17,7 +17,7 @@ namespace System.Drawing /// /// Initializes a new instance of the class. /// - public static readonly SizeF Empty = new SizeF(); + public static readonly SizeF Empty; private float width; // Do not rename (binary serialization) private float height; // Do not rename (binary serialization) diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibNative.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibNative.cs index 99e3ee7..b4e10f7 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibNative.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/DeflateZLib/ZLibNative.cs @@ -182,7 +182,6 @@ namespace System.IO.Compression public ZLibStreamHandle() : base(new IntPtr(-1), true) { - _zStream = new ZStream(); _zStream.Init(); _initializationState = State.NotInitialized; diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs index 95493e0..063fc39 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipArchiveEntry.cs @@ -456,7 +456,7 @@ namespace System.IO.Compression Debug.Assert(_storedEntryNameBytes.Length <= ushort.MaxValue); // decide if we need the Zip64 extra field: - Zip64ExtraField zip64ExtraField = new Zip64ExtraField(); + Zip64ExtraField zip64ExtraField = default; uint compressedSizeTruncated, uncompressedSizeTruncated, offsetOfLocalHeaderTruncated; bool zip64Needed = false; @@ -804,7 +804,7 @@ namespace System.IO.Compression Debug.Assert(_storedEntryNameBytes.Length <= ushort.MaxValue); // decide if we need the Zip64 extra field: - Zip64ExtraField zip64ExtraField = new Zip64ExtraField(); + Zip64ExtraField zip64ExtraField = default; bool zip64Used = false; uint compressedSizeTruncated, uncompressedSizeTruncated; diff --git a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs index 20fb1e7..f5028da 100644 --- a/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs +++ b/src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs @@ -35,7 +35,7 @@ namespace System.IO.Compression // assumes we are positioned at the beginning of an extra field subfield public static bool TryReadBlock(BinaryReader reader, long endExtraField, out ZipGenericExtraField field) { - field = new ZipGenericExtraField(); + field = default; // not enough bytes to read tag + size if (endExtraField - reader.BaseStream.Position < 4) @@ -159,7 +159,7 @@ namespace System.IO.Compression } } - zip64Field = new Zip64ExtraField(); + zip64Field = default; zip64Field._compressedSize = null; zip64Field._uncompressedSize = null; @@ -174,7 +174,7 @@ namespace System.IO.Compression bool readLocalHeaderOffset, bool readStartDiskNumber, out Zip64ExtraField zip64Block) { - zip64Block = new Zip64ExtraField(); + zip64Block = default; zip64Block._compressedSize = null; zip64Block._uncompressedSize = null; @@ -231,7 +231,7 @@ namespace System.IO.Compression bool readUncompressedSize, bool readCompressedSize, bool readLocalHeaderOffset, bool readStartDiskNumber) { - Zip64ExtraField zip64Field = new Zip64ExtraField(); + Zip64ExtraField zip64Field = default; zip64Field._compressedSize = null; zip64Field._uncompressedSize = null; @@ -299,7 +299,7 @@ namespace System.IO.Compression public static bool TryReadBlock(BinaryReader reader, out Zip64EndOfCentralDirectoryLocator zip64EOCDLocator) { - zip64EOCDLocator = new Zip64EndOfCentralDirectoryLocator(); + zip64EOCDLocator = default; if (reader.ReadUInt32() != SignatureConstant) return false; @@ -337,7 +337,7 @@ namespace System.IO.Compression public static bool TryReadBlock(BinaryReader reader, out Zip64EndOfCentralDirectoryRecord zip64EOCDRecord) { - zip64EOCDRecord = new Zip64EndOfCentralDirectoryRecord(); + zip64EOCDRecord = default; if (reader.ReadUInt32() != SignatureConstant) return false; @@ -564,7 +564,7 @@ namespace System.IO.Compression // in either case, the zip64 extra field info will be incorporated into other fields public static bool TryReadBlock(BinaryReader reader, bool saveExtraFieldsAndComments, out ZipCentralDirectoryFileHeader header) { - header = new ZipCentralDirectoryFileHeader(); + header = default; if (reader.ReadUInt32() != SignatureConstant) return false; @@ -693,7 +693,7 @@ namespace System.IO.Compression public static bool TryReadBlock(BinaryReader reader, out ZipEndOfCentralDirectoryBlock eocdBlock) { - eocdBlock = new ZipEndOfCentralDirectoryBlock(); + eocdBlock = default; if (reader.ReadUInt32() != SignatureConstant) return false; diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs index 4a6c3ac..c347e15 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Windows.cs @@ -46,7 +46,7 @@ namespace System.IO.Enumeration // We'll only suppress the media insertion prompt on the topmost directory as that is the // most likely scenario and we don't want to take the perf hit for large enumerations. // (We weren't consistent with how we handled this historically.) - using (new DisableMediaInsertionPrompt()) + using (default(DisableMediaInsertionPrompt)) { // We need to initialize the directory handle up front to ensure // we immediately throw IO exceptions for missing directory/etc. diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Windows.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Windows.cs index 69fa9d7..8c62969 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Windows.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Windows.cs @@ -72,7 +72,7 @@ namespace System.IO public static FileAttributes GetAttributes(string fullPath) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: true); if (errorCode != 0) throw Win32Marshal.GetExceptionForWin32Error(errorCode, fullPath); @@ -82,7 +82,7 @@ namespace System.IO public static DateTimeOffset GetCreationTime(string fullPath) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: false); if (errorCode != 0) throw Win32Marshal.GetExceptionForWin32Error(errorCode, fullPath); @@ -99,7 +99,7 @@ namespace System.IO public static DateTimeOffset GetLastAccessTime(string fullPath) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: false); if (errorCode != 0) throw Win32Marshal.GetExceptionForWin32Error(errorCode, fullPath); @@ -109,7 +109,7 @@ namespace System.IO public static DateTimeOffset GetLastWriteTime(string fullPath) { - Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default; int errorCode = FillAttributeInfo(fullPath, ref data, returnErrorOnNotFound: false); if (errorCode != 0) throw Win32Marshal.GetExceptionForWin32Error(errorCode, fullPath); @@ -185,7 +185,7 @@ namespace System.IO return; } - Interop.Kernel32.WIN32_FIND_DATA findData = new Interop.Kernel32.WIN32_FIND_DATA(); + Interop.Kernel32.WIN32_FIND_DATA findData = default; GetFindData(fullPath, ref findData); if (IsNameSurrogateReparsePoint(ref findData)) { diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs index ca9d015..7f02a12 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs @@ -145,7 +145,7 @@ namespace System.IO { if (_dataInitialized == -1) { - _data = new Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA(); + _data = default; Refresh(); } diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs index 38de642..b60d81e 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedFile.Windows.cs @@ -245,7 +245,7 @@ namespace System.IO.MemoryMappedFiles Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default(Interop.Kernel32.SECURITY_ATTRIBUTES); if ((inheritability & HandleInheritability.Inheritable) != 0) { - secAttrs = new Interop.Kernel32.SECURITY_ATTRIBUTES(); + secAttrs = default; secAttrs.nLength = (uint)sizeof(Interop.Kernel32.SECURITY_ATTRIBUTES); secAttrs.bInheritHandle = Interop.BOOL.TRUE; } diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs index 2648a39..46c0da4 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs @@ -46,7 +46,7 @@ namespace System.IO.MemoryMappedFiles } // Query the view for its size and allocation type - Interop.Kernel32.MEMORY_BASIC_INFORMATION viewInfo = new Interop.Kernel32.MEMORY_BASIC_INFORMATION(); + Interop.Kernel32.MEMORY_BASIC_INFORMATION viewInfo = default; Interop.Kernel32.VirtualQuery(viewHandle, ref viewInfo, (UIntPtr)Marshal.SizeOf(viewInfo)); ulong viewSize = (ulong)viewInfo.RegionSize; @@ -72,7 +72,7 @@ namespace System.IO.MemoryMappedFiles throw Win32Marshal.GetExceptionForWin32Error(lastError); } // again query the view for its new size - viewInfo = new Interop.Kernel32.MEMORY_BASIC_INFORMATION(); + viewInfo = default; Interop.Kernel32.VirtualQuery(viewHandle, ref viewInfo, (UIntPtr)Marshal.SizeOf(viewInfo)); viewSize = (ulong)viewInfo.RegionSize; } @@ -119,7 +119,7 @@ namespace System.IO.MemoryMappedFiles if (error != Interop.Errors.ERROR_LOCK_VIOLATION) throw Win32Marshal.GetExceptionForWin32Error(error); - SpinWait spinWait = new SpinWait(); + SpinWait spinWait = default; for (int w = 0; w < MaxFlushWaits; w++) { int pause = (1 << w); // MaxFlushRetries should never be over 30 diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs index 563dd97..d66d40d 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs @@ -352,7 +352,7 @@ namespace System.IO.Pipelines // If the writer is completed (which it will be most of the time) then return a completed ValueTask if (_writerAwaitable.IsCompleted) { - var flushResult = new FlushResult(); + FlushResult flushResult = default; GetFlushResult(ref flushResult); result = new ValueTask(flushResult); } diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs index cf5cc25..4a4ff09 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeReader.cs @@ -205,7 +205,7 @@ namespace System.IO.Pipelines return new ReadResult(buffer: default, isCanceled: false, isCompleted: true); } - var reg = new CancellationTokenRegistration(); + CancellationTokenRegistration reg = default; if (cancellationToken.CanBeCanceled) { reg = cancellationToken.UnsafeRegister(state => ((StreamPipeReader)state!).Cancel(), this); @@ -291,7 +291,7 @@ namespace System.IO.Pipelines return true; } - result = new ReadResult(); + result = default; return false; } diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs index a5a7ec2..c87d6f3 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriter.cs @@ -265,7 +265,7 @@ namespace System.IO.Pipelines { // Write all completed segments and whatever remains in the current segment // and flush the result. - var reg = new CancellationTokenRegistration(); + CancellationTokenRegistration reg = default; if (cancellationToken.CanBeCanceled) { reg = cancellationToken.UnsafeRegister(state => ((StreamPipeWriter)state!).Cancel(), this); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs index aed3ec1..7c632ed 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/AnonymousPipeServerStream.Windows.cs @@ -32,7 +32,7 @@ namespace System.IO.Pipes SafePipeHandle newServerHandle; // Create the two pipe handles that make up the anonymous pipe. - var pinningHandle = new GCHandle(); + GCHandle pinningHandle = default; try { Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = PipeStream.GetSecAttrs(inheritability, pipeSecurity, ref pinningHandle); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.cs index f9c74cb..796c3f9 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeClientStream.cs @@ -144,7 +144,7 @@ namespace System.IO.Pipes { // This is the main connection loop. It will loop until the timeout expires. int elapsed = 0; - var sw = new SpinWait(); + SpinWait sw = default; do { cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs index 99eeb0c..82f1eb3 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/NamedPipeServerStream.Windows.cs @@ -84,7 +84,7 @@ namespace System.IO.Pipes maxNumberOfServerInstances = 255; } - var pinningHandle = new GCHandle(); + GCHandle pinningHandle = default; try { Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = PipeStream.GetSecAttrs(inheritability, pipeSecurity, ref pinningHandle); diff --git a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs index 04d966e..3973970 100644 --- a/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs +++ b/src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Windows.cs @@ -402,7 +402,7 @@ namespace System.IO.Pipes Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs = default(Interop.Kernel32.SECURITY_ATTRIBUTES); if ((inheritability & HandleInheritability.Inheritable) != 0) { - secAttrs = new Interop.Kernel32.SECURITY_ATTRIBUTES(); + secAttrs = default; secAttrs.nLength = (uint)sizeof(Interop.Kernel32.SECURITY_ATTRIBUTES); secAttrs.bInheritHandle = Interop.BOOL.TRUE; } diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs index 785830d..4616384 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Unix.cs @@ -384,7 +384,7 @@ namespace System.IO.Ports { if (_handle == null) InternalResources.FileNotOpen(); - SpinWait sw = new SpinWait(); + SpinWait sw = default; while (!_writeQueue.IsEmpty) { sw.SpinOnce(); diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs index d634115..56cf3b7 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialStream.Windows.cs @@ -604,7 +604,7 @@ namespace System.IO.Ports // fine for "LPT1" on Win9x, so that alone can't be relied here to // detect non serial devices. - _commProp = new Interop.Kernel32.COMMPROP(); + _commProp = default; int pinStatus = 0; if (!Interop.Kernel32.GetCommProperties(_handle, ref _commProp) @@ -622,10 +622,10 @@ namespace System.IO.Ports if (_commProp.dwMaxBaud != 0 && baudRate > _commProp.dwMaxBaud) throw new ArgumentOutOfRangeException(nameof(baudRate), SR.Format(SR.Max_Baud, _commProp.dwMaxBaud)); - _comStat = new Interop.Kernel32.COMSTAT(); + _comStat = default; // create internal DCB structure, initialize according to Platform SDK // standard: ms-help://MS.MSNDNQTR.2002APR.1003/hardware/commun_965u.htm - _dcb = new Interop.Kernel32.DCB(); + _dcb = default; // set constant properties of the DCB InitializeDCB(baudRate, parity, dataBits, stopBits, discardNull); diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs index 18e548d..41af1c7 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs @@ -212,7 +212,7 @@ namespace System.Linq.Expressions.Interpreter { if (_keysAndValues[i].Key == key) { - _keysAndValues[i] = new KeyValuePair(); + _keysAndValues[i] = default; return; } } diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/QuerySettings.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/QuerySettings.cs index d9c63bd..930787d 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/QuerySettings.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/QueryOperators/QuerySettings.cs @@ -212,7 +212,7 @@ namespace System.Linq.Parallel // Returns the default settings internal static QuerySettings Empty { - get { return new QuerySettings(null, null, new CancellationToken(), null, null); } + get { return new QuerySettings(null, null, CancellationToken.None, null, null); } } // Cleanup internal state once the entire query is complete. diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/QueryTask.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/QueryTask.cs index 714e654..1e6c1a2 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/QueryTask.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/QueryTask.cs @@ -82,7 +82,7 @@ namespace System.Linq.Parallel Debug.Assert(taskScheduler == TaskScheduler.Default, "PLINQ queries can currently execute only on the default scheduler."); TraceHelpers.TraceInfo("[timing]: {0}: Queue work {1} to occur asynchronously", DateTime.Now.Ticks, _taskIndex); - return Task.Factory.StartNew(s_baseWorkDelegate, this, new CancellationToken(), TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness, taskScheduler); + return Task.Factory.StartNew(s_baseWorkDelegate, this, CancellationToken.None, TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness, taskScheduler); } //----------------------------------------------------------------------------------- diff --git a/src/libraries/System.Linq/src/System/Linq/Concat.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/Concat.SpeedOpt.cs index 6bbfc46..b803ea0 100644 --- a/src/libraries/System.Linq/src/System/Linq/Concat.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/Concat.SpeedOpt.cs @@ -104,7 +104,7 @@ namespace System.Linq Debug.Assert(!_hasOnlyCollections); var builder = new SparseArrayBuilder(initialize: true); - var deferredCopies = new ArrayBuilder(); + ArrayBuilder deferredCopies = default; for (int i = 0; ; i++) { diff --git a/src/libraries/System.Linq/src/System/Linq/SelectMany.SpeedOpt.cs b/src/libraries/System.Linq/src/System/Linq/SelectMany.SpeedOpt.cs index 15ed767..62354cd 100644 --- a/src/libraries/System.Linq/src/System/Linq/SelectMany.SpeedOpt.cs +++ b/src/libraries/System.Linq/src/System/Linq/SelectMany.SpeedOpt.cs @@ -33,7 +33,7 @@ namespace System.Linq public TResult[] ToArray() { var builder = new SparseArrayBuilder(initialize: true); - var deferredCopies = new ArrayBuilder>(); + ArrayBuilder> deferredCopies = default; foreach (TSource element in _source) { diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCertificateHelper.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCertificateHelper.cs index a2417e8..2cb6775 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCertificateHelper.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpCertificateHelper.cs @@ -54,11 +54,11 @@ namespace System.Net.Http // Verify the hostName matches the certificate. unsafe { - var cppStruct = new Interop.Crypt32.CERT_CHAIN_POLICY_PARA(); + Interop.Crypt32.CERT_CHAIN_POLICY_PARA cppStruct = default; cppStruct.cbSize = (uint)sizeof(Interop.Crypt32.CERT_CHAIN_POLICY_PARA); cppStruct.dwFlags = 0; - var eppStruct = new Interop.Crypt32.SSL_EXTRA_CERT_CHAIN_POLICY_PARA(); + Interop.Crypt32.SSL_EXTRA_CERT_CHAIN_POLICY_PARA eppStruct = default; eppStruct.cbSize = (uint)sizeof(Interop.Crypt32.SSL_EXTRA_CERT_CHAIN_POLICY_PARA); eppStruct.dwAuthType = Interop.Crypt32.AuthType.AUTHTYPE_SERVER; @@ -71,7 +71,7 @@ namespace System.Net.Http Interop.Crypt32.CertChainPolicyIgnoreFlags.CERT_CHAIN_POLICY_IGNORE_ALL & ~Interop.Crypt32.CertChainPolicyIgnoreFlags.CERT_CHAIN_POLICY_IGNORE_INVALID_NAME_FLAG; - var status = new Interop.Crypt32.CERT_CHAIN_POLICY_STATUS(); + Interop.Crypt32.CERT_CHAIN_POLICY_STATUS status = default; status.cbSize = (uint)sizeof(Interop.Crypt32.CERT_CHAIN_POLICY_STATUS); if (Interop.Crypt32.CertVerifyCertificateChainPolicy( (IntPtr)Interop.Crypt32.CertChainPolicy.CERT_CHAIN_POLICY_SSL, diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs index cea24d3..13034a2 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs @@ -1027,7 +1027,7 @@ namespace System.Net.Http if (state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseCustomProxy || state.WindowsProxyUsePolicy == WindowsProxyUsePolicy.UseWinInetProxy) { - var proxyInfo = new Interop.WinHttp.WINHTTP_PROXY_INFO(); + Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo = default; bool updateProxySettings = false; Uri uri = state.RequestMessage.RequestUri; diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinInetProxyHelper.cs b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinInetProxyHelper.cs index f677d10..ff1b71e 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinInetProxyHelper.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinInetProxyHelper.cs @@ -22,7 +22,7 @@ namespace System.Net.Http public WinInetProxyHelper() { - var proxyConfig = new Interop.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG(); + Interop.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig = default; try { diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs index 8b440de..9340e4a 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/ConnectHelper.cs @@ -90,7 +90,7 @@ namespace System.Net.Http public void Initialize(CancellationToken cancellationToken) { CancellationToken = cancellationToken; - var b = new AsyncTaskMethodBuilder(); + AsyncTaskMethodBuilder b = default; _ = b.Task; // force initialization Builder = b; } diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/FailedProxyCache.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/FailedProxyCache.cs index 7d56346..43cc034 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/FailedProxyCache.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/FailedProxyCache.cs @@ -36,7 +36,7 @@ namespace System.Net.Http // This lock can be folded into _nextFlushTicks for space optimization, but // this class should only have a single instance so would rather have clarity. - private SpinLock _flushLock = new SpinLock(); + private SpinLock _flushLock = new SpinLock(enableThreadOwnerTracking: false); // mutable struct; do not make this readonly /// /// Checks when a proxy will become usable. diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs index a5158e3..3434641 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpWindowsProxy.cs @@ -198,7 +198,7 @@ namespace System.Net.Http // won't actually discover a PAC file on the network since WPAD protocol isn't configured. if (_proxyHelper.AutoSettingsUsed && !_proxyHelper.RecentAutoDetectionFailure) { - var proxyInfo = new Interop.WinHttp.WINHTTP_PROXY_INFO(); + Interop.WinHttp.WINHTTP_PROXY_INFO proxyInfo = default; try { if (_proxyHelper.GetProxyForUrl(_sessionHandle, uri, out proxyInfo)) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/MacProxy.cs b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/MacProxy.cs index 1e19e91..6c6243d 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/MacProxy.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/MacProxy.cs @@ -62,7 +62,7 @@ namespace System.Net.Http CFRunLoopStop(runLoop); }; - var clientContext = new CFStreamClientContext(); + CFStreamClientContext clientContext = default; CFRunLoopSourceRef loopSource = proxy.ProxyType == CFProxy.kCFProxyTypeAutoConfigurationURL ? CFNetworkExecuteProxyAutoConfigurationURL(proxy.AutoConfigurationURL, cfurl, cb, ref clientContext) : diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs index f091e8b..08fe539 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs @@ -124,8 +124,7 @@ namespace System.Net { ValidateV2Property(); // CheckDispose and initilize HttpListener in the case of app.config timeouts - Interop.HttpApi.HTTP_TIMEOUT_LIMIT_INFO timeoutinfo = - new Interop.HttpApi.HTTP_TIMEOUT_LIMIT_INFO(); + Interop.HttpApi.HTTP_TIMEOUT_LIMIT_INFO timeoutinfo = default; timeoutinfo.Flags = Interop.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT; timeoutinfo.DrainEntityBody = @@ -345,7 +344,7 @@ namespace System.Net // Set the association between request queue and url group. After this, requests for registered urls will // get delivered to this request queue. // - Interop.HttpApi.HTTP_BINDING_INFO info = new Interop.HttpApi.HTTP_BINDING_INFO(); + Interop.HttpApi.HTTP_BINDING_INFO info = default; info.Flags = Interop.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT; info.RequestQueueHandle = DangerousGetHandle(); @@ -366,7 +365,7 @@ namespace System.Net // is fine since http.sys allows to set HttpServerBindingProperty multiple times for valid // Url groups. // - Interop.HttpApi.HTTP_BINDING_INFO info = new Interop.HttpApi.HTTP_BINDING_INFO(); + Interop.HttpApi.HTTP_BINDING_INFO info = default; info.Flags = Interop.HttpApi.HTTP_FLAGS.NONE; info.RequestQueueHandle = IntPtr.Zero; @@ -1676,8 +1675,8 @@ namespace System.Net private void SendError(ulong requestId, HttpStatusCode httpStatusCode, ArrayList challenges) { if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"RequestId: {requestId}"); - Interop.HttpApi.HTTP_RESPONSE httpResponse = new Interop.HttpApi.HTTP_RESPONSE(); - httpResponse.Version = new Interop.HttpApi.HTTP_VERSION(); + Interop.HttpApi.HTTP_RESPONSE httpResponse = default; + httpResponse.Version = default; httpResponse.Version.MajorVersion = (ushort)1; httpResponse.Version.MinorVersion = (ushort)1; httpResponse.StatusCode = (ushort)httpStatusCode; @@ -1699,8 +1698,8 @@ namespace System.Net httpResponse.Headers.UnknownHeaderCount = checked((ushort)(challenges == null ? 0 : challenges.Count)); GCHandle[] challengeHandles = null; Interop.HttpApi.HTTP_UNKNOWN_HEADER[] headersArray = null; - GCHandle headersArrayHandle = new GCHandle(); - GCHandle wwwAuthenticateHandle = new GCHandle(); + GCHandle headersArrayHandle = default; + GCHandle wwwAuthenticateHandle = default; if (httpResponse.Headers.UnknownHeaderCount > 0) { challengeHandles = new GCHandle[httpResponse.Headers.UnknownHeaderCount]; @@ -1924,7 +1923,7 @@ namespace System.Net { int oldValue; - SpinWait spin = new SpinWait(); + SpinWait spin = default; while ((oldValue = Interlocked.CompareExchange(ref _ownershipState, 1, 0)) == 2) { // Must block until it equals 3 - we must be in the callback right now. diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerRequest.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerRequest.Windows.cs index 339db8a..19b8975 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerRequest.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerRequest.Windows.cs @@ -148,7 +148,7 @@ namespace System.Net { get { - Guid guid = new Guid(); + Guid guid = default; *(1 + (ulong*)&guid) = RequestId; return guid; } diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerResponse.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerResponse.Windows.cs index 4386639..5e75832 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerResponse.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerResponse.Windows.cs @@ -32,7 +32,7 @@ namespace System.Net internal HttpListenerResponse() { if (NetEventSource.IsEnabled) NetEventSource.Info(this); - _nativeResponse = new Interop.HttpApi.HTTP_RESPONSE(); + _nativeResponse = default; _nativeResponse.StatusCode = (ushort)HttpStatusCode.OK; _nativeResponse.Version.MajorVersion = 1; _nativeResponse.Version.MinorVersion = 1; @@ -64,7 +64,7 @@ namespace System.Net public void CopyFrom(HttpListenerResponse templateResponse) { if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"templateResponse {templateResponse}"); - _nativeResponse = new Interop.HttpApi.HTTP_RESPONSE(); + _nativeResponse = default; _responseState = ResponseState.Created; _webHeaders = templateResponse._webHeaders; _boundaryType = templateResponse._boundaryType; diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStream.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStream.Windows.cs index 84e3408..db4575c 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStream.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStream.Windows.cs @@ -93,7 +93,7 @@ namespace System.Net pBuffer = (byte*)pBufferAsIntPtr; offset = 0; } - Interop.HttpApi.HTTP_DATA_CHUNK dataChunk = new Interop.HttpApi.HTTP_DATA_CHUNK(); + Interop.HttpApi.HTTP_DATA_CHUNK dataChunk = default; dataChunk.DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; dataChunk.pBuffer = (byte*)(pBuffer + offset); dataChunk.BufferLength = dataToWrite; @@ -316,7 +316,7 @@ namespace System.Net Interop.HttpApi.HTTP_DATA_CHUNK* pDataChunk = null; if (_httpContext.Response.BoundaryType == BoundaryType.Chunked) { - Interop.HttpApi.HTTP_DATA_CHUNK dataChunk = new Interop.HttpApi.HTTP_DATA_CHUNK(); + Interop.HttpApi.HTTP_DATA_CHUNK dataChunk = default; dataChunk.DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; dataChunk.pBuffer = (byte*)pBuffer; dataChunk.BufferLength = (uint)s_chunkTerminator.Length; diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStreamAsyncResult.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStreamAsyncResult.cs index 7d1c342..cb4069a 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStreamAsyncResult.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpResponseStreamAsyncResult.cs @@ -139,19 +139,19 @@ namespace System.Net { chunkHeaderBuffer = GetChunkHeader(size, out chunkHeaderOffset); - _dataChunks[0] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[0] = default; _dataChunks[0].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; _dataChunks[0].BufferLength = (uint)(chunkHeaderBuffer.Length - chunkHeaderOffset); objectsToPin[0] = chunkHeaderBuffer; - _dataChunks[1] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[1] = default; _dataChunks[1].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; _dataChunks[1].BufferLength = (uint)size; objectsToPin[1] = buffer; - _dataChunks[2] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[2] = default; _dataChunks[2].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; _dataChunks[2].BufferLength = (uint)s_CRLFArray.Length; @@ -159,7 +159,7 @@ namespace System.Net } else { - _dataChunks[0] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[0] = default; _dataChunks[0].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; _dataChunks[0].BufferLength = (uint)size; 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 6e7a1ff..1fdd601 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 @@ -1998,7 +1998,7 @@ namespace System.Net.WebSockets } Interop.WebSocket.Buffer payloadBuffer; - payloadBuffer = new Interop.WebSocket.Buffer(); + payloadBuffer = default; _webSocket._internalBuffer.PinSendBuffer(buffer.Value, out _BufferHasBeenPinned); payloadBuffer.Data.BufferData = _webSocket._internalBuffer.ConvertPinnedSendPayloadToNative(buffer.Value); payloadBuffer.Data.BufferLength = (uint)buffer.Value.Count; @@ -2074,7 +2074,7 @@ namespace System.Net.WebSockets return null; } - Interop.WebSocket.Buffer payloadBuffer = new Interop.WebSocket.Buffer(); + Interop.WebSocket.Buffer payloadBuffer = default; if (CloseReason != null) { byte[] blob = Encoding.UTF8.GetBytes(CloseReason); diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs index 54c98bd..6ce5d7e 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/WebSockets/WebSocketHttpListenerDuplexStream.cs @@ -133,7 +133,7 @@ namespace System.Net.WebSockets NetEventSource.Enter(this, HttpWebSocket.GetTraceMsgForParameters(offset, count, cancellationToken)); } - CancellationTokenRegistration cancellationTokenRegistration = new CancellationTokenRegistration(); + CancellationTokenRegistration cancellationTokenRegistration = default; int bytesRead = 0; try @@ -357,7 +357,7 @@ namespace System.Net.WebSockets NetEventSource.Enter(this); } - CancellationTokenRegistration cancellationTokenRegistration = new CancellationTokenRegistration(); + CancellationTokenRegistration cancellationTokenRegistration = default; try { @@ -419,7 +419,7 @@ namespace System.Net.WebSockets NetEventSource.Enter(this, HttpWebSocket.GetTraceMsgForParameters(offset, count, cancellationToken)); } - CancellationTokenRegistration cancellationTokenRegistration = new CancellationTokenRegistration(); + CancellationTokenRegistration cancellationTokenRegistration = default; try { @@ -608,7 +608,7 @@ namespace System.Net.WebSockets NetEventSource.Enter(this); } - CancellationTokenRegistration cancellationTokenRegistration = new CancellationTokenRegistration(); + CancellationTokenRegistration cancellationTokenRegistration = default; try { @@ -1097,9 +1097,9 @@ namespace System.Net.WebSockets { _dataChunks = new Interop.HttpApi.HTTP_DATA_CHUNK[2]; _dataChunksGCHandle = GCHandle.Alloc(_dataChunks, GCHandleType.Pinned); - _dataChunks[0] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[0] = default; _dataChunks[0].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; - _dataChunks[1] = new Interop.HttpApi.HTTP_DATA_CHUNK(); + _dataChunks[1] = default; _dataChunks[1].DataChunkType = Interop.HttpApi.HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory; } diff --git a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpReplyReaderFactory.cs b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpReplyReaderFactory.cs index 9f899fe..833a5f8 100644 --- a/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpReplyReaderFactory.cs +++ b/src/libraries/System.Net.Mail/src/System/Net/Mail/SmtpReplyReaderFactory.cs @@ -98,7 +98,7 @@ namespace System.Net.Mail { return info[0]; } - return new LineInfo(); + return default; } internal SmtpReplyReader GetNextReplyReader() @@ -296,7 +296,7 @@ namespace System.Net.Mail { return info[0]; } - return new LineInfo(); + return default; } internal LineInfo[] ReadLines(SmtpReplyReader caller) diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs index b5187e1..cf0655c 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs @@ -124,7 +124,7 @@ namespace System.Net.NetworkInformation { Debug.Assert(s_dynamicStoreRef == null); - var storeContext = new Interop.SystemConfiguration.SCDynamicStoreContext(); + Interop.SystemConfiguration.SCDynamicStoreContext storeContext = default; using (SafeCreateHandle storeName = Interop.CoreFoundation.CFStringCreateWithCString("NetworkAddressChange.OSX")) { s_dynamicStoreRef = Interop.SystemConfiguration.SCDynamicStoreCreate( diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalStatistics.cs index 385ace9..3b4e464 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPGlobalStatistics.cs @@ -9,7 +9,7 @@ namespace System.Net.NetworkInformation /// IP statistics. internal class SystemIPGlobalStatistics : IPGlobalStatistics { - private readonly Interop.IpHlpApi.MibIpStats _stats = new Interop.IpHlpApi.MibIpStats(); + private readonly Interop.IpHlpApi.MibIpStats _stats = default; private SystemIPGlobalStatistics() { } diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceStatistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceStatistics.cs index 4808c20..005971e 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceStatistics.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIPInterfaceStatistics.cs @@ -39,7 +39,7 @@ namespace System.Net.NetworkInformation internal static Interop.IpHlpApi.MibIfRow2 GetIfEntry2(long index) { - Interop.IpHlpApi.MibIfRow2 ifRow = new Interop.IpHlpApi.MibIfRow2(); + Interop.IpHlpApi.MibIfRow2 ifRow = default; if (index == 0) { return ifRow; diff --git a/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs b/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs index 5db20f6..7671efc 100644 --- a/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs +++ b/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs @@ -200,7 +200,7 @@ namespace System.Net { if (NetEventSource.IsEnabled) NetEventSource.Enter(chainContext, cpp.dwFlags); - var status = new Interop.Crypt32.CERT_CHAIN_POLICY_STATUS(); + Interop.Crypt32.CERT_CHAIN_POLICY_STATUS status = default; status.cbSize = (uint)sizeof(Interop.Crypt32.CERT_CHAIN_POLICY_STATUS); bool errorCode = diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/ReceiveMessageOverlappedAsyncResult.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/ReceiveMessageOverlappedAsyncResult.Windows.cs index 2c9f22c..003fb24 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/ReceiveMessageOverlappedAsyncResult.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/ReceiveMessageOverlappedAsyncResult.Windows.cs @@ -104,7 +104,7 @@ namespace System.Net.Sockets else { // Other - _ipPacketInformation = new IPPacketInformation(); + _ipPacketInformation = default; } } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SafeSocketHandle.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SafeSocketHandle.cs index d662eae..e39df10 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SafeSocketHandle.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SafeSocketHandle.cs @@ -100,7 +100,7 @@ namespace System.Net.Sockets bool canceledOperations = false; // Wait until it's safe. - SpinWait sw = new SpinWait(); + SpinWait sw = default; while (!_released) { // The socket was not released due to the SafeHandle being used. diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs index 893a173..6901197 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncContext.Unix.cs @@ -202,7 +202,7 @@ namespace System.Net.Sockets CancellationRegistration.Dispose(); // Try to transition from Waiting to Cancelled - var spinWait = new SpinWait(); + SpinWait spinWait = default; bool keepWaiting = true; while (keepWaiting) { diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs index c3233b5..29a0226 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEventArgs.Windows.cs @@ -1192,7 +1192,7 @@ namespace System.Net.Sockets // The operation could complete so quickly that it races with the code // initiating it. Wait until that initiation code has completed before // we try to undo the state it configures. - var sw = new SpinWait(); + SpinWait sw = default; while (_singleBufferHandleState == SingleBufferHandleState.InProcess) { sw.SpinOnce(); @@ -1233,7 +1233,7 @@ namespace System.Net.Sockets else { // Other. - _receiveMessageFromPacketInfo = new IPPacketInformation(); + _receiveMessageFromPacketInfo = default; } } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs index a795b77..0946c9b 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Unix.cs @@ -1405,7 +1405,7 @@ namespace System.Net.Sockets public static unsafe SocketError GetLingerOption(SafeSocketHandle handle, out LingerOption optionValue) { - var opt = new Interop.Sys.LingerOption(); + Interop.Sys.LingerOption opt = default; Interop.Error err = Interop.Sys.GetLingerOption(handle, &opt); if (err != Interop.Error.SUCCESS) { diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs index a66979b..dad69e9 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs @@ -545,7 +545,7 @@ namespace System.Net.Sockets public static SocketError SetMulticastOption(SafeSocketHandle handle, SocketOptionName optionName, MulticastOption optionValue) { - Interop.Winsock.IPMulticastRequest ipmr = new Interop.Winsock.IPMulticastRequest(); + Interop.Winsock.IPMulticastRequest ipmr = default; #pragma warning disable CS0618 // Address is marked obsolete ipmr.MulticastAddress = unchecked((int)optionValue.Group.Address); @@ -590,7 +590,7 @@ namespace System.Net.Sockets public static SocketError SetIPv6MulticastOption(SafeSocketHandle handle, SocketOptionName optionName, IPv6MulticastOption optionValue) { - Interop.Winsock.IPv6MulticastRequest ipmr = new Interop.Winsock.IPv6MulticastRequest(); + Interop.Winsock.IPv6MulticastRequest ipmr = default; ipmr.MulticastAddress = optionValue.Group.GetAddressBytes(); ipmr.InterfaceIndex = unchecked((int)optionValue.InterfaceIndex); @@ -607,7 +607,7 @@ namespace System.Net.Sockets public static SocketError SetLingerOption(SafeSocketHandle handle, LingerOption optionValue) { - Interop.Winsock.Linger lngopt = new Interop.Winsock.Linger(); + Interop.Winsock.Linger lngopt = default; lngopt.OnOff = optionValue.Enabled ? (ushort)1 : (ushort)0; lngopt.Time = (ushort)optionValue.LingerTime; @@ -666,7 +666,7 @@ namespace System.Net.Sockets public static SocketError GetMulticastOption(SafeSocketHandle handle, SocketOptionName optionName, out MulticastOption optionValue) { - Interop.Winsock.IPMulticastRequest ipmr = new Interop.Winsock.IPMulticastRequest(); + Interop.Winsock.IPMulticastRequest ipmr = default; int optlen = Interop.Winsock.IPMulticastRequest.Size; // This can throw ObjectDisposedException. @@ -703,7 +703,7 @@ namespace System.Net.Sockets public static SocketError GetIPv6MulticastOption(SafeSocketHandle handle, SocketOptionName optionName, out IPv6MulticastOption optionValue) { - Interop.Winsock.IPv6MulticastRequest ipmr = new Interop.Winsock.IPv6MulticastRequest(); + Interop.Winsock.IPv6MulticastRequest ipmr = default; int optlen = Interop.Winsock.IPv6MulticastRequest.Size; @@ -727,7 +727,7 @@ namespace System.Net.Sockets public static SocketError GetLingerOption(SafeSocketHandle handle, out LingerOption optionValue) { - Interop.Winsock.Linger lngopt = new Interop.Winsock.Linger(); + Interop.Winsock.Linger lngopt = default; int optlen = 4; // This can throw ObjectDisposedException. @@ -757,7 +757,7 @@ namespace System.Net.Sockets IntPtr rawHandle = handle.DangerousGetHandle(); IntPtr* fileDescriptorSet = stackalloc IntPtr[2] { (IntPtr)1, rawHandle }; - Interop.Winsock.TimeValue IOwait = new Interop.Winsock.TimeValue(); + Interop.Winsock.TimeValue IOwait = default; // A negative timeout value implies an indefinite wait. int socketCount; @@ -853,7 +853,7 @@ namespace System.Net.Sockets { if (microseconds != -1) { - Interop.Winsock.TimeValue IOwait = new Interop.Winsock.TimeValue(); + Interop.Winsock.TimeValue IOwait = default; MicrosecondsToTimeValue((long)(uint)microseconds, ref IOwait); socketCount = diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerReadContextComplexJson.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerReadContextComplexJson.cs index 35d9015..1e91ad1 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerReadContextComplexJson.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerReadContextComplexJson.cs @@ -22,7 +22,7 @@ namespace System.Runtime.Serialization.Json private readonly bool _useSimpleDictionaryFormat; public XmlObjectSerializerReadContextComplexJson(DataContractJsonSerializer serializer, DataContract rootTypeDataContract) - : base(null, int.MaxValue, new StreamingContext(), true) + : base(null, int.MaxValue, default(StreamingContext), true) { this.rootTypeDataContract = rootTypeDataContract; this.serializerKnownTypeList = serializer.KnownTypes; @@ -30,7 +30,7 @@ namespace System.Runtime.Serialization.Json } internal XmlObjectSerializerReadContextComplexJson(DataContractJsonSerializerImpl serializer, DataContract rootTypeDataContract) - : base(serializer, serializer.MaxItemsInObjectGraph, new StreamingContext(), false) + : base(serializer, serializer.MaxItemsInObjectGraph, default(StreamingContext), false) { this.rootTypeDataContract = rootTypeDataContract; this.serializerKnownTypeList = serializer.knownTypeList; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerWriteContextComplexJson.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerWriteContextComplexJson.cs index ce19246..b116f64 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerWriteContextComplexJson.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/Json/XmlObjectSerializerWriteContextComplexJson.cs @@ -21,7 +21,7 @@ namespace System.Runtime.Serialization.Json private readonly bool _useSimpleDictionaryFormat; public XmlObjectSerializerWriteContextComplexJson(DataContractJsonSerializer serializer, DataContract rootTypeDataContract) - : base(null, int.MaxValue, new StreamingContext(), true) + : base(null, int.MaxValue, default(StreamingContext), true) { _jsonSerializer = serializer; @@ -40,7 +40,7 @@ namespace System.Runtime.Serialization.Json } internal XmlObjectSerializerWriteContextComplexJson(DataContractJsonSerializerImpl serializer, DataContract rootTypeDataContract) - : base(serializer, serializer.MaxItemsInObjectGraph, new StreamingContext(), false) + : base(serializer, serializer.MaxItemsInObjectGraph, default(StreamingContext), false) { _emitXsiType = serializer.EmitTypeInformation; this.rootTypeDataContract = rootTypeDataContract; diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerContext.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerContext.cs index 9328579..5912642 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerContext.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerContext.cs @@ -20,7 +20,7 @@ namespace System.Runtime.Serialization { protected XmlObjectSerializer serializer; protected DataContract rootTypeDataContract; - internal ScopedKnownTypes scopedKnownTypes = new ScopedKnownTypes(); + internal ScopedKnownTypes scopedKnownTypes; protected DataContractDictionary serializerKnownDataContracts; private bool _isSerializerKnownDataContractsSetExplicit; protected IList serializerKnownTypeList; @@ -50,7 +50,7 @@ namespace System.Runtime.Serialization internal XmlObjectSerializerContext(DataContractSerializer serializer, DataContract rootTypeDataContract, DataContractResolver dataContractResolver) : this(serializer, serializer.MaxItemsInObjectGraph, - new StreamingContext(), + default(StreamingContext), serializer.IgnoreExtensionDataObject, dataContractResolver ) diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs index 7e6edc9..0993590 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlObjectSerializerWriteContext.cs @@ -24,7 +24,7 @@ namespace System.Runtime.Serialization internal class XmlObjectSerializerWriteContext : XmlObjectSerializerContext #endif { - private ObjectReferenceStack _byValObjectsInScope = new ObjectReferenceStack(); + private ObjectReferenceStack _byValObjectsInScope; private XmlSerializableWriter _xmlSerializableWriter; private const int depthToCheckCyclicReference = 512; private ObjectToIdCache _serializedObjects; diff --git a/src/libraries/System.Private.Uri/src/System/Uri.cs b/src/libraries/System.Private.Uri/src/System/Uri.cs index 39f42cd..2416926 100644 --- a/src/libraries/System.Private.Uri/src/System/Uri.cs +++ b/src/libraries/System.Private.Uri/src/System/Uri.cs @@ -842,7 +842,7 @@ namespace System } else { - var pathSegments = new ArrayBuilder(); + ArrayBuilder pathSegments = default; int current = 0; while (current < path.Length) { diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs index 31c5801..19e7202 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XContainer.cs @@ -904,8 +904,8 @@ namespace System.Xml.Linq private sealed class ContentReader { - private readonly NamespaceCache _eCache = new NamespaceCache(); - private readonly NamespaceCache _aCache = new NamespaceCache(); + private readonly NamespaceCache _eCache; + private readonly NamespaceCache _aCache; private readonly IXmlLineInfo _lineInfo; private XContainer _currentContainer; private string _baseUri; diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs index 8c5102a..5ccbf7e 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XElement.cs @@ -844,7 +844,7 @@ namespace System.Xml.Linq { if (await reader.MoveToContentAsync().ConfigureAwait(false) != XmlNodeType.Element) throw new InvalidOperationException(SR.Format(SR.InvalidOperation_ExpectedNodeType, XmlNodeType.Element, reader.NodeType)); - XElement e = new XElement(new AsyncConstructionSentry()); + XElement e = new XElement(default(AsyncConstructionSentry)); await e.ReadElementFromAsync(reader, options, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs index 1f6fa3b..46f7068 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XLinq.cs @@ -201,7 +201,7 @@ namespace System.Xml.Linq public ElementWriter(XmlWriter writer) { _writer = writer; - _resolver = new NamespaceResolver(); + _resolver = default; } public void WriteElement(XElement e) @@ -535,7 +535,7 @@ namespace System.Xml.Linq _writer = w; _element = null; _attributes = new List(); - _resolver = new NamespaceResolver(); + _resolver = default; } private void FlushElement() diff --git a/src/libraries/System.Private.Xml.Linq/src/System/Xml/XPath/XNodeNavigator.cs b/src/libraries/System.Private.Xml.Linq/src/System/Xml/XPath/XNodeNavigator.cs index 7b5a4eb..e45c917 100644 --- a/src/libraries/System.Private.Xml.Linq/src/System/Xml/XPath/XNodeNavigator.cs +++ b/src/libraries/System.Private.Xml.Linq/src/System/Xml/XPath/XNodeNavigator.cs @@ -948,7 +948,7 @@ namespace System.Xml.XPath public static object XPathEvaluate(this XNode node, string expression, IXmlNamespaceResolver resolver) { if (node == null) throw new ArgumentNullException(nameof(node)); - return new XPathEvaluator().Evaluate(node, expression, resolver); + return default(XPathEvaluator).Evaluate(node, expression, resolver); } /// @@ -997,7 +997,7 @@ namespace System.Xml.XPath public static IEnumerable XPathSelectElements(this XNode node, string expression, IXmlNamespaceResolver resolver) { if (node == null) throw new ArgumentNullException(nameof(node)); - return (IEnumerable)new XPathEvaluator().Evaluate(node, expression, resolver); + return (IEnumerable)default(XPathEvaluator).Evaluate(node, expression, resolver); } private static XText CalibrateText(XText n) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs index bd30e49..edfd33e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/ContentValidator.cs @@ -1869,7 +1869,7 @@ namespace System.Xml.Schema runningPositions = new List(); context.RunningPositions = runningPositions; } - RangePositionInfo rposInfo = new RangePositionInfo(); + RangePositionInfo rposInfo = default; rposInfo.curpos = _firstpos.Clone(); rposInfo.rangeCounters = new decimal[_minMaxNodesCount]; @@ -1987,8 +1987,8 @@ namespace System.Xml.Schema rposInfo = runningPositions[j]; if (matchCount + 2 >= runningPositions.Count) { - runningPositions.Add(new RangePositionInfo()); - runningPositions.Add(new RangePositionInfo()); + runningPositions.Add(default(RangePositionInfo)); + runningPositions.Add(default(RangePositionInfo)); } RangePositionInfo newRPosInfo = runningPositions[matchCount]; if (newRPosInfo.rangeCounters == null) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs index 8949e58..c071cda 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlSchemaSet.cs @@ -368,7 +368,7 @@ namespace System.Xml.Schema bool schemasLockObtained = false; try { - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (true) { Monitor.TryEnter(InternalSyncObject, ref thisLockObtained); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs index 09456ad..2707825 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDateTime.cs @@ -137,7 +137,7 @@ namespace System.Xml.Schema /// public XsdDateTime(string text, XsdDateTimeFlags kinds) : this() { - Parser parser = new Parser(); + Parser parser = default; if (!parser.Parse(text, kinds)) { throw new FormatException(SR.Format(SR.XmlConvert_BadFormat, text, kinds)); @@ -162,10 +162,10 @@ namespace System.Xml.Schema internal static bool TryParse(string text, XsdDateTimeFlags kinds, out XsdDateTime result) { - Parser parser = new Parser(); + Parser parser = default; if (!parser.Parse(text, kinds)) { - result = new XsdDateTime(); + result = default; return false; } result = new XsdDateTime(parser); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs index 8ab5bf6..9a73084 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XsdDuration.cs @@ -438,7 +438,7 @@ namespace System.Xml.Schema int value, pos, numDigits; Parts parts = Parts.HasNone; - result = new XsdDuration(); + result = default; s = s.Trim(); length = s.Length; 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 0ef7265..b50d640 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 @@ -968,7 +968,7 @@ namespace System.Xml.Serialization char[] chars = value.ToCharArray(); int charsLength = chars.Length; - SoapArrayInfo soapArrayInfo = new SoapArrayInfo(); + SoapArrayInfo soapArrayInfo = default; // Parse backwards to get length first, then optional dimensions, then qname. int pos = charsLength - 1; @@ -1039,7 +1039,7 @@ namespace System.Xml.Serialization private SoapArrayInfo ParseSoap12ArrayType(string itemType, string arraySize) { - SoapArrayInfo soapArrayInfo = new SoapArrayInfo(); + SoapArrayInfo soapArrayInfo = default; if (itemType != null && itemType.Length > 0) soapArrayInfo.qname = itemType; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs index dc2dffe..b68eaa4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializer.cs @@ -125,7 +125,7 @@ namespace System.Xml.Serialization #pragma warning restore 0414 private readonly Type _primitiveType; private XmlMapping _mapping; - private XmlDeserializationEvents _events = new XmlDeserializationEvents(); + private XmlDeserializationEvents _events; internal string DefaultNamespace = null; private Type _rootType; private bool _isReflectionBasedSerializer = false; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs index 191ff57..9c8ae17 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/IteratorDescriptor.cs @@ -58,7 +58,7 @@ namespace System.Xml.Xsl.IlGen /// public static StorageDescriptor None() { - return new StorageDescriptor(); + return default; } /// @@ -66,7 +66,7 @@ namespace System.Xml.Xsl.IlGen /// public static StorageDescriptor Stack(Type itemStorageType, bool isCached) { - StorageDescriptor storage = new StorageDescriptor(); + StorageDescriptor storage = default; storage._location = ItemLocation.Stack; storage._itemStorageType = itemStorageType; storage._isCached = isCached; @@ -78,7 +78,7 @@ namespace System.Xml.Xsl.IlGen /// public static StorageDescriptor Parameter(int paramIndex, Type itemStorageType, bool isCached) { - StorageDescriptor storage = new StorageDescriptor(); + StorageDescriptor storage = default; storage._location = ItemLocation.Parameter; storage._locationObject = paramIndex; storage._itemStorageType = itemStorageType; @@ -95,7 +95,7 @@ namespace System.Xml.Xsl.IlGen typeof(IList<>).MakeGenericType(itemStorageType).IsAssignableFrom(loc.LocalType), "Type " + itemStorageType + " does not match the local variable's type"); - StorageDescriptor storage = new StorageDescriptor(); + StorageDescriptor storage = default; storage._location = ItemLocation.Local; storage._locationObject = loc; storage._itemStorageType = itemStorageType; @@ -111,7 +111,7 @@ namespace System.Xml.Xsl.IlGen Debug.Assert(locIter.LocalType.GetMethod("get_Current").ReturnType == itemStorageType, "Type " + itemStorageType + " does not match type of Current property."); - StorageDescriptor storage = new StorageDescriptor(); + StorageDescriptor storage = default; storage._location = ItemLocation.Current; storage._locationObject = locIter; storage._itemStorageType = itemStorageType; @@ -127,7 +127,7 @@ namespace System.Xml.Xsl.IlGen typeof(IList<>).MakeGenericType(itemStorageType).IsAssignableFrom(methGlobal.ReturnType), "Type " + itemStorageType + " does not match the global method's return type"); - StorageDescriptor storage = new StorageDescriptor(); + StorageDescriptor storage = default; storage._location = ItemLocation.Global; storage._locationObject = methGlobal; storage._itemStorageType = itemStorageType; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs index e16631c..9ad24cb 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlILOptimizerVisitor.cs @@ -1640,7 +1640,7 @@ namespace System.Xml.Xsl.IlGen if (AllowReplace(XmlILOptimization.EliminateStrConcat, local0)) { // Concatenate all constant arguments - StringConcat concat = new StringConcat(); + StringConcat concat = default; concat.Delimiter = local3; foreach (QilLiteral lit in local2) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs index 3d66fae..7abb98e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/IlGen/XmlIlVisitor.cs @@ -731,7 +731,7 @@ namespace System.Xml.Xsl.IlGen /// protected override QilNode VisitOr(QilBinary ndOr) { - Label lblTemp = new Label(); + Label lblTemp = default; // Visit left branch switch (_iterCurr.CurrentBranchingContext) @@ -819,7 +819,7 @@ namespace System.Xml.Xsl.IlGen /// protected override QilNode VisitNot(QilUnary ndNot) { - Label lblTemp = new Label(); + Label lblTemp = default; // Visit operand // Reverse branch types @@ -1153,7 +1153,7 @@ namespace System.Xml.Xsl.IlGen private void Sequence(QilList ndSeq) { LocalBuilder locIdx, locList; - Label lblStart, lblNext, lblOnEnd = new Label(); + Label lblStart, lblNext, lblOnEnd = default; Label[] arrSwitchLabels; int i; Type itemStorageType = GetItemStorageType(ndSeq); @@ -4413,7 +4413,7 @@ namespace System.Xml.Xsl.IlGen // By default, do not create a new iteration label hasOnEnd = false; - lblOnEnd = new Label(); + lblOnEnd = default; // If loop is not involved in Xml construction, or if loop returns exactly one value, then do nothing if (!info.PushToWriterLast || nd.XmlType.IsSingleton) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs index 2e68c6d..107e045 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/TreeIterators.cs @@ -262,7 +262,7 @@ namespace System.Xml.Xsl.Runtime /// public void Create(XPathNavigator context, XmlNavigatorFilter filter, bool orSelf) { - AncestorIterator wrapped = new AncestorIterator(); + AncestorIterator wrapped = default; wrapped.Create(context, filter, orSelf); _stack.Reset(); @@ -602,7 +602,7 @@ namespace System.Xml.Xsl.Runtime /// public void Create(XPathNavigator context, XmlNavigatorFilter filter) { - XPathPrecedingDocOrderIterator wrapped = new XPathPrecedingDocOrderIterator(); + XPathPrecedingDocOrderIterator wrapped = default; wrapped.Create(context, filter); _stack.Reset(); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs index e484841..06a768a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Runtime/XmlCollation.cs @@ -161,7 +161,7 @@ namespace System.Xml.Xsl.Runtime Uri collationUri; CultureInfo cultInfo = null; - Options options = new Options(); + Options options = default; if (throwOnError) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs index e67b087..9c237b7 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGenerator.cs @@ -107,7 +107,7 @@ namespace System.Xml.Xsl.Xslt _invkGen = new InvokeGenerator(_f, debug); _matcherBuilder = new MatcherBuilder(_f, _refReplacer, _invkGen); _singlFocus = new SingletonFocus(_f); - _funcFocus = new FunctionFocus(); + _funcFocus = default; _curLoop = new LoopFocus(_f); _strConcat = new QilStrConcatenator(_f); _varHelper = new VariableHelper(_f); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs index 8074fb2..0739cef 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/QilGeneratorEnv.cs @@ -411,7 +411,7 @@ namespace System.Xml.Xsl.Xslt { string keyName = (QilLiteral)name; - _compiler.ParseQName(keyName, out string prefix, out string local, new ThrowErrorHelper()); + _compiler.ParseQName(keyName, out string prefix, out string local, default(ThrowErrorHelper)); string nsUri = ResolvePrefixThrow(/*ignoreDefaultNs:*/true, prefix); QilName qname = _f.QName(local, nsUri, prefix); @@ -643,7 +643,7 @@ namespace System.Xml.Xsl.Xslt private XmlQualifiedName ResolveQNameThrow(bool ignoreDefaultNs, QilNode qilName) { string name = (QilLiteral)qilName; - _compiler.ParseQName(name, out string prefix, out string local, new ThrowErrorHelper()); + _compiler.ParseQName(name, out string prefix, out string local, default(ThrowErrorHelper)); string nsUri = ResolvePrefixThrow(/*ignoreDefaultNs:*/ignoreDefaultNs, prefix); return new XmlQualifiedName(local, nsUri); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs index 51dfd4f..29573ca 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XslAstAnalyzer.cs @@ -1134,7 +1134,7 @@ namespace System.Xml.Xsl.Xslt funcFlags = XslFlags.AnyType; if (_compiler.Settings.EnableScript && ns != null) { - XmlExtensionFunction scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, new NullErrorHelper()); + XmlExtensionFunction scrFunc = _compiler.Scripts.ResolveFunction(name, ns, args.Count, default(NullErrorHelper)); if (scrFunc != null) { XmlQueryType xt = scrFunc.XmlReturnType; diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs index 1b248c3..182e7be 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltInput.cs @@ -266,7 +266,7 @@ namespace System.Xml.Xsl.Xslt } } - private StringConcat _strConcat = new StringConcat(); + private StringConcat _strConcat; // returns false if attribute is actualy namespace private bool ReadAttribute(ref Record rec) diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableByteArrayInterop.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableByteArrayInterop.cs index 02dc1ba..1eeac8b 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableByteArrayInterop.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/ImmutableByteArrayInterop.cs @@ -60,7 +60,7 @@ namespace System.Reflection.Internal byte[] givenArray = array; array = null; - var union = new ByteArrayUnion(); + ByteArrayUnion union = default; union.UnderlyingArray = givenArray; return union.ImmutableArray; } @@ -82,7 +82,7 @@ namespace System.Reflection.Internal /// The underlying array, or null if is true. internal static byte[] DangerousGetUnderlyingArray(ImmutableArray array) { - var union = new ByteArrayUnion(); + ByteArrayUnion union = default; union.ImmutableArray = array; return union.UnderlyingArray; } diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Modules/Ecma/EcmaModule.ManifestResources.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Modules/Ecma/EcmaModule.ManifestResources.cs index 50971d2..f12d586 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Modules/Ecma/EcmaModule.ManifestResources.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/Modules/Ecma/EcmaModule.ManifestResources.cs @@ -16,7 +16,7 @@ namespace System.Reflection.TypeLoading.Ecma { MetadataReader reader = Reader; - InternalManifestResourceInfo result = new InternalManifestResourceInfo(); + InternalManifestResourceInfo result = default; ManifestResourceHandleCollection manifestResources = reader.ManifestResources; foreach (ManifestResourceHandle resourceHandle in manifestResources) { diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.BindingFlags.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.BindingFlags.cs index 356acac..b5f4abf 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.BindingFlags.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/RuntimeTypeInfo.BindingFlags.cs @@ -17,7 +17,7 @@ namespace System.Reflection.TypeLoading Debug.Assert(types != null); QueryResult queryResult = Query(bindingAttr); - ListBuilder candidates = new ListBuilder(); + ListBuilder candidates = default; foreach (ConstructorInfo candidate in queryResult) { if (candidate.QualifiesBasedOnParameterCount(bindingAttr, callConvention, types)) @@ -81,7 +81,7 @@ namespace System.Reflection.TypeLoading { // Group #2: This group of api takes a set of parameter types and an optional binder. QueryResult queryResult = Query(name, bindingAttr); - ListBuilder candidates = new ListBuilder(); + ListBuilder candidates = default; foreach (MethodInfo candidate in queryResult) { if (genericParameterCount != GenericParameterCountAny && genericParameterCount != candidate.GetGenericParameterCount()) @@ -124,7 +124,7 @@ namespace System.Reflection.TypeLoading { // Group #2: This group of api takes a set of parameter types, a return type (both cannot be null) and an optional binder. QueryResult queryResult = Query(name, bindingAttr); - ListBuilder candidates = new ListBuilder(); + ListBuilder candidates = default; foreach (PropertyInfo candidate in queryResult) { if (types == null || (candidate.GetIndexParameters().Length == types.Length)) diff --git a/src/libraries/System.Runtime.Numerics/src/System/Globalization/FormatProvider.BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Globalization/FormatProvider.BigInteger.cs index 0bd585f..72df935 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Globalization/FormatProvider.BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Globalization/FormatProvider.BigInteger.cs @@ -15,7 +15,7 @@ namespace System.Globalization { fixed (char* overrideDigits = digits) { - var numberBuffer = new Number.NumberBuffer(); + Number.NumberBuffer numberBuffer = default; numberBuffer.overrideDigits = overrideDigits + startIndex; numberBuffer.precision = precision; numberBuffer.scale = scale; @@ -44,7 +44,7 @@ namespace System.Globalization out bool sign ) { - FormatProvider.Number.NumberBuffer numberBuffer = new FormatProvider.Number.NumberBuffer(); + FormatProvider.Number.NumberBuffer numberBuffer = default; unsafe { diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs index 4bf034d..492a405 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigNumber.cs @@ -296,7 +296,7 @@ namespace System.Numerics public static BigNumberBuffer Create() { - BigNumberBuffer number = new BigNumberBuffer(); + BigNumberBuffer number = default; number.digits = new StringBuilder(); return number; } diff --git a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Duration.cs b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Duration.cs index c49d840..b80b134 100644 --- a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Duration.cs +++ b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Duration.cs @@ -216,7 +216,7 @@ namespace Windows.UI.Xaml { get { - Duration duration = new Duration(); + Duration duration = default; duration._durationType = DurationType.Automatic; return duration; @@ -227,7 +227,7 @@ namespace Windows.UI.Xaml { get { - Duration duration = new Duration(); + Duration duration = default; duration._durationType = DurationType.Forever; return duration; diff --git a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/KeyTime.cs b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/KeyTime.cs index b2439d1..2942b2a 100644 --- a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/KeyTime.cs +++ b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/KeyTime.cs @@ -33,7 +33,7 @@ namespace Windows.UI.Xaml.Media.Animation throw new ArgumentOutOfRangeException(nameof(timeSpan)); } - KeyTime keyTime = new KeyTime(); + KeyTime keyTime = default; keyTime._timeSpan = timeSpan; diff --git a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/RepeatBehavior.cs b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/RepeatBehavior.cs index 26af935..c297e68 100644 --- a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/RepeatBehavior.cs +++ b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Animation/RepeatBehavior.cs @@ -67,7 +67,7 @@ namespace Windows.UI.Xaml.Media.Animation { get { - RepeatBehavior forever = new RepeatBehavior(); + RepeatBehavior forever = default; forever.Type = RepeatBehaviorType.Forever; return forever; diff --git a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Matrix.cs b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Matrix.cs index cfbb12f..2460c84 100644 --- a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Matrix.cs +++ b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Matrix.cs @@ -215,7 +215,7 @@ namespace Windows.UI.Xaml.Media private static Matrix CreateIdentity() { - Matrix matrix = new Matrix(); + Matrix matrix = default; matrix.SetMatrix(1, 0, 0, 1, 0, 0); diff --git a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Media3D/Matrix3D.cs b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Media3D/Matrix3D.cs index 9fee814..af001ab 100644 --- a/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Media3D/Matrix3D.cs +++ b/src/libraries/System.Runtime.WindowsRuntime.UI.Xaml/src/System/Windows/Media/Media3D/Matrix3D.cs @@ -498,7 +498,7 @@ namespace Windows.UI.Xaml.Media.Media3D public static Matrix3D operator *(Matrix3D matrix1, Matrix3D matrix2) { - Matrix3D matrix3D = new Matrix3D(); + Matrix3D matrix3D = default; matrix3D.M11 = matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21 + @@ -588,7 +588,7 @@ namespace Windows.UI.Xaml.Media.Media3D private static Matrix3D CreateIdentity() { - Matrix3D matrix3D = new Matrix3D(); + Matrix3D matrix3D = default; matrix3D.SetMatrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Rect.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Rect.cs index c133128..e4d6dbe 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Rect.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Rect.cs @@ -260,7 +260,7 @@ namespace Windows.Foundation private static Rect CreateEmptyRect() { - Rect rect = new Rect(); + Rect rect = default; // TODO: for consistency with width/height we should change these // to assign directly to the backing fields. diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Size.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Size.cs index efb12f3..b0c6cde 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Size.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/Size.cs @@ -84,7 +84,7 @@ namespace Windows.Foundation private static Size CreateEmptySize() { - Size size = new Size(); + Size size = default; // We can't set these via the property setters because negatives widths // are rejected in those APIs. size._width = float.NegativeInfinity; diff --git a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/UI/Color.cs b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/UI/Color.cs index 0c4df0a..9866532 100644 --- a/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/UI/Color.cs +++ b/src/libraries/System.Runtime.WindowsRuntime/src/System/Windows/UI/Color.cs @@ -41,7 +41,7 @@ namespace Windows.UI public static Color FromArgb(byte a, byte r, byte g, byte b) { - Color c1 = new Color(); + Color c1 = default; c1.A = a; c1.R = r; diff --git a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/Privilege.cs b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/Privilege.cs index 31a59fd..30925d5 100644 --- a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/Privilege.cs +++ b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/Privilege.cs @@ -476,7 +476,7 @@ namespace System.Security.AccessControl newState.Privileges.Luid = this.luid; newState.Privileges.Attributes = enable ? Interop.Advapi32.SEPrivileges.SE_PRIVILEGE_ENABLED : Interop.Advapi32.SEPrivileges.SE_PRIVILEGE_DISABLED; - Interop.Advapi32.TOKEN_PRIVILEGE previousState = new Interop.Advapi32.TOKEN_PRIVILEGE(); + Interop.Advapi32.TOKEN_PRIVILEGE previousState = default; uint previousSize = 0; // diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CngKeyLite.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CngKeyLite.cs index 90f1551..bec5385 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CngKeyLite.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/CngKeyLite.cs @@ -281,7 +281,7 @@ namespace System.Security.Cryptography { Interop.NCrypt.NCryptBuffer* buffers = stackalloc Interop.NCrypt.NCryptBuffer[3]; - Interop.NCrypt.PBE_PARAMS pbeParams = new Interop.NCrypt.PBE_PARAMS(); + Interop.NCrypt.PBE_PARAMS pbeParams = default; Span salt = new Span(pbeParams.rgbSalt, Interop.NCrypt.PBE_PARAMS.RgbSaltSize); RandomNumberGenerator.Fill(salt); pbeParams.Params.cbSalt = salt.Length; diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECCurve.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECCurve.cs index d1e8960..40b7683 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECCurve.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECCurve.cs @@ -95,7 +95,7 @@ namespace System.Security.Cryptography /// private static ECCurve Create(Oid oid) { - ECCurve curve = new ECCurve(); + ECCurve curve = default; curve.CurveType = ECCurveType.Named; curve.Oid = oid; return curve; diff --git a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs index 725e807..e355c85 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs @@ -54,7 +54,7 @@ namespace System.Security.Cryptography throw new ObjectDisposedException(nameof(ECDiffieHellmanPublicKey)); } - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; ECCng.ExportPrimeCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false); return ecparams; } @@ -81,7 +81,7 @@ namespace System.Security.Cryptography } else { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; ECCng.ExportNamedCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false); ecparams.Curve = ECCurve.CreateFromFriendlyName(_curveName); return ecparams; diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKey.Export.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKey.Export.cs index c861f15..9006103 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKey.Export.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/CngKey.Export.cs @@ -138,7 +138,7 @@ namespace System.Security.Cryptography { Interop.NCrypt.NCryptBuffer* buffers = stackalloc Interop.NCrypt.NCryptBuffer[3]; - Interop.NCrypt.PBE_PARAMS pbeParams = new Interop.NCrypt.PBE_PARAMS(); + Interop.NCrypt.PBE_PARAMS pbeParams = default; Span salt = new Span(pbeParams.rgbSalt, Interop.NCrypt.PBE_PARAMS.RgbSaltSize); RandomNumberGenerator.Fill(salt); pbeParams.Params.cbSalt = salt.Length; diff --git a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs index dd94672..36a01de 100644 --- a/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs +++ b/src/libraries/System.Security.Cryptography.Cng/src/System/Security/Cryptography/ECDiffieHellmanCngPublicKey.cs @@ -112,7 +112,7 @@ namespace System.Security.Cryptography { using (CngKey key = Import()) { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; byte[] blob = ECCng.ExportFullKeyBlob(key, includePrivateParameters: false); ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters: false); return ecparams; @@ -132,7 +132,7 @@ namespace System.Security.Cryptography { using (CngKey key = Import()) { - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; string curveName = key.GetCurveName(out _); if (string.IsNullOrEmpty(curveName)) diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs index 381be95..2c5a781 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.DSA.Shared.cs @@ -157,7 +157,7 @@ namespace Internal.NativeCrypto byte bVersion; ReadKeyBlobHeader(br, out bVersion); - DSAParameters dsaParameters = new DSAParameters(); + DSAParameters dsaParameters = default; if (bVersion > 2) { diff --git a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs index 15f8ca7..8fb0ca3 100644 --- a/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs +++ b/src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Shared.cs @@ -178,7 +178,7 @@ namespace Internal.NativeCrypto uint expAsDword = br.ReadUInt32(); - RSAParameters rsaParameters = new RSAParameters(); + RSAParameters rsaParameters = default; rsaParameters.Exponent = ExponentAsBytes(expAsDword); rsaParameters.Modulus = br.ReadReversed(modulusLength); if (includePrivateParameters) diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.KeyTrans.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.KeyTrans.cs index a9d15ea..b31bd55 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.KeyTrans.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/AnyOS/ManagedPal.KeyTrans.cs @@ -109,7 +109,7 @@ namespace Internal.Cryptography.Pal.AnyOS CmsRecipient recipient, out bool v0Recipient) { - KeyTransRecipientInfoAsn ktri = new KeyTransRecipientInfoAsn(); + KeyTransRecipientInfoAsn ktri = default; if (recipient.RecipientIdentifierType == SubjectIdentifierType.SubjectKeyIdentifier) { diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs index 18f1ca9..6f35e2c 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System/Security/Cryptography/Pkcs/CmsSigner.cs @@ -127,7 +127,7 @@ namespace System.Security.Cryptography.Pkcs hasher.AppendData(data.Span); byte[] dataHash = hasher.GetHashAndReset(); - SignerInfoAsn newSignerInfo = new SignerInfoAsn(); + SignerInfoAsn newSignerInfo = default; newSignerInfo.DigestAlgorithm.Algorithm = DigestAlgorithm; // If the user specified attributes (not null, count > 0) we need attributes. @@ -163,7 +163,7 @@ namespace System.Security.Cryptography.Pkcs } // Use the serializer/deserializer to DER-normalize the attribute order. - SignedAttributesSet signedAttrsSet = new SignedAttributesSet(); + SignedAttributesSet signedAttrsSet = default; signedAttrsSet.SignedAttributes = PkcsHelpers.NormalizeAttributeSet( signedAttrs.ToArray(), normalized => hasher.AppendData(normalized)); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ManagedX509ExtensionProcessor.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ManagedX509ExtensionProcessor.cs index 383bd37..e88618e 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ManagedX509ExtensionProcessor.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Unix/ManagedX509ExtensionProcessor.cs @@ -69,7 +69,7 @@ namespace Internal.Cryptography.Pal bool hasPathLengthConstraint, int pathLengthConstraint) { - BasicConstraintsAsn constraints = new BasicConstraintsAsn(); + BasicConstraintsAsn constraints = default; constraints.CA = certificateAuthority; if (hasPathLengthConstraint) @@ -194,7 +194,7 @@ namespace Internal.Cryptography.Pal // The CapiSha1 value is the SHA-1 of the SubjectPublicKeyInfo field, inclusive // of the DER structural bytes. - SubjectPublicKeyInfoAsn spki = new SubjectPublicKeyInfoAsn(); + SubjectPublicKeyInfoAsn spki = default; spki.Algorithm = new AlgorithmIdentifierAsn { Algorithm = key.Oid, Parameters = key.EncodedParameters.RawData }; spki.SubjectPublicKey = key.EncodedKeyValue.RawData; diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.PrivateKey.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.PrivateKey.cs index f5a64f1..545d28d 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.PrivateKey.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.PrivateKey.cs @@ -342,7 +342,7 @@ namespace Internal.Cryptography.Pal // check to see if we can figure out what key number it needs to re-open. int keySpec = GuessKeySpec(provider, keyName, machineKey, cngKey.AlgorithmGroup); - CRYPT_KEY_PROV_INFO keyProvInfo = new CRYPT_KEY_PROV_INFO(); + CRYPT_KEY_PROV_INFO keyProvInfo = default; fixed (char* keyNamePtr = cngKey.KeyName) fixed (char* provNamePtr = cngKey.Provider.Provider) @@ -529,7 +529,7 @@ namespace Internal.Cryptography.Pal // Make a new pal from bytes. CertificatePal pal = (CertificatePal)FromBlob(RawData, SafePasswordHandle.InvalidHandle, X509KeyStorageFlags.PersistKeySet); - CRYPT_KEY_PROV_INFO keyProvInfo = new CRYPT_KEY_PROV_INFO(); + CRYPT_KEY_PROV_INFO keyProvInfo = default; fixed (char* keyName = keyContainerInfo.KeyContainerName) fixed (char* provName = keyContainerInfo.ProviderName) diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs index 87803da..dd8ff76 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/CertificatePal.cs @@ -148,7 +148,7 @@ namespace Internal.Cryptography.Pal int cbData = 0; if (!Interop.crypt32.CertGetCertificateContextProperty(_certContext, CertContextPropId.CERT_PUBKEY_ALG_PARA_PROP_ID, null, ref cbData)) { - CERT_CHAIN_PARA chainPara = new CERT_CHAIN_PARA(); + CERT_CHAIN_PARA chainPara = default; chainPara.cbSize = sizeof(CERT_CHAIN_PARA); if (!Interop.crypt32.CertGetCertificateChain((IntPtr)ChainEngine.HCCE_CURRENT_USER, _certContext, (FILETIME*)null, SafeCertStoreHandle.InvalidHandle, ref chainPara, CertChainFlags.None, IntPtr.Zero, out certChainContext)) throw Marshal.GetHRForLastWin32Error().ToCryptographicException(); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.BuildChain.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.BuildChain.cs index 2136de8..6ccb01b 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.BuildChain.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.BuildChain.cs @@ -45,7 +45,7 @@ namespace Internal.Cryptography.Pal using (SafeChainEngineHandle storeHandle = GetChainEngine(trustMode, customTrustStore, useMachineContext)) using (SafeCertStoreHandle extraStoreHandle = ConvertStoreToSafeHandle(extraStore)) { - CERT_CHAIN_PARA chainPara = new CERT_CHAIN_PARA(); + CERT_CHAIN_PARA chainPara = default; chainPara.cbSize = Marshal.SizeOf(); int applicationPolicyCount; @@ -96,7 +96,7 @@ namespace Internal.Cryptography.Pal // Need to get a valid SafeCertStoreHandle otherwise the default stores will be trusted using (SafeCertStoreHandle customTrustStoreHandle = ConvertStoreToSafeHandle(customTrustStore, true)) { - CERT_CHAIN_ENGINE_CONFIG customChainEngine = new CERT_CHAIN_ENGINE_CONFIG(); + CERT_CHAIN_ENGINE_CONFIG customChainEngine = default; customChainEngine.cbSize = Marshal.SizeOf(); customChainEngine.hExclusiveRoot = customTrustStoreHandle.DangerousGetHandle(); chainEngineHandle = Interop.crypt32.CertCreateCertificateChainEngine(ref customChainEngine); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.cs index 1c1a3ba..24d535c 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/ChainPal.cs @@ -37,11 +37,11 @@ namespace Internal.Cryptography.Pal unsafe { - CERT_CHAIN_POLICY_PARA para = new CERT_CHAIN_POLICY_PARA(); + CERT_CHAIN_POLICY_PARA para = default; para.cbSize = sizeof(CERT_CHAIN_POLICY_PARA); para.dwFlags = (int)flags; - CERT_CHAIN_POLICY_STATUS status = new CERT_CHAIN_POLICY_STATUS(); + CERT_CHAIN_POLICY_STATUS status = default; status.cbSize = sizeof(CERT_CHAIN_POLICY_STATUS); if (!Interop.crypt32.CertVerifyCertificateChainPolicy(ChainPolicy.CERT_CHAIN_POLICY_BASE, _chain, ref para, ref status)) diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs index 081a66b..a68d931 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/Internal/Cryptography/Pal.Windows/X509Pal.PublicKey.cs @@ -84,7 +84,7 @@ namespace Internal.Cryptography.Pal { blobFormat = CngKeyBlobFormat.EccPublicBlob; keyBlob = ExportKeyBlob(bCryptKeyHandle, blobFormat); - ECParameters ecparams = new ECParameters(); + ECParameters ecparams = default; ExportNamedCurveParameters(ref ecparams, keyBlob, false); ecparams.Curve = ECCurve.CreateFromFriendlyName(curveName); ecdsa = new ECDsaCng(); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Pkcs10CertificationRequestInfo.cs b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Pkcs10CertificationRequestInfo.cs index 522a1fa..9088a67 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Pkcs10CertificationRequestInfo.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/src/System/Security/Cryptography/X509Certificates/Pkcs10CertificationRequestInfo.cs @@ -53,7 +53,7 @@ namespace System.Security.Cryptography.X509Certificates Helpers.ValidateDer(signatureAlgorithmAsn.Parameters.Value); } - SubjectPublicKeyInfoAsn spki = new SubjectPublicKeyInfoAsn(); + SubjectPublicKeyInfoAsn spki = default; spki.Algorithm = new AlgorithmIdentifierAsn { Algorithm = PublicKey.Oid, Parameters = PublicKey.EncodedParameters.RawData }; spki.SubjectPublicKey = PublicKey.EncodedKeyValue.RawData; diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/Win32.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/Win32.cs index 524a3e7..49154ee 100644 --- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/Win32.cs +++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/Win32.cs @@ -42,7 +42,7 @@ namespace System.Security.Principal { SafeLsaPolicyHandle policyHandle; - var attributes = new Interop.OBJECT_ATTRIBUTES(); + Interop.OBJECT_ATTRIBUTES attributes = default; uint error = Interop.Advapi32.LsaOpenPolicy(systemName, ref attributes, (int)rights, out policyHandle); if (error == 0) { diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/CategoriesDocument.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/CategoriesDocument.cs index 3a28dfe..b45e196 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/CategoriesDocument.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/CategoriesDocument.cs @@ -10,7 +10,7 @@ namespace System.ServiceModel.Syndication { public abstract class CategoriesDocument : IExtensibleSyndicationObject { - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; internal CategoriesDocument() { diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ResourceCollectionInfo.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ResourceCollectionInfo.cs index 4028b02..df0b982 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ResourceCollectionInfo.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ResourceCollectionInfo.cs @@ -13,7 +13,7 @@ namespace System.ServiceModel.Syndication private static IEnumerable s_singleEmptyAccept; private Collection _accepts; private Collection _categories; - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; public ResourceCollectionInfo() { diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ServiceDocument.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ServiceDocument.cs index 689b6ab..98ea4d9 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ServiceDocument.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/ServiceDocument.cs @@ -10,7 +10,7 @@ namespace System.ServiceModel.Syndication { public class ServiceDocument : IExtensibleSyndicationObject { - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; private Collection _workspaces; public ServiceDocument() : this(null) diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationCategory.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationCategory.cs index f64311e..8f5ae3d 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationCategory.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationCategory.cs @@ -10,7 +10,7 @@ namespace System.ServiceModel.Syndication // NOTE: This class implements Clone so if you add any members, please update the copy ctor public class SyndicationCategory : IExtensibleSyndicationObject { - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; public SyndicationCategory() : this((string)null) { diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeed.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeed.cs index f5eada8..112a487 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeed.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationFeed.cs @@ -21,7 +21,7 @@ namespace System.ServiceModel.Syndication private Collection _authors; private Collection _categories; private Collection _contributors; - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; private IEnumerable _items; private DateTimeOffset _lastUpdatedTime; private Collection _links; diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationItem.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationItem.cs index 3eded60..e860683 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationItem.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationItem.cs @@ -15,7 +15,7 @@ namespace System.ServiceModel.Syndication private Collection _authors; private Collection _categories; private Collection _contributors; - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; private DateTimeOffset _lastUpdatedTime; private Collection _links; private DateTimeOffset _publishDate; diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationLink.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationLink.cs index 861aa6a..4a35271 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationLink.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationLink.cs @@ -10,7 +10,7 @@ namespace System.ServiceModel.Syndication // NOTE: This class implements Clone so if you add any members, please update the copy ctor public class SyndicationLink : IExtensibleSyndicationObject { - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; private long _length; public SyndicationLink(Uri uri) : this(uri, null, null, null, 0) diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationPerson.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationPerson.cs index 8845b27..53b37f1 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationPerson.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/SyndicationPerson.cs @@ -11,7 +11,7 @@ namespace System.ServiceModel.Syndication // NOTE: This class implements Clone so if you add any members, please update the copy ctor public class SyndicationPerson : IExtensibleSyndicationObject { - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; public SyndicationPerson() : this((string)null) { diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Workspace.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Workspace.cs index 56a7e5c..0b42f19 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Workspace.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/Workspace.cs @@ -11,7 +11,7 @@ namespace System.ServiceModel.Syndication public class Workspace : IExtensibleSyndicationObject { private Collection _collections; - private ExtensibleSyndicationObject _extensions = new ExtensibleSyndicationObject(); + private ExtensibleSyndicationObject _extensions; public Workspace() { diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs index 4120427..72f07e9 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceBase.cs @@ -23,7 +23,7 @@ namespace System.ServiceProcess /// public class ServiceBase : Component { - private SERVICE_STATUS _status = new SERVICE_STATUS(); + private SERVICE_STATUS _status; private IntPtr _statusHandle; private ServiceControlCallbackEx _commandCallbackEx; private ServiceMainCallback _mainCallback; diff --git a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs index d4a7acf..e635a9c 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/src/System/ServiceProcess/ServiceController.cs @@ -464,7 +464,7 @@ namespace System.ServiceProcess { using (var serviceHandle = GetServiceHandle(Interop.Advapi32.ServiceOptions.SERVICE_QUERY_STATUS)) { - Interop.Advapi32.SERVICE_STATUS svcStatus = new Interop.Advapi32.SERVICE_STATUS(); + Interop.Advapi32.SERVICE_STATUS svcStatus = default; bool success = Interop.Advapi32.QueryServiceStatus(serviceHandle, &svcStatus); if (!success) throw new Win32Exception(Marshal.GetLastWin32Error()); @@ -750,7 +750,7 @@ namespace System.ServiceProcess { using (var serviceHandle = GetServiceHandle(Interop.Advapi32.ServiceOptions.SERVICE_PAUSE_CONTINUE)) { - Interop.Advapi32.SERVICE_STATUS status = new Interop.Advapi32.SERVICE_STATUS(); + Interop.Advapi32.SERVICE_STATUS status = default; bool result = Interop.Advapi32.ControlService(serviceHandle, Interop.Advapi32.ControlOptions.CONTROL_PAUSE, &status); if (!result) { @@ -765,7 +765,7 @@ namespace System.ServiceProcess { using (var serviceHandle = GetServiceHandle(Interop.Advapi32.ServiceOptions.SERVICE_PAUSE_CONTINUE)) { - Interop.Advapi32.SERVICE_STATUS status = new Interop.Advapi32.SERVICE_STATUS(); + Interop.Advapi32.SERVICE_STATUS status = default; bool result = Interop.Advapi32.ControlService(serviceHandle, Interop.Advapi32.ControlOptions.CONTROL_CONTINUE, &status); if (!result) { @@ -779,7 +779,7 @@ namespace System.ServiceProcess { using (var serviceHandle = GetServiceHandle(Interop.Advapi32.ServiceOptions.SERVICE_USER_DEFINED_CONTROL)) { - Interop.Advapi32.SERVICE_STATUS status = new Interop.Advapi32.SERVICE_STATUS(); + Interop.Advapi32.SERVICE_STATUS status = default; bool result = Interop.Advapi32.ControlService(serviceHandle, command, &status); if (!result) { @@ -831,7 +831,7 @@ namespace System.ServiceProcess throw; } - GCHandle argPtrsHandle = new GCHandle(); + GCHandle argPtrsHandle = default; try { argPtrsHandle = GCHandle.Alloc(argPtrs, GCHandleType.Pinned); @@ -872,7 +872,7 @@ namespace System.ServiceProcess } } - Interop.Advapi32.SERVICE_STATUS status = new Interop.Advapi32.SERVICE_STATUS(); + Interop.Advapi32.SERVICE_STATUS status = default; bool result = Interop.Advapi32.ControlService(serviceHandle, Interop.Advapi32.ControlOptions.CONTROL_STOP, &status); if (!result) { diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs index 7992063..71ec914 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Date.cs @@ -178,10 +178,11 @@ namespace System.Text.Json /// "true" if successfully parsed. private static bool TryParseDateTimeOffset(ReadOnlySpan source, out DateTimeParseData parseData) { + parseData = default; + // Source does not have enough characters for YYYY-MM-DD if (source.Length < 10) { - parseData = default; return false; } @@ -197,8 +198,6 @@ namespace System.Text.Json // just [year]["-"][month] (a) and just [year] (b), but we currently // don't permit it. - parseData = new DateTimeParseData(); - { uint digit1 = source[0] - (uint)'0'; uint digit2 = source[1] - (uint)'0'; diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs index 802fca0..b4058ec 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Internal/ConcurrentQueue.cs @@ -235,7 +235,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections //current head is empty and it is NOT the last segment, //it means another thread is growing new segment { - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (head.IsEmpty) { if (head.Next == null) @@ -319,7 +319,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections tail = _tail; headLow = head.Low; tailHigh = tail.High; - SpinWait spin = new SpinWait(); + SpinWait spin = default; //we loop until the observed values are stable and sensible. //This ensures that any update order by other methods can be tolerated. @@ -456,7 +456,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections { try { - SpinWait spin = new SpinWait(); + SpinWait spin = default; if (head == tail) { @@ -534,7 +534,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections /// public void Enqueue(T item) { - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (true) { Segment tail = _tail; @@ -779,7 +779,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections /// return false only if the current segment is empty internal bool TryRemove(out T result) { - SpinWait spin = new SpinWait(); + SpinWait spin = default; int lowLocal = Low, highLocal = High; while (lowLocal <= highLocal) { @@ -788,7 +788,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections { //if the specified value is not available (this spot is taken by a push operation, // but the value is not written into yet), then spin - SpinWait spinLocal = new SpinWait(); + SpinWait spinLocal = default; while (!_state[lowLocal]._value) { spinLocal.SpinOnce(); @@ -814,7 +814,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections //while the *current* thread is doing *this* Dequeue operation, and finds that it needs to //dispose the current (and ONLY) segment. Then we need to wait till thread A finishes its //Grow operation, this is the reason of having the following while loop - spinLocal = new SpinWait(); + spinLocal = default; while (_next == null) { spinLocal.SpinOnce(); @@ -847,7 +847,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections int lowLocal = Low; if (lowLocal > High) return false; - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (!_state[lowLocal]._value) { spin.SpinOnce(); @@ -866,7 +866,7 @@ namespace System.Threading.Tasks.Dataflow.Internal.Collections { for (int i = start; i <= end; i++) { - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (!_state[i]._value) { spin.SpinOnce(); diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs index dba1146..6f966cb 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/Parallel.cs @@ -1021,7 +1021,7 @@ namespace System.Threading.Tasks "thread local functions should only be supplied for loops w/ thread local bodies"); // Instantiate our result. Specifics will be filled in later. - ParallelLoopResult result = new ParallelLoopResult(); + ParallelLoopResult result = default; // We just return immediately if 'to' is smaller (or equal to) 'from'. if (toExclusive <= fromInclusive) @@ -1282,7 +1282,7 @@ namespace System.Threading.Tasks "thread local functions should only be supplied for loops w/ thread local bodies"); // Instantiate our result. Specifics will be filled in later. - ParallelLoopResult result = new ParallelLoopResult(); + ParallelLoopResult result = default; // We just return immediately if 'to' is smaller (or equal to) 'from'. if (toExclusive <= fromInclusive) @@ -3101,7 +3101,7 @@ namespace System.Threading.Tasks ParallelLoopStateFlags64 sharedPStateFlags = new ParallelLoopStateFlags64(); // Instantiate our result. Specifics will be filled in later. - ParallelLoopResult result = new ParallelLoopResult(); + ParallelLoopResult result = default; // Keep track of any cancellations OperationCanceledException? oce = null; diff --git a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs index 50eb53e..44c3b1e 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/src/System/Threading/Tasks/ParallelLoopState.cs @@ -208,7 +208,7 @@ namespace System.Threading.Tasks int oldLBI = pflags._lowestBreakIteration; if (iteration < oldLBI) { - SpinWait wait = new SpinWait(); + SpinWait wait = default; while (Interlocked.CompareExchange( ref pflags._lowestBreakIteration, iteration, @@ -249,7 +249,7 @@ namespace System.Threading.Tasks long oldLBI = pflags.LowestBreakIteration; if (iteration < oldLBI) { - SpinWait wait = new SpinWait(); + SpinWait wait = default; while (Interlocked.CompareExchange( ref pflags._lowestBreakIteration, iteration, @@ -419,7 +419,7 @@ namespace System.Threading.Tasks internal bool AtomicLoopStateUpdate(int newState, int illegalStates, ref int oldState) { - SpinWait sw = new SpinWait(); + SpinWait sw = default; do { diff --git a/src/libraries/System.Threading/src/System/Threading/Barrier.cs b/src/libraries/System.Threading/src/System/Threading/Barrier.cs index ddd16b5..82a2a15 100644 --- a/src/libraries/System.Threading/src/System/Threading/Barrier.cs +++ b/src/libraries/System.Threading/src/System/Threading/Barrier.cs @@ -334,7 +334,7 @@ namespace System.Threading throw new InvalidOperationException(SR.Barrier_InvalidOperation_CalledFromPHA); } - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; long newPhase = 0; while (true) { @@ -435,7 +435,7 @@ namespace System.Threading throw new InvalidOperationException(SR.Barrier_InvalidOperation_CalledFromPHA); } - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (true) { int currentTotal = _currentTotalCount; @@ -486,7 +486,7 @@ namespace System.Threading /// disposed. public void SignalAndWait() { - SignalAndWait(new CancellationToken()); + SignalAndWait(CancellationToken.None); } /// @@ -535,7 +535,7 @@ namespace System.Threading /// disposed. public bool SignalAndWait(TimeSpan timeout) { - return SignalAndWait(timeout, new CancellationToken()); + return SignalAndWait(timeout, CancellationToken.None); } /// @@ -589,7 +589,7 @@ namespace System.Threading /// disposed. public bool SignalAndWait(int millisecondsTimeout) { - return SignalAndWait(millisecondsTimeout, new CancellationToken()); + return SignalAndWait(millisecondsTimeout, CancellationToken.None); } /// @@ -637,7 +637,7 @@ namespace System.Threading int current; int currentTotal; long phase; - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (true) { currentTotal = _currentTotalCount; @@ -838,7 +838,7 @@ namespace System.Threading //1- The event is set //2- the phase count is incremented more than one time, this means the next phase is finished as well, //but the event will be reset again, so we check the phase count instead - SpinWait spinner = new SpinWait(); + SpinWait spinner = default; while (!currentPhaseEvent.IsSet && CurrentPhaseNumber - observedPhase <= 1) { spinner.SpinOnce(); diff --git a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs index 03f5046..813306c 100644 --- a/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs +++ b/src/libraries/System.Threading/src/System/Threading/CountdownEvent.cs @@ -225,7 +225,7 @@ namespace System.Threading Debug.Assert(_event != null); int observedCount; - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (true) { observedCount = _currentCount; @@ -332,7 +332,7 @@ namespace System.Threading // Loop around until we successfully increment the count. int observedCount; - SpinWait spin = new SpinWait(); + SpinWait spin = default; while (true) { observedCount = _currentCount; @@ -417,7 +417,7 @@ namespace System.Threading /// disposed. public void Wait() { - Wait(Timeout.Infinite, new CancellationToken()); + Wait(Timeout.Infinite, CancellationToken.None); } @@ -465,7 +465,7 @@ namespace System.Threading throw new ArgumentOutOfRangeException(nameof(timeout)); } - return Wait((int)totalMilliseconds, new CancellationToken()); + return Wait((int)totalMilliseconds, CancellationToken.None); } /// @@ -512,7 +512,7 @@ namespace System.Threading /// disposed. public bool Wait(int millisecondsTimeout) { - return Wait(millisecondsTimeout, new CancellationToken()); + return Wait(millisecondsTimeout, CancellationToken.None); } /// diff --git a/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs b/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs index afd940a..57a1c63 100644 --- a/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs +++ b/src/libraries/System.Threading/src/System/Threading/ReaderWriterLock.cs @@ -673,7 +673,7 @@ namespace System.Threading throw GetInvalidTimeoutException(nameof(millisecondsTimeout)); } - var lockCookie = new LockCookie(); + LockCookie lockCookie = default; int threadID = GetCurrentThreadID(); lockCookie._threadID = threadID; @@ -876,7 +876,7 @@ namespace System.Threading public LockCookie ReleaseLock() { - var lockCookie = new LockCookie(); + LockCookie lockCookie = default; int threadID = GetCurrentThreadID(); lockCookie._threadID = threadID; diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs index ac07bcb..c5b6410 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/EnlistmentTraceIdentifier.cs @@ -11,7 +11,7 @@ namespace System.Transactions /// internal readonly struct EnlistmentTraceIdentifier : IEquatable { - public static readonly EnlistmentTraceIdentifier Empty = new EnlistmentTraceIdentifier(); + public static readonly EnlistmentTraceIdentifier Empty = default; public EnlistmentTraceIdentifier( Guid resourceManagerIdentifier, diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionState.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionState.cs index 5ecf438..2d911c0 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionState.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionState.cs @@ -2201,7 +2201,7 @@ namespace System.Transactions } // Just create a new transaction. - TransactionOptions options = new TransactionOptions(); + TransactionOptions options = default; options.IsolationLevel = tx._outcomeSource._isoLevel; options.Timeout = newTimeout; diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs index 130e381..0dfd048 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionTraceIdentifier.cs @@ -11,7 +11,7 @@ namespace System.Transactions /// internal readonly struct TransactionTraceIdentifier : IEquatable { - public static readonly TransactionTraceIdentifier Empty = new TransactionTraceIdentifier(); + public static readonly TransactionTraceIdentifier Empty = default; public TransactionTraceIdentifier(string transactionIdentifier, int cloneIdentifier) { diff --git a/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs b/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs index 72ef934..aaea655 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Drawing/FontConverter.cs @@ -37,7 +37,7 @@ namespace System.Drawing culture = CultureInfo.CurrentCulture; } - ValueStringBuilder sb = new ValueStringBuilder(); + ValueStringBuilder sb = default; sb.Append(font.Name); sb.Append(culture.TextInfo.ListSeparator[0] + " "); sb.Append(font.Size.ToString(culture.NumberFormat)); -- 2.7.4