diff --git a/docs/coding-guidelines/coding-style.md b/docs/coding-guidelines/coding-style.md index 709d4719d1c68cf9bb7c4acb64f7d026f3721b65..ac12a6c69d4b4d7802c9eb98ad9318b6cfc174d6 100644 --- a/docs/coding-guidelines/coding-style.md +++ b/docs/coding-guidelines/coding-style.md @@ -24,6 +24,7 @@ The general rule we follow is "use Visual Studio defaults". 9. If a file happens to differ in style from these guidelines (e.g. private members are named `m_member` rather than `_member`), the existing style in that file takes precedence. 10. We only use `var` when the type is explicitly named on the right-hand side, typically due to either `new` or an explicit cast, e.g. `var stream = new FileStream(...)` not `var stream = OpenStandardInput()`. + - Similarly, target-typed `new()` can only be used when the type is explicitly named on the left-hand side, in a variable definition statement or a field definition statement. e.g. `FileStream stream = new(...);`, but not `stream = new(...);` (where the type was specified on a previous line). 11. We use language keywords instead of BCL types (e.g. `int, string, float` instead of `Int32, String, Single`, etc) for both type references as well as method calls (e.g. `int.Parse` instead of `Int32.Parse`). See issue [#13976](https://github.com/dotnet/runtime/issues/13976) for examples. 12. We use PascalCasing to name all our constant local variables and fields. The only exception is for interop code where the constant value should exactly match the name and value of the code you are calling via interop. 13. We use PascalCasing for all method names, including local functions. diff --git a/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs b/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs index 7383ecf6324b4dd7ba7d60271ba1b8fe1048a448..182cea820b063a332f8e3f24a0072f2c6d09eeaf 100644 --- a/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs +++ b/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs @@ -46,7 +46,7 @@ public MemoryCache(IOptions optionsAccessor!!, ILoggerFactor _options = optionsAccessor.Value; _logger = loggerFactory.CreateLogger(); - _coherentState = new(); + _coherentState = new CoherentState(); if (_options.Clock == null) { diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs index 9a3c909bb177b2caf28fe3456f450d5e38f2956f..3e24a95d376f7e2d154a515d706fc4800030eda6 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/LegacyPropagator.cs @@ -165,7 +165,7 @@ internal static bool TryExtractBaggage(string baggageString, out IEnumerable>(); // Insert in reverse order for asp.net compatability. baggageList.Insert(0, new KeyValuePair( diff --git a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageAnimator.ManualTests.cs b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageAnimator.ManualTests.cs index 84d9da6d2c1a385c8198b337fa3e69255484e597..a7abefdcb39034963c6e2b5049d1a2853fcd0ec9 100644 --- a/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageAnimator.ManualTests.cs +++ b/src/libraries/System.Drawing.Common/tests/System/Drawing/ImageAnimator.ManualTests.cs @@ -70,7 +70,7 @@ public void AnimateAndCaptureFrames() animation.Save(Path.Combine(testOutputFolder, $"{++frameIndexes[imageName]}_{timestamp}.jpg"), ImageFormat.Jpeg); })); - bitmaps[imageName] = new(Helpers.GetTestBitmapPath(imageName)); + bitmaps[imageName] = new Bitmap(Helpers.GetTestBitmapPath(imageName)); ImageAnimator.Animate(bitmaps[imageName], handlers[imageName]); } diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs index d01c3db01a51ef308c751b53ba3480d7fb29dedb..362242c6896c10072f1661310864424753dc186c 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ContentType.cs @@ -139,7 +139,7 @@ internal string SubTypeComponent /// This will return an enumerator over a dictionary of the parameter/value pairs. /// internal Dictionary.Enumerator ParameterValuePairs => - (_parameterDictionary ??= new()).GetEnumerator(); + (_parameterDictionary ??= new Dictionary()).GetEnumerator(); #endregion Internal Properties #region Internal Methods @@ -330,7 +330,7 @@ private void ParseParameterAndValue(ReadOnlySpan parameterAndValue) //Get length of the parameter value int parameterValueLength = GetLengthOfParameterValue(parameterAndValue, parameterStartIndex); - (_parameterDictionary ??= new()).Add( + (_parameterDictionary ??= new Dictionary()).Add( ValidateToken(parameterAndValue.Slice(0, equalSignIndex).ToString()), ValidateQuotedStringOrToken(parameterAndValue.Slice(parameterStartIndex, parameterValueLength).ToString())); diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/MsQuicNativeMethods.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/MsQuicNativeMethods.cs index f19e664fa21e9de49b8376141da461ba7cd608fc..1327c5a1030c596f22fd3ede3f691581c1871ffb 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/MsQuicNativeMethods.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Interop/MsQuicNativeMethods.cs @@ -841,7 +841,7 @@ internal void SetCallbackHandler(SafeHandle handle, Delegate del, IntPtr context // handle.DangerousAddRef(ref handle__addRefd); IntPtr __handle_gen_native = handle.DangerousGetHandle(); - __del_gen_native__marshaller = new(del); + __del_gen_native__marshaller = new AnyDelegateMarshaller(del); IntPtr __del_gen_native = __del_gen_native__marshaller.Value; ((delegate* unmanaged[Cdecl])_functionPointer)(__handle_gen_native, __del_gen_native, context); } @@ -929,7 +929,7 @@ internal uint RegistrationOpen(ref RegistrationConfig config, out SafeMsQuicRegi // // Marshal // - __config_gen_native = new(config); + __config_gen_native = new RegistrationConfig.Native(config); __retVal = ((delegate* unmanaged[Cdecl])_functionPointer)(&__config_gen_native, &__registrationContext_gen_native); __invokeSucceeded = true; // @@ -1017,7 +1017,7 @@ internal uint ConfigurationLoadCredential(SafeMsQuicConfigurationHandle configur // configuration.DangerousAddRef(ref configuration__addRefd); IntPtr __configuration_gen_native = configuration.DangerousGetHandle(); - __credConfig_gen_native = new(credConfig); + __credConfig_gen_native = new CredentialConfig.Native(credConfig); __retVal = ((delegate* unmanaged[Cdecl])_functionPointer)(__configuration_gen_native, &__credConfig_gen_native); // // Unmarshal diff --git a/src/libraries/System.Net.WebSockets/tests/WebSocketDeflateTests.cs b/src/libraries/System.Net.WebSockets/tests/WebSocketDeflateTests.cs index 184c7e9089e2a67eaa5e093abe68effd269f33fc..03ae5981c9b8986219e5b67ff7af92315ab469ef 100644 --- a/src/libraries/System.Net.WebSockets/tests/WebSocketDeflateTests.cs +++ b/src/libraries/System.Net.WebSockets/tests/WebSocketDeflateTests.cs @@ -44,7 +44,7 @@ public async Task ReceiveHelloWithContextTakeover() stream.Enqueue(0xc1, 0x07, 0xf2, 0x48, 0xcd, 0xc9, 0xc9, 0x07, 0x00); using WebSocket websocket = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); Memory buffer = new byte[5]; @@ -74,7 +74,7 @@ public async Task SendHelloWithContextTakeover() using WebSocket websocket = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); await websocket.SendAsync(Encoding.UTF8.GetBytes("Hello"), WebSocketMessageType.Text, true, CancellationToken); @@ -95,7 +95,7 @@ public async Task SendHelloWithDisableCompression() using WebSocket websocket = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); byte[] bytes = Encoding.UTF8.GetBytes("Hello"); @@ -113,7 +113,7 @@ public async Task SendHelloWithEmptyFrame() using WebSocket websocket = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); byte[] bytes = Encoding.UTF8.GetBytes("Hello"); @@ -123,7 +123,7 @@ public async Task SendHelloWithEmptyFrame() using WebSocket client = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { IsServer = false, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); ValueWebSocketReceiveResult result = await client.ReceiveAsync(bytes.AsMemory(), CancellationToken); @@ -141,7 +141,7 @@ public async Task ReceiveHelloWithoutContextTakeover() WebSocketTestStream stream = new(); using WebSocket websocket = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientContextTakeover = false } @@ -171,7 +171,7 @@ public async Task SendHelloWithoutContextTakeover() using WebSocket websocket = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ServerContextTakeover = false } @@ -196,7 +196,7 @@ public async Task TwoDeflateBlocksInOneMessage() WebSocketTestStream stream = new(); using WebSocket websocket = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); // The first 3 octets(0xf2 0x48 0x05) and the least significant two // bits of the 4th octet(0x00) constitute one DEFLATE block with @@ -285,14 +285,14 @@ public async Task LargeMessageSplitInMultipleFrames(int windowBits) using WebSocket server = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientMaxWindowBits = windowBits } }); using WebSocket client = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientMaxWindowBits = windowBits } @@ -466,7 +466,7 @@ public async Task SendReceiveWithDifferentWindowBits(int clientWindowBits, int s using WebSocket server = WebSocket.CreateFromStream(stream, new WebSocketCreationOptions { IsServer = true, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientContextTakeover = false, ClientMaxWindowBits = clientWindowBits, @@ -476,7 +476,7 @@ public async Task SendReceiveWithDifferentWindowBits(int clientWindowBits, int s }); using WebSocket client = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientContextTakeover = false, ClientMaxWindowBits = clientWindowBits, @@ -568,7 +568,7 @@ public async Task AutobahnTestCase13_3_1() { IsServer = true, KeepAliveInterval = TimeSpan.Zero, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientMaxWindowBits = 9, ServerMaxWindowBits = 9 @@ -577,7 +577,7 @@ public async Task AutobahnTestCase13_3_1() using WebSocket client = WebSocket.CreateFromStream(stream.Remote, new WebSocketCreationOptions { KeepAliveInterval = TimeSpan.Zero, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() { ClientMaxWindowBits = 9, ServerMaxWindowBits = 9 @@ -609,7 +609,7 @@ public async Task CompressedMessageWithEmptyLastFrame() { IsServer = true, KeepAliveInterval = TimeSpan.Zero, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); byte[] frame1 = new byte[1024]; @@ -626,7 +626,7 @@ public async Task CompressedMessageWithEmptyLastFrame() { IsServer = false, KeepAliveInterval = TimeSpan.Zero, - DangerousDeflateOptions = new() + DangerousDeflateOptions = new WebSocketDeflateOptions() }); int messageSize = 0; diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs index bc543756cd8dc17ae92ecbbc537c88f093dcce63..c854be82fa5195bf8ec261931f744480b7d75093 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs @@ -209,7 +209,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second) else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59); + this = new DateTime(year, month, day, hour, minute, 59); ValidateLeapSecond(); } } @@ -226,7 +226,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, kind); + this = new DateTime(year, month, day, hour, minute, 59, kind); ValidateLeapSecond(); } } @@ -243,7 +243,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, calendar); + this = new DateTime(year, month, day, hour, minute, 59, calendar); ValidateLeapSecond(); } } @@ -265,7 +265,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, millisecond); + this = new DateTime(year, month, day, hour, minute, 59, millisecond); ValidateLeapSecond(); } } @@ -285,7 +285,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, millisecond, kind); + this = new DateTime(year, month, day, hour, minute, 59, millisecond, kind); ValidateLeapSecond(); } } @@ -302,7 +302,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, millisecond, calendar); + this = new DateTime(year, month, day, hour, minute, 59, millisecond, calendar); ValidateLeapSecond(); } } @@ -320,7 +320,7 @@ public DateTime(int year, int month, int day, int hour, int minute, int second, else { // if we have a leap second, then we adjust it to 59 so that DateTime will consider it the last in the specified minute. - this = new(year, month, day, hour, minute, 59, millisecond, calendar, kind); + this = new DateTime(year, month, day, hour, minute, 59, millisecond, calendar, kind); ValidateLeapSecond(); } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs index 28a1902466407adbb865257ccf8509ca2cfc713f..8721461f4e42b7b7cb294a38cf50c09f2eca05a1 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs @@ -389,11 +389,11 @@ private static NullableAttributeStateParser CreateParser(IList()).Add(token); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs index 94e065a7b94b7ef8ad250c954f6a5fc419a84544..97b1f6b999d227cfc37f86ebf93ae3ce832a1da8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.IO.Windows.cs @@ -148,7 +148,7 @@ public IOCompletionPoller(nint port) _nativeEvents = (Interop.Kernel32.OVERLAPPED_ENTRY*) NativeMemory.Alloc(NativeEventCapacity, (nuint)sizeof(Interop.Kernel32.OVERLAPPED_ENTRY)); - _events = new(default); + _events = new ThreadPoolTypedWorkItemQueue(default); // These threads don't run user code, use a smaller stack size _thread = new Thread(Poll, SmallStackSizeBytes); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskAsyncEnumerableExtensions.ToBlockingEnumerable.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskAsyncEnumerableExtensions.ToBlockingEnumerable.cs index bb0b436deca9f129cc4ad5dcfa368daffcb3ab44..4c165a913929a23da976d416e2aacc9cafc70587 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskAsyncEnumerableExtensions.ToBlockingEnumerable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/TaskAsyncEnumerableExtensions.ToBlockingEnumerable.cs @@ -41,7 +41,7 @@ public static IEnumerable ToBlockingEnumerable(this IAsyncEnumerable so if (!moveNextTask.IsCompleted) { - (mres ??= new()).Wait(moveNextTask.ConfigureAwait(false).GetAwaiter()); + (mres ??= new ManualResetEventWithAwaiterSupport()).Wait(moveNextTask.ConfigureAwait(false).GetAwaiter()); Debug.Assert(moveNextTask.IsCompleted); } @@ -59,7 +59,7 @@ public static IEnumerable ToBlockingEnumerable(this IAsyncEnumerable so if (!disposeTask.IsCompleted) { - (mres ?? new()).Wait(disposeTask.ConfigureAwait(false).GetAwaiter()); + (mres ?? new ManualResetEventWithAwaiterSupport()).Wait(disposeTask.ConfigureAwait(false).GetAwaiter()); Debug.Assert(disposeTask.IsCompleted); } diff --git a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs index 164d98287ad9cc82cc5c82082ebb96db5a159317..876c0681bc664879099169711d6e626c4c9f7867 100644 --- a/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs +++ b/src/libraries/System.Runtime.InteropServices/tests/System.Runtime.InteropServices.UnitTests/System/Runtime/InteropServices/CollectionsMarshalTests.cs @@ -158,7 +158,7 @@ public void GetValueRefOrNullRefValueType() Assert.Equal(0, dict[1].Value); Assert.Equal(0, dict[1].Property); - var itemVal = dict[1]; + Struct itemVal = dict[1]; itemVal.Value = 1; itemVal.Property = 2; @@ -172,7 +172,7 @@ public void GetValueRefOrNullRefValueType() Assert.Equal(3, dict[1].Value); Assert.Equal(4, dict[1].Property); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 2); + ref Struct itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 2); Assert.Equal(0, itemRef.Value); Assert.Equal(0, itemRef.Property); @@ -185,7 +185,7 @@ public void GetValueRefOrNullRefValueType() Assert.Equal(dict[2].Value, itemRef.Value); Assert.Equal(dict[2].Property, itemRef.Property); - itemRef = new() { Value = 7, Property = 8 }; + itemRef = new Struct() { Value = 7, Property = 8 }; Assert.Equal(7, itemRef.Value); Assert.Equal(8, itemRef.Property); @@ -205,8 +205,8 @@ public void GetValueRefOrNullRefClass() { var dict = new Dictionary { - { 1, new() }, - { 2, new() } + { 1, new IntAsObject() }, + { 2, new IntAsObject() } }; Assert.Equal(2, dict.Count); @@ -214,7 +214,7 @@ public void GetValueRefOrNullRefClass() Assert.Equal(0, dict[1].Value); Assert.Equal(0, dict[1].Property); - var itemVal = dict[1]; + IntAsObject itemVal = dict[1]; itemVal.Value = 1; itemVal.Property = 2; @@ -228,7 +228,7 @@ public void GetValueRefOrNullRefClass() Assert.Equal(3, dict[1].Value); Assert.Equal(4, dict[1].Property); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 2); + ref IntAsObject itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 2); Assert.Equal(0, itemRef.Value); Assert.Equal(0, itemRef.Property); @@ -241,7 +241,7 @@ public void GetValueRefOrNullRefClass() Assert.Equal(dict[2].Value, itemRef.Value); Assert.Equal(dict[2].Property, itemRef.Property); - itemRef = new() { Value = 7, Property = 8 }; + itemRef = new IntAsObject() { Value = 7, Property = 8 }; Assert.Equal(7, itemRef.Value); Assert.Equal(8, itemRef.Property); @@ -261,12 +261,12 @@ public void GetValueRefOrNullRefLinkBreaksOnResize() { var dict = new Dictionary { - { 1, new() } + { 1, new Struct() } }; Assert.Equal(1, dict.Count); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 1); + ref Struct itemRef = ref CollectionsMarshal.GetValueRefOrNullRef(dict, 1); Assert.Equal(0, itemRef.Value); Assert.Equal(0, itemRef.Property); @@ -283,7 +283,7 @@ public void GetValueRefOrNullRefLinkBreaksOnResize() dict.EnsureCapacity(100); for (int i = 2; i <= 50; i++) { - dict.Add(i, new()); + dict.Add(i, new Struct()); } itemRef.Value = 3; @@ -316,7 +316,7 @@ public void GetValueRefOrAddDefaultValueType() Assert.Equal(0, dict[1].Value); Assert.Equal(0, dict[1].Property); - var itemVal = dict[1]; + Struct itemVal = dict[1]; itemVal.Value = 1; itemVal.Property = 2; @@ -336,7 +336,7 @@ public void GetValueRefOrAddDefaultValueType() Assert.Equal(3, dict[1].Value); Assert.Equal(4, dict[1].Property); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 2, out exists); + ref Struct itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 2, out exists); Assert.True(exists); Assert.Equal(2, dict.Count); @@ -351,7 +351,7 @@ public void GetValueRefOrAddDefaultValueType() Assert.Equal(dict[2].Value, itemRef.Value); Assert.Equal(dict[2].Property, itemRef.Property); - itemRef = new() { Value = 7, Property = 8 }; + itemRef = new Struct() { Value = 7, Property = 8 }; Assert.Equal(7, itemRef.Value); Assert.Equal(8, itemRef.Property); @@ -360,7 +360,7 @@ public void GetValueRefOrAddDefaultValueType() // Check for correct additions - ref var entry3Ref = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 3, out exists); + ref Struct entry3Ref = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 3, out exists); Assert.False(exists); Assert.Equal(3, dict.Count); @@ -370,7 +370,7 @@ public void GetValueRefOrAddDefaultValueType() entry3Ref.Property = 42; entry3Ref.Value = 12345; - var value3 = dict[3]; + Struct value3 = dict[3]; Assert.Equal(42, value3.Property); Assert.Equal(12345, value3.Value); @@ -381,8 +381,8 @@ public void GetValueRefOrAddDefaultClass() { var dict = new Dictionary { - { 1, new() }, - { 2, new() } + { 1, new IntAsObject() }, + { 2, new IntAsObject() } }; Assert.Equal(2, dict.Count); @@ -390,7 +390,7 @@ public void GetValueRefOrAddDefaultClass() Assert.Equal(0, dict[1].Value); Assert.Equal(0, dict[1].Property); - var itemVal = dict[1]; + IntAsObject itemVal = dict[1]; itemVal.Value = 1; itemVal.Property = 2; @@ -410,7 +410,7 @@ public void GetValueRefOrAddDefaultClass() Assert.Equal(3, dict[1].Value); Assert.Equal(4, dict[1].Property); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 2, out exists); + ref IntAsObject itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 2, out exists); Assert.True(exists); Assert.Equal(2, dict.Count); @@ -425,7 +425,7 @@ public void GetValueRefOrAddDefaultClass() Assert.Equal(dict[2].Value, itemRef.Value); Assert.Equal(dict[2].Property, itemRef.Property); - itemRef = new() { Value = 7, Property = 8 }; + itemRef = new IntAsObject() { Value = 7, Property = 8 }; Assert.Equal(7, itemRef.Value); Assert.Equal(8, itemRef.Property); @@ -434,16 +434,16 @@ public void GetValueRefOrAddDefaultClass() // Check for correct additions - ref var entry3Ref = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 3, out exists); + ref IntAsObject entry3Ref = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 3, out exists); Assert.False(exists); Assert.Equal(3, dict.Count); Assert.False(Unsafe.IsNullRef(ref entry3Ref)); Assert.Null(entry3Ref); - entry3Ref = new() { Value = 12345, Property = 42 }; + entry3Ref = new IntAsObject() { Value = 12345, Property = 42 }; - var value3 = dict[3]; + IntAsObject value3 = dict[3]; Assert.Equal(42, value3.Property); Assert.Equal(12345, value3.Value); @@ -454,12 +454,12 @@ public void GetValueRefOrAddDefaultLinkBreaksOnResize() { var dict = new Dictionary { - { 1, new() } + { 1, new Struct() } }; Assert.Equal(1, dict.Count); - ref var itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 1, out bool exists); + ref Struct itemRef = ref CollectionsMarshal.GetValueRefOrAddDefault(dict, 1, out bool exists); Assert.True(exists); Assert.Equal(1, dict.Count); @@ -478,7 +478,7 @@ public void GetValueRefOrAddDefaultLinkBreaksOnResize() dict.EnsureCapacity(100); for (int i = 2; i <= 50; i++) { - dict.Add(i, new()); + dict.Add(i, new Struct()); } itemRef.Value = 3; diff --git a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs index 0cbe26a005ede31253a06a5f5ceac7ab7a15fafa..a004a43ae8dab21736fe8e3ef1d37d23da0f829d 100644 --- a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs +++ b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs @@ -1284,7 +1284,7 @@ public static void ParseExact_String_String_FormatProvider_DateTimeStyles_R(Date public static IEnumerable ParseExact_TestData_R() { // Lowest, highest, and random DateTime in lower, upper, and normal casing - var pairs = new(DateTime, string)[] + var pairs = new (DateTime, string)[] { (DateTime.MaxValue, "Fri, 31 Dec 9999 23:59:59"), (DateTime.MinValue, "Mon, 01 Jan 0001 00:00:00"), diff --git a/src/libraries/System.Runtime/tests/System/Runtime/DependentHandleTests.cs b/src/libraries/System.Runtime/tests/System/Runtime/DependentHandleTests.cs index 2ee4eca51d48f280627ebf93bc3e89093519541e..3c798557d321cb064cd4dc1116117123998df2f9 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/DependentHandleTests.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/DependentHandleTests.cs @@ -223,7 +223,7 @@ public void DependentIsCollectedAfterTargetIsSetToNull() [MethodImpl(MethodImplOptions.NoInlining)] static DependentHandle Initialize(out object target, out WeakReference weakDependent) { - target = new(); + target = new object(); object dependent = new(); @@ -268,7 +268,7 @@ public void SetTarget_NotAllocated_ThrowsInvalidOperationException() Assert.Throws(() => { DependentHandle handle = default; - handle.Target = new(); + handle.Target = new object(); }); } @@ -281,7 +281,7 @@ public void SetTarget_NotNullObject_ThrowsInvalidOperationException() try { - handle.Target = new(); + handle.Target = new object(); } finally { @@ -296,7 +296,7 @@ public void SetDependent_ThrowsInvalidOperationException() Assert.Throws(() => { DependentHandle handle = default; - handle.Dependent = new(); + handle.Dependent = new object(); }); } diff --git a/src/libraries/System.Security.Cryptography.Cose/tests/CoseSign1MessageTests.Sign.cs b/src/libraries/System.Security.Cryptography.Cose/tests/CoseSign1MessageTests.Sign.cs index 696b7c2eee7f3b910495ecc83e46348f7c690fa6..8a0c6a5edd117c7c9e21a0f3e7b8b194c796c498 100644 --- a/src/libraries/System.Security.Cryptography.Cose/tests/CoseSign1MessageTests.Sign.cs +++ b/src/libraries/System.Security.Cryptography.Cose/tests/CoseSign1MessageTests.Sign.cs @@ -285,7 +285,7 @@ void Initialize() mapForCustomHeader = useProtectedMap ? protectedHeaders : unprotectedHeaders; expectedProtectedHeaders = GetExpectedProtectedHeaders(); - expectedUnprotectedHeaders = new(); + expectedUnprotectedHeaders = new List<(CoseHeaderLabel, ReadOnlyMemory)>(); listForCustomHeader = useProtectedMap ? expectedProtectedHeaders : expectedUnprotectedHeaders; } } diff --git a/src/libraries/System.Security.Cryptography.Cose/tests/CoseTestHelpers.cs b/src/libraries/System.Security.Cryptography.Cose/tests/CoseTestHelpers.cs index 461382b715fd1f7e79452e5f54b128b750fc9c4f..239c37cea831a693f682432eec91ef3d418b0593 100644 --- a/src/libraries/System.Security.Cryptography.Cose/tests/CoseTestHelpers.cs +++ b/src/libraries/System.Security.Cryptography.Cose/tests/CoseTestHelpers.cs @@ -235,7 +235,7 @@ private static void AssertSign1Headers(CborReader reader, List<(CoseHeaderLabel, private static ECParameters CreateECParameters(string curveFriendlyName, string base64UrlQx, string base64UrlQy, string base64UrlPrivateKey) { - return new() + return new ECParameters() { Curve = ECCurve.CreateFromFriendlyName(curveFriendlyName), Q = new ECPoint diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConverterList.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConverterList.cs index da2391d4045225e0b5b81fd7a2498bd5a06e481f..a2f65ff8fe893a80038ce8252cb433a287ab10fd 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConverterList.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/ConverterList.cs @@ -17,7 +17,7 @@ internal sealed class ConverterList : IList public ConverterList(JsonSerializerOptions options) { _options = options; - _list = new(); + _list = new List(); } public ConverterList(JsonSerializerOptions options, ConverterList source) diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Caching.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Caching.cs index 75f7b9801a42693d4a6790c17e7dbca40f9c71c8..fd62229d44f175de06f39d4551d51570d3ee8b9e 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Caching.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializerOptions.Caching.cs @@ -172,7 +172,7 @@ public static CachingContext GetOrCreate(JsonSerializerOptions options) Debug.Assert(key._cachingContext == null); ctx = new CachingContext(options); - bool success = cache.TryAdd(key, new(ctx)); + bool success = cache.TryAdd(key, new WeakReference(ctx)); Debug.Assert(success); return ctx; diff --git a/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Dictionary.NonStringKey.cs b/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Dictionary.NonStringKey.cs index 2c2ee556fbb991cc043da8415576642b6858362b..eb050d1bb81fdef3045b677ca96dc5545fbeae84 100644 --- a/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Dictionary.NonStringKey.cs +++ b/src/libraries/System.Text.Json/tests/Common/CollectionTests/CollectionTests.Dictionary.NonStringKey.cs @@ -679,7 +679,7 @@ public class CustomInt32ConverterSerializerContext : JsonSerializerContext JsonTypeInfo valueInfo = JsonMetadataServices.CreateValueInfo(Options, JsonMetadataServices.StringConverter); JsonCollectionInfoValues> info = new() { - ObjectCreator = () => new(), + ObjectCreator = () => new Dictionary(), KeyInfo = keyInfo, ElementInfo = valueInfo, }; diff --git a/src/libraries/System.Text.Json/tests/Common/UnsupportedTypesTests.cs b/src/libraries/System.Text.Json/tests/Common/UnsupportedTypesTests.cs index 09a428b20b816fc4c55e0a877cd0dad9ab0beb45..73d2a845275d1a84ccfa3a8ae333a35601fcac92 100644 --- a/src/libraries/System.Text.Json/tests/Common/UnsupportedTypesTests.cs +++ b/src/libraries/System.Text.Json/tests/Common/UnsupportedTypesTests.cs @@ -237,7 +237,7 @@ public async Task RuntimeConverterIsSupported_AsyncEnumerable() Assert.Equal("Read", obj.Status); ClassWithAsyncEnumerableConverter poco = new(); - poco.MyAsyncEnumerable = new(); + poco.MyAsyncEnumerable = new ClassThatImplementsIAsyncEnumerable(); Assert.Equal("Created", poco.MyAsyncEnumerable.Status); serialized = await Serializer.SerializeWrapper(poco, options); Assert.Equal(Json, serialized); @@ -252,7 +252,7 @@ public async Task CompileTimeConverterIsSupported_AsyncEnumerable() const string Json = "{\"MyAsyncEnumerable\":[]}"; ClassWithAsyncEnumerableConverter obj = new(); - obj.MyAsyncEnumerable = new(); + obj.MyAsyncEnumerable = new ClassThatImplementsIAsyncEnumerable(); Assert.Equal("Created", obj.MyAsyncEnumerable.Status); string serialized = await Serializer.SerializeWrapper(obj); diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs index 3e3ae63472535cceb1df44caf33327bf797fc371..8496254aaed348aa67c5bcc61014253ea508995f 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/ContinuationTests.cs @@ -390,7 +390,7 @@ private class DictionaryTestClass : ITestObject where TNested : INested void ITestObject.Initialize(INestedObject nested) { nested.Initialize(); - A = new() { { "a", (TNested)nested }, { "b", (TNested)nested } }; + A = new Dictionary() { { "a", (TNested)nested }, { "b", (TNested)nested } }; } void ITestObject.Verify() diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs index 8fed9581d4d26829d958874103a1b701d58098a7..afc2a31e3ecd890d0f1f567ee0ce70c6417d60c2 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/NumberHandlingTests.cs @@ -1767,7 +1767,7 @@ public static void AdaptableCustomConverter() Converters = { new AdaptableInt32Converter() } }; - obj = new() { Prop = new List() { 1 } }; + obj = new PlainClassWithList() { Prop = new List() { 1 } }; json = JsonSerializer.Serialize(obj, options); Assert.Equal("{\"Prop\":[101]}", json); @@ -1775,13 +1775,13 @@ public static void AdaptableCustomConverter() Assert.Equal(1, obj.Prop[0]); // Then with strings - options = new() + options = new JsonSerializerOptions() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString, Converters = { new AdaptableInt32Converter() } }; - obj = new() { Prop = new List() { 1 } }; + obj = new PlainClassWithList() { Prop = new List() { 1 } }; json = JsonSerializer.Serialize(obj, options); Assert.Equal("{\"Prop\":[\"101\"]}", json); diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs index 6a0b41a6c6cf35d00ca662620bc4b28a9ee6d3fb..5547039f053546b463d93f30c0c63ee8fcecb1b4 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs @@ -132,7 +132,10 @@ public RegexFindOptimizations(RegexNode root, RegexOptions options, CultureInfo else { // The set may match multiple characters. Search for that. - FixedDistanceSets = new() { (chars, set.CharClass, 0, set.CaseInsensitive) }; + FixedDistanceSets = new List<(char[]? Chars, string Set, int Distance, bool CaseInsensitive)>() + { + (chars, set.CharClass, 0, set.CaseInsensitive) + }; FindMode = set.CaseInsensitive ? FindNextStartingPositionMode.LeadingSet_RightToLeft_CaseInsensitive : FindNextStartingPositionMode.LeadingSet_RightToLeft_CaseSensitive; diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexTreeAnalyzer.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexTreeAnalyzer.cs index 51c16ba651e60f349555b51f8b57af221e1d9cf6..36f6887b0b3c38527e1b385a8a9f6d9a8f99a0b6 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexTreeAnalyzer.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexTreeAnalyzer.cs @@ -43,7 +43,7 @@ static bool TryAnalyze(RegexNode node, AnalysisResults results, bool isAtomicByA case RegexNodeKind.Alternate: case RegexNodeKind.Loop or RegexNodeKind.Lazyloop when node.M != node.N: case RegexNodeKind.Oneloop or RegexNodeKind.Notoneloop or RegexNodeKind.Setloop or RegexNodeKind.Onelazy or RegexNodeKind.Notonelazy or RegexNodeKind.Setlazy when node.M != node.N: - (results._mayBacktrack ??= new()).Add(node); + (results._mayBacktrack ??= new HashSet()).Add(node); break; } } @@ -120,7 +120,7 @@ static bool TryAnalyze(RegexNode node, AnalysisResults results, bool isAtomicByA // will be visible from this node to it. if (!isAtomicBySelf && (results._mayBacktrack?.Contains(child) == true)) { - (results._mayBacktrack ??= new()).Add(node); + (results._mayBacktrack ??= new HashSet()).Add(node); } } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/RegexNodeConverter.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/RegexNodeConverter.cs index 698f9fce3fa40a3a37c0b010b0f1d696237a2047..a2571f10b71addbea255d533ea5b01e14c5b8f9c 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/RegexNodeConverter.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/RegexNodeConverter.cs @@ -263,7 +263,7 @@ bool TryGetIntersection(RegexNode node, [Diagnostics.CodeAnalysis.NotNullWhen(tr return false; } - conjuncts = new(); + conjuncts = new List(); conjuncts.Add(node.Child(0)); node = node.Child(1); while (IsIntersect(node)) @@ -293,7 +293,7 @@ private BDD CreateBDDFromSetString(bool ignoreCase, string set) } // Lazily-initialize the set cache on first use, since some expressions may not have character classes in them. - _setBddCache ??= new(); + _setBddCache ??= new Dictionary<(bool IgnoreCase, string Set), BDD>(); // Try to get the cached BDD for the combined ignoreCase+set key. // If one doesn't yet exist, compute and populate it. diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexMatcher.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexMatcher.cs index 0d541be0a30ff4e6efa8e3d469bec9a22840e6ae..fac9e55c28103aaf3470faa90ca79358ee9e154b 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexMatcher.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexMatcher.cs @@ -1053,8 +1053,8 @@ public PerThreadData(SymbolicRegexBuilder builder, int capsize) // Only create data used for capturing mode if there are subcaptures if (capsize > 1) { - Current = new(); - Next = new(); + Current = new SparseIntMap(); + Next = new SparseIntMap(); InitialRegisters = new Registers(new int[capsize], new int[capsize]); } } diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexNode.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexNode.cs index 59522b71116bd95ade330c831d8a324f0cb4409f..800a42116a3fbae02a813cb228ccd76c1991c6bc 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexNode.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Symbolic/SymbolicRegexNode.cs @@ -75,14 +75,14 @@ private static SymbolicRegexNode Create(SymbolicRegexBuilder builder, Symb // Do not internalize top level Or-nodes or else NFA mode will become ineffective if (kind == SymbolicRegexNodeKind.Or) { - node = new(builder, kind, left, right, lower, upper, set, alts, info); + node = new SymbolicRegexNode(builder, kind, left, right, lower, upper, set, alts, info); return node; } left = left == null || left._kind != SymbolicRegexNodeKind.Or || left._isInternalizedUnion ? left : Internalize(left); right = right == null || right._kind != SymbolicRegexNodeKind.Or || right._isInternalizedUnion ? right : Internalize(right); - node = new(builder, kind, left, right, lower, upper, set, alts, info); + node = new SymbolicRegexNode(builder, kind, left, right, lower, upper, set, alts, info); builder._nodeCache[key] = node; }