From 9f7bf79991df506f75d6d4a1b48d25dcaa2326b9 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 28 Jun 2022 14:46:45 -0400 Subject: [PATCH] Enable IDE0170 (Simplify property pattern) and IDE0200 (remove unnecessary lambda expression) (#71011) As part of updating the config file with recently added rules, also turn on a few of them. --- eng/CodeAnalysis.src.globalconfig | 24 +++++++++-- eng/CodeAnalysis.test.globalconfig | 24 +++++++++-- .../InteropServices/Marshal.CoreCLR.cs | 16 +++---- .../Interop.ASN1.GetIntegerBytes.cs | 4 +- .../Interop.ASN1.Nid.cs | 2 +- .../Interop.Crypto.cs | 8 ++-- .../Interop.PooledCrypto.cs | 2 +- .../Interop.X509.cs | 4 +- .../Interop.X509Name.cs | 4 +- .../Interop.X509StoreCtx.cs | 2 +- .../ECDiffieHellmanAndroid.Derive.cs | 6 +-- .../ECDiffieHellmanOpenSsl.Derive.cs | 6 +-- .../ECDiffieHellmanSecurityTransforms.cs | 6 +-- .../src/ConfigurationManager.cs | 4 +- .../src/ConfigurationRoot.cs | 2 +- .../src/ServiceLookup/CallSiteFactory.cs | 2 +- .../src/ServiceLookup/CallSiteVisitor.cs | 2 +- .../src/PhysicalFileProvider.cs | 2 +- .../src/WindowsServiceLifetime.cs | 5 +-- .../src/OptionsMonitor.cs | 4 +- .../DataAnnotations/ValidationContext.cs | 2 +- .../Composition/AttributedModelServices.cs | 2 +- .../Hosting/FilteredCatalog.Traversal.cs | 2 +- .../ExportfactoryCreator.LifetimeContext.cs | 2 +- .../ReflectionModel/ExportfactoryCreator.cs | 2 +- .../System/ComponentModel/BackgroundWorker.cs | 2 +- .../Hosting/Core/ExportDescriptorProvider.cs | 2 +- .../Composition/Hosting/Util/Formatters.cs | 2 +- .../Composition/Runtime/Util/Formatters.cs | 2 +- .../src/System/Data/Common/SqlUDTStorage.cs | 2 +- .../src/System/Data/TypeLimiter.cs | 2 +- .../Diagnostics/Metrics/MeterListener.cs | 4 +- .../Formats/Asn1/AsnDecoder.BitString.cs | 2 +- .../src/System/Net/Http/WinHttpHandler.cs | 2 +- .../src/System/Net/WebRequest.cs | 2 +- .../InteropServices/ComponentActivator.cs | 2 +- .../Diagnostics/Tracing/EventProvider.cs | 3 +- .../src/System/IO/FileSystem.Unix.cs | 2 +- .../Runtime/Serialization/AccessorBuilder.cs | 5 +-- .../ReflectionXmlSerializationReader.cs | 43 ++++--------------- .../Reflection/TypeLoading/General/Helpers.cs | 5 +-- .../Serialization/SerializationEventsCache.cs | 2 +- .../Security/Cryptography/Pkcs/CmsSigner.cs | 2 +- .../Cryptography/AsymmetricAlgorithm.cs | 10 ++--- .../ECDsaCertificateExtensions.cs | 4 +- .../X509Certificates/OpenSslExportProvider.cs | 4 +- .../OpenSslX509CertificateReader.cs | 4 +- .../OpenSslX509ChainProcessor.cs | 6 +-- .../X509Certificates/X509Certificate2.cs | 4 +- .../AtomPub10CategoriesDocumentFormatter.cs | 4 +- .../Internal/SapiInterop/SapiRecoContext.cs | 2 +- .../gen/JsonSourceGenerator.Parser.cs | 2 +- .../gen/RegexGenerator.Emitter.cs | 2 +- .../gen/RegexGenerator.Parser.cs | 2 +- .../src/Blocks/BatchBlock.cs | 2 +- .../Reflection/Metadata/MetadataUpdater.cs | 2 +- .../debugger/BrowserDebugProxy/DebugStore.cs | 2 +- src/tasks/AotCompilerTask/MonoAOTCompiler.cs | 2 +- 58 files changed, 138 insertions(+), 139 deletions(-) diff --git a/eng/CodeAnalysis.src.globalconfig b/eng/CodeAnalysis.src.globalconfig index 95f58b409563a..a21a9e9ef00c4 100644 --- a/eng/CodeAnalysis.src.globalconfig +++ b/eng/CodeAnalysis.src.globalconfig @@ -1445,9 +1445,6 @@ dotnet_diagnostic.IDE0048.severity = silent # IDE0049: Use language keywords instead of framework type names for type references dotnet_diagnostic.IDE0049.severity = warning -# IDE0050: Convert anonymous type to tuple -dotnet_diagnostic.IDE0050.severity = suggestion - # IDE0051: Remove unused private members dotnet_diagnostic.IDE0051.severity = suggestion @@ -1569,6 +1566,27 @@ dotnet_diagnostic.IDE0160.severity = silent # IDE0161: Convert to file-scoped namespace dotnet_diagnostic.IDE0161.severity = silent +# IDE0170: Simplify property pattern +dotnet_diagnostic.IDE0170.severity = warning + +# IDE0180: Use tuple swap +dotnet_diagnostic.IDE0180.severity = suggestion + +# IDE0200: Remove unnecessary lambda expression +dotnet_diagnostic.IDE0200.severity = warning + +# IDE0210: Use top-level statements +dotnet_diagnostic.IDE0210.severity = silent + +# IDE0211: Use program main +dotnet_diagnostic.IDE0211.severity = silent + +# IDE0220: foreach cast +dotnet_diagnostic.IDE0220.severity = silent + +# IDE0230: Use UTF8 string literal +dotnet_diagnostic.IDE0230.severity = suggestion + # IDE1005: Delegate invocation can be simplified. dotnet_diagnostic.IDE1005.severity = warning diff --git a/eng/CodeAnalysis.test.globalconfig b/eng/CodeAnalysis.test.globalconfig index 59fc4e0022deb..d5d00ae4af2d2 100644 --- a/eng/CodeAnalysis.test.globalconfig +++ b/eng/CodeAnalysis.test.globalconfig @@ -1440,9 +1440,6 @@ dotnet_diagnostic.IDE0048.severity = silent # IDE0049: Use language keywords instead of framework type names for type references dotnet_diagnostic.IDE0049.severity = silent -# IDE0050: Convert anonymous type to tuple -dotnet_diagnostic.IDE0050.severity = silent - # IDE0051: Remove unused private members dotnet_diagnostic.IDE0051.severity = silent @@ -1563,6 +1560,27 @@ dotnet_diagnostic.IDE0160.severity = silent # IDE0161: Convert to file-scoped namespace dotnet_diagnostic.IDE0161.severity = silent +# IDE0170: Simplify property pattern +dotnet_diagnostic.IDE0170.severity = silent + +# IDE0180: Use tuple swap +dotnet_diagnostic.IDE0180.severity = silent + +# IDE0200: Remove unnecessary lambda expression +dotnet_diagnostic.IDE0200.severity = silent + +# IDE0210: Use top-level statements +dotnet_diagnostic.IDE0210.severity = silent + +# IDE0211: Use program main +dotnet_diagnostic.IDE0211.severity = silent + +# IDE0220: foreach cast +dotnet_diagnostic.IDE0220.severity = silent + +# IDE0230: Use UTF8 string literal +dotnet_diagnostic.IDE0230.severity = silent + # IDE1005: Delegate invocation can be simplified. dotnet_diagnostic.IDE1005.severity = silent diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs index 4b6592369ea7f..4ee3f10c2d40d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs @@ -57,7 +57,7 @@ public static IntPtr OffsetOf(Type t, string fieldName) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static byte ReadByte(object ptr, int ofs) { - return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadByte(nativeHome, offset)); + return ReadValueSlow(ptr, ofs, ReadByte); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -65,7 +65,7 @@ public static byte ReadByte(object ptr, int ofs) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static short ReadInt16(object ptr, int ofs) { - return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt16(nativeHome, offset)); + return ReadValueSlow(ptr, ofs, ReadInt16); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -73,7 +73,7 @@ public static short ReadInt16(object ptr, int ofs) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static int ReadInt32(object ptr, int ofs) { - return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt32(nativeHome, offset)); + return ReadValueSlow(ptr, ofs, ReadInt32); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -83,7 +83,7 @@ public static int ReadInt32(object ptr, int ofs) public static long ReadInt64([MarshalAs(UnmanagedType.AsAny), In] object ptr, int ofs) #pragma warning restore CS0618 // Type or member is obsolete { - return ReadValueSlow(ptr, ofs, (IntPtr nativeHome, int offset) => ReadInt64(nativeHome, offset)); + return ReadValueSlow(ptr, ofs, ReadInt64); } /// Read value from marshaled object (marshaled using AsAny). @@ -125,7 +125,7 @@ private static unsafe T ReadValueSlow(object ptr, int ofs, Func WriteByte(nativeHome, offset, value)); + WriteValueSlow(ptr, ofs, val, WriteByte); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -133,7 +133,7 @@ public static void WriteByte(object ptr, int ofs, byte val) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static void WriteInt16(object ptr, int ofs, short val) { - WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, short value) => Marshal.WriteInt16(nativeHome, offset, value)); + WriteValueSlow(ptr, ofs, val, Marshal.WriteInt16); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -141,7 +141,7 @@ public static void WriteInt16(object ptr, int ofs, short val) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static void WriteInt32(object ptr, int ofs, int val) { - WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, int value) => Marshal.WriteInt32(nativeHome, offset, value)); + WriteValueSlow(ptr, ofs, val, Marshal.WriteInt32); } [EditorBrowsable(EditorBrowsableState.Never)] @@ -149,7 +149,7 @@ public static void WriteInt32(object ptr, int ofs, int val) [RequiresDynamicCode("Marshalling code for the object might not be available")] public static void WriteInt64(object ptr, int ofs, long val) { - WriteValueSlow(ptr, ofs, val, (IntPtr nativeHome, int offset, long value) => Marshal.WriteInt64(nativeHome, offset, value)); + WriteValueSlow(ptr, ofs, val, Marshal.WriteInt64); } /// diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs index a5af06c76a940..abbd2e4620e10 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.GetIntegerBytes.cs @@ -31,8 +31,8 @@ internal static byte[] GetAsn1IntegerBytes(SafeSharedAsn1IntegerHandle asn1Integ // wrong endianness here), DER encode it, then use the DER reader to skip past the tag // and length. byte[] derEncoded = OpenSslEncode( - handle => GetAsn1IntegerDerSize(handle), - (handle, buf) => EncodeAsn1Integer(handle, buf), + GetAsn1IntegerDerSize, + EncodeAsn1Integer, asn1Integer); try diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs index 3de8f890eb8f2..cc22af2a6d03a 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.ASN1.Nid.cs @@ -20,7 +20,7 @@ internal static partial class Crypto internal static int ResolveRequiredNid(string oid) { - return s_nidLookup.GetOrAdd(oid, s => LookupNid(s)); + return s_nidLookup.GetOrAdd(oid, LookupNid); } private static int LookupNid(string oid) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs index 50dc4c2478fd0..a2f209e837c38 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Crypto.cs @@ -107,25 +107,25 @@ private static partial int CryptoNative_X509StoreSetVerifyTime( internal static byte[] GetAsn1StringBytes(IntPtr asn1) { - return GetDynamicBuffer((ptr, buf, i) => GetAsn1StringBytes(ptr, buf, i), asn1); + return GetDynamicBuffer(GetAsn1StringBytes, asn1); } internal static byte[] GetX509Thumbprint(SafeX509Handle x509) { - return GetDynamicBuffer((handle, buf, i) => GetX509Thumbprint(handle, buf, i), x509); + return GetDynamicBuffer(GetX509Thumbprint, x509); } internal static X500DistinguishedName LoadX500Name(IntPtr namePtr) { CheckValidOpenSslHandle(namePtr); - byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr); + byte[] buf = GetDynamicBuffer(GetX509NameRawBytes, namePtr); return new X500DistinguishedName(buf); } internal static byte[] GetX509PublicKeyParameterBytes(SafeX509Handle x509) { - return GetDynamicBuffer((handle, buf, i) => GetX509PublicKeyParameterBytes(handle, buf, i), x509); + return GetDynamicBuffer(GetX509PublicKeyParameterBytes, x509); } internal static void X509StoreSetVerifyTime(SafeX509StoreHandle ctx, DateTime verifyTime) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.PooledCrypto.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.PooledCrypto.cs index 3d7c192659d3e..ae78b51f7fcc4 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.PooledCrypto.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.PooledCrypto.cs @@ -10,7 +10,7 @@ internal static partial class Crypto { internal static ArraySegment RentAsn1StringBytes(IntPtr asn1) { - return RentDynamicBuffer((ptr, buf, i) => GetAsn1StringBytes(ptr, buf, i), asn1); + return RentDynamicBuffer(GetAsn1StringBytes, asn1); } private static ArraySegment RentDynamicBuffer(NegativeSizeReadMethod method, THandle handle) diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs index ede2291117371..1362a2a9a7525 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509.cs @@ -90,7 +90,7 @@ internal static SafeSharedAsn1IntegerHandle X509GetSerialNumber(SafeX509Handle x CheckValidOpenSslHandle(x); return SafeInteriorHandle.OpenInteriorHandle( - handle => X509GetSerialNumber_private(handle), + X509GetSerialNumber_private, x); } @@ -117,7 +117,7 @@ internal static SafeSharedAsn1OctetStringHandle X509FindExtensionData(SafeX509Ha CheckValidOpenSslHandle(x); return SafeInteriorHandle.OpenInteriorHandle( - (handle, arg) => CryptoNative_X509FindExtensionData(handle, arg), + CryptoNative_X509FindExtensionData, x, extensionNid); } diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs index 0bc5e5a821f76..9cd1e9e8bd254 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509Name.cs @@ -24,7 +24,7 @@ internal static X500DistinguishedName LoadX500Name(SafeSharedX509NameHandle name { CheckValidOpenSslHandle(namePtr); - byte[] buf = GetDynamicBuffer((ptr, buf1, i) => GetX509NameRawBytes(ptr, buf1, i), namePtr); + byte[] buf = GetDynamicBuffer(GetX509NameRawBytes, namePtr); return new X500DistinguishedName(buf); } @@ -33,7 +33,7 @@ internal static SafeSharedX509NameHandle GetX509NameStackField(SafeSharedX509Nam CheckValidOpenSslHandle(sk); return SafeInteriorHandle.OpenInteriorHandle( - (handle, i) => GetX509NameStackField_private(handle, i), + GetX509NameStackField_private, sk, loc); } diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs index 08cf5b40b41fb..808dd56f4f80c 100644 --- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs +++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.X509StoreCtx.cs @@ -61,7 +61,7 @@ internal static void X509StoreCtxResetForSignatureError( internal static SafeSharedX509StackHandle X509StoreCtxGetSharedUntrusted(SafeX509StoreCtxHandle ctx) { return SafeInteriorHandle.OpenInteriorHandle( - x => X509StoreCtxGetSharedUntrusted_private(x), + X509StoreCtxGetSharedUntrusted_private, ctx); } } diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs index 4c266209ea6f3..94763e9b4588c 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanAndroid.Derive.cs @@ -33,7 +33,7 @@ public override byte[] DeriveKeyFromHash( hashAlgorithm, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyFromHmac( @@ -54,7 +54,7 @@ public override byte[] DeriveKeyFromHmac( hmacKey, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed) @@ -69,7 +69,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey otherPartyPublicKey, prfLabel, prfSeed, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } /// diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs index 734047e7e255b..beb222fa5a133 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanOpenSsl.Derive.cs @@ -30,7 +30,7 @@ public override byte[] DeriveKeyFromHash( hashAlgorithm, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyFromHmac( @@ -51,7 +51,7 @@ public override byte[] DeriveKeyFromHmac( hmacKey, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed) @@ -66,7 +66,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey otherPartyPublicKey, prfLabel, prfSeed, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } /// diff --git a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs index 9033c3af00c4f..dd5a73838a159 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/ECDiffieHellmanSecurityTransforms.cs @@ -136,7 +136,7 @@ public override byte[] DeriveKeyFromHash( hashAlgorithm, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyFromHmac( @@ -157,7 +157,7 @@ public override byte[] DeriveKeyFromHmac( hmacKey, secretPrepend, secretAppend, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed) @@ -172,7 +172,7 @@ public override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey otherPartyPublicKey, prfLabel, prfSeed, - (pubKey, hasher) => DeriveSecretAgreement(pubKey, hasher)); + DeriveSecretAgreement); } private byte[]? DeriveSecretAgreement(ECDiffieHellmanPublicKey otherPartyPublicKey, IncrementalHash? hasher) diff --git a/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationManager.cs b/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationManager.cs index 5b27bfb8ccbe2..fda645e7923a5 100644 --- a/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationManager.cs +++ b/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationManager.cs @@ -120,7 +120,7 @@ private void AddSource(IConfigurationSource source) IConfigurationProvider provider = source.Build(this); provider.Load(); - _changeTokenRegistrations.Add(ChangeToken.OnChange(() => provider.GetReloadToken(), () => RaiseChanged())); + _changeTokenRegistrations.Add(ChangeToken.OnChange(provider.GetReloadToken, RaiseChanged)); _providerManager.AddProvider(provider); RaiseChanged(); @@ -143,7 +143,7 @@ private void ReloadSources() foreach (IConfigurationProvider p in newProvidersList) { p.Load(); - _changeTokenRegistrations.Add(ChangeToken.OnChange(() => p.GetReloadToken(), () => RaiseChanged())); + _changeTokenRegistrations.Add(ChangeToken.OnChange(p.GetReloadToken, RaiseChanged)); } _providerManager.ReplaceProviders(newProvidersList); diff --git a/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationRoot.cs b/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationRoot.cs index 74f53a8d6c6bb..2e3455bd17f1e 100644 --- a/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationRoot.cs +++ b/src/libraries/Microsoft.Extensions.Configuration/src/ConfigurationRoot.cs @@ -30,7 +30,7 @@ public ConfigurationRoot(IList providers) foreach (IConfigurationProvider p in providers) { p.Load(); - _changeTokenRegistrations.Add(ChangeToken.OnChange(() => p.GetReloadToken(), () => RaiseChanged())); + _changeTokenRegistrations.Add(ChangeToken.OnChange(p.GetReloadToken, RaiseChanged)); } } diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs index 81add91190dae..07052e920c67e 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteFactory.cs @@ -179,7 +179,7 @@ private static bool AreCompatible(DynamicallyAccessedMemberTypes serviceDynamica { if (!_stackGuard.TryEnterOnCurrentStack()) { - return _stackGuard.RunOnEmptyStack((type, chain) => CreateCallSite(type, chain), serviceType, callSiteChain); + return _stackGuard.RunOnEmptyStack(CreateCallSite, serviceType, callSiteChain); } // We need to lock the resolution process for a single service type at a time: diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs index b7143a2c577fc..3b2dbee3ea20d 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteVisitor.cs @@ -18,7 +18,7 @@ protected virtual TResult VisitCallSite(ServiceCallSite callSite, TArgument argu { if (!_stackGuard.TryEnterOnCurrentStack()) { - return _stackGuard.RunOnEmptyStack((c, a) => VisitCallSite(c, a), callSite, argument); + return _stackGuard.RunOnEmptyStack(VisitCallSite, callSite, argument); } switch (callSite.Cache.Location) diff --git a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs index de633a8c53191..fb2306d56e9f9 100644 --- a/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs +++ b/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFileProvider.cs @@ -67,7 +67,7 @@ public PhysicalFileProvider(string root, ExclusionFilters filters) } _filters = filters; - _fileWatcherFactory = () => CreateFileWatcher(); + _fileWatcherFactory = CreateFileWatcher; } /// diff --git a/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs b/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs index b535f51f2beef..a6101b49f7eaa 100644 --- a/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs +++ b/src/libraries/Microsoft.Extensions.Hosting.WindowsServices/src/WindowsServiceLifetime.cs @@ -54,10 +54,7 @@ public Task WaitForStartAsync(CancellationToken cancellationToken) { Logger.LogInformation("Application is shutting down..."); }); - ApplicationLifetime.ApplicationStopped.Register(() => - { - _delayStop.Set(); - }); + ApplicationLifetime.ApplicationStopped.Register(_delayStop.Set); Thread thread = new Thread(Run); thread.IsBackground = true; diff --git a/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs b/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs index 39301d8816e85..a736240557289 100644 --- a/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs +++ b/src/libraries/Microsoft.Extensions.Options/src/OptionsMonitor.cs @@ -36,8 +36,8 @@ public OptionsMonitor(IOptionsFactory factory, IEnumerable source) { IDisposable registration = ChangeToken.OnChange( - () => source.GetChangeToken(), - (name) => InvokeChanged(name), + source.GetChangeToken, + InvokeChanged, source.Name); _registrations.Add(registration); diff --git a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs index 8708881796026..a0b8d71a6ca35 100644 --- a/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs +++ b/src/libraries/System.ComponentModel.Annotations/src/System/ComponentModel/DataAnnotations/ValidationContext.cs @@ -91,7 +91,7 @@ public ValidationContext(object instance, IServiceProvider? serviceProvider, IDi if (serviceProvider != null) { IServiceProvider localServiceProvider = serviceProvider; - InitializeServiceProvider(serviceType => localServiceProvider.GetService(serviceType)); + InitializeServiceProvider(localServiceProvider.GetService); } _items = items != null ? new Dictionary(items) : new Dictionary(); diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModelServices.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModelServices.cs index 3763bb90e2d4c..9b5435a94f824 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModelServices.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/AttributedModelServices.cs @@ -151,7 +151,7 @@ public static void ComposeParts(this CompositionContainer container, params obje Requires.NotNullOrNullElements(attributedParts, nameof(attributedParts)); CompositionBatch batch = new CompositionBatch( - attributedParts.Select(attributedPart => AttributedModelServices.CreatePart(attributedPart)).ToArray(), + attributedParts.Select(AttributedModelServices.CreatePart).ToArray(), Enumerable.Empty()); container.Compose(batch); diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/FilteredCatalog.Traversal.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/FilteredCatalog.Traversal.cs index 57ad4ed0d92ca..39b06528d960f 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/FilteredCatalog.Traversal.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/FilteredCatalog.Traversal.cs @@ -69,7 +69,7 @@ private FilteredCatalog Traverse(IComposablePartCatalogTraversal traversal) { traversal.Initialize(); var traversalClosure = GetTraversalClosure(_innerCatalog.Where(_filter), traversal); - return new FilteredCatalog(_innerCatalog, p => traversalClosure.Contains(p)); + return new FilteredCatalog(_innerCatalog, traversalClosure.Contains); } finally { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.LifetimeContext.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.LifetimeContext.cs index 9321e722f5943..0ebbeae0e3ab6 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.LifetimeContext.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.LifetimeContext.cs @@ -47,7 +47,7 @@ public static Tuple GetExportLifetimeContextFromExport(Export expo if (disposable != null) { - disposeAction = () => disposable.Dispose(); + disposeAction = disposable.Dispose; } else { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.cs index 7c0b4db850762..d49741aab0c61 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ReflectionModel/ExportfactoryCreator.cs @@ -38,7 +38,7 @@ public Func CreateStronglyTypedExportFactoryFactory(Type exportT } Func exportFactoryFactory = (Func)Delegate.CreateDelegate(typeof(Func), this, genericMethod); - return (e) => exportFactoryFactory.Invoke(e); + return exportFactoryFactory.Invoke; } private object CreateStronglyTypedExportFactoryOfT(Export export) diff --git a/src/libraries/System.ComponentModel.EventBasedAsync/src/System/ComponentModel/BackgroundWorker.cs b/src/libraries/System.ComponentModel.EventBasedAsync/src/System/ComponentModel/BackgroundWorker.cs index 552ef1de2523d..d0e1e7a4e6675 100644 --- a/src/libraries/System.ComponentModel.EventBasedAsync/src/System/ComponentModel/BackgroundWorker.cs +++ b/src/libraries/System.ComponentModel.EventBasedAsync/src/System/ComponentModel/BackgroundWorker.cs @@ -126,7 +126,7 @@ public void RunWorkerAsync(object? argument) _asyncOperation = AsyncOperationManager.CreateOperation(null); Task.Factory.StartNew( - arg => WorkerThreadStart(arg), + WorkerThreadStart, argument, CancellationToken.None, TaskCreationOptions.DenyChildAttach, diff --git a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Core/ExportDescriptorProvider.cs b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Core/ExportDescriptorProvider.cs index 39948b9d73962..da6737f10b3bc 100644 --- a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Core/ExportDescriptorProvider.cs +++ b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Core/ExportDescriptorProvider.cs @@ -28,7 +28,7 @@ public abstract class ExportDescriptorProvider /// /// Constant value provided so that subclasses can avoid creating additional duplicate values. /// - protected static readonly Func> NoDependencies = () => Enumerable.Empty(); + protected static readonly Func> NoDependencies = Enumerable.Empty; /// /// Promise export descriptors for the specified export key. diff --git a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Util/Formatters.cs b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Util/Formatters.cs index 863fccf11b85b..c7e0af32f4ba7 100644 --- a/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Util/Formatters.cs +++ b/src/libraries/System.Composition.Hosting/src/System/Composition/Hosting/Util/Formatters.cs @@ -46,7 +46,7 @@ private static string FormatClosedGeneric(Type closedGenericType) } var name = closedGenericType.Name.Substring(0, closedGenericType.Name.IndexOf('`')); - var args = closedGenericType.GenericTypeArguments.Select(t => Format(t)); + var args = closedGenericType.GenericTypeArguments.Select(Format); return $"{name}<{string.Join(", ", args)}>"; } } diff --git a/src/libraries/System.Composition.Runtime/src/System/Composition/Runtime/Util/Formatters.cs b/src/libraries/System.Composition.Runtime/src/System/Composition/Runtime/Util/Formatters.cs index 2120fb035eb1e..104ba2f4a4cab 100644 --- a/src/libraries/System.Composition.Runtime/src/System/Composition/Runtime/Util/Formatters.cs +++ b/src/libraries/System.Composition.Runtime/src/System/Composition/Runtime/Util/Formatters.cs @@ -25,7 +25,7 @@ private static string FormatClosedGeneric(Type closedGenericType) Debug.Assert(closedGenericType.IsConstructedGenericType); var name = closedGenericType.Name.Substring(0, closedGenericType.Name.IndexOf('`')); - IEnumerable args = closedGenericType.GenericTypeArguments.Select(t => Format(t)); + IEnumerable args = closedGenericType.GenericTypeArguments.Select(Format); return $"{name}<{string.Join(SR.Formatter_ListSeparatorWithSpace, args)}>"; } } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/SqlUDTStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/SqlUDTStorage.cs index 244b1096e68e2..41b70d77cb6a3 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/SqlUDTStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/SqlUDTStorage.cs @@ -35,7 +35,7 @@ private SqlUdtStorage(DataColumn column, Type type, object nullValue) } // to support oracle types and other INUllable types that have static Null as field - internal static object GetStaticNullForUdtType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)] Type type) => s_typeToNull.GetOrAdd(type, t => GetStaticNullForUdtTypeCore(t)); + internal static object GetStaticNullForUdtType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)] Type type) => s_typeToNull.GetOrAdd(type, GetStaticNullForUdtTypeCore); [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2070:UnrecognizedReflectionPattern", Justification = "The only callsite is marked with DynamicallyAccessedMembers. Workaround for https://github.com/mono/linker/issues/1981")] diff --git a/src/libraries/System.Data.Common/src/System/Data/TypeLimiter.cs b/src/libraries/System.Data.Common/src/System/Data/TypeLimiter.cs index 59258ead096ad..4d68583c28d59 100644 --- a/src/libraries/System.Data.Common/src/System/Data/TypeLimiter.cs +++ b/src/libraries/System.Data.Common/src/System/Data/TypeLimiter.cs @@ -118,7 +118,7 @@ private static IEnumerable GetPreviouslyDeclaredDataTypes(DataTable dataTa private static IEnumerable GetPreviouslyDeclaredDataTypes(DataSet dataSet) { return (dataSet != null) - ? dataSet.Tables.Cast().SelectMany(table => GetPreviouslyDeclaredDataTypes(table)) + ? dataSet.Tables.Cast().SelectMany(GetPreviouslyDeclaredDataTypes) : Enumerable.Empty(); } diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MeterListener.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MeterListener.cs index d11a28994f545..4b3c0f12b5610 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MeterListener.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MeterListener.cs @@ -67,7 +67,7 @@ public void EnableMeasurementEvents(Instrument instrument, object? state = null) { if (instrument is not null && !_disposed && !instrument.Meter.Disposed) { - _enabledMeasurementInstruments.AddIfNotExist(instrument, (instrument1, instrument2) => object.ReferenceEquals(instrument1, instrument2)); + _enabledMeasurementInstruments.AddIfNotExist(instrument, object.ReferenceEquals); oldState = instrument.EnableMeasurement(new ListenerSubscription(this, state), out oldStateStored); enabled = true; } @@ -98,7 +98,7 @@ public void EnableMeasurementEvents(Instrument instrument, object? state = null) object? state = null; lock (Instrument.SyncObject) { - if (instrument is null || _enabledMeasurementInstruments.Remove(instrument, (instrument1, instrument2) => object.ReferenceEquals(instrument1, instrument2)) == default) + if (instrument is null || _enabledMeasurementInstruments.Remove(instrument, object.ReferenceEquals) == default) { return default; } diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.BitString.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.BitString.cs index 2af50e73c722a..e36dd619053ed 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.BitString.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/AsnDecoder.BitString.cs @@ -443,7 +443,7 @@ private static void CopyConstructedBitString( source, ruleSet, tmpDest, - (value, lastByte, dest) => CopyBitStringValue(value, lastByte, dest), + CopyBitStringValue, isIndefinite, out unusedBitCount, out bytesRead); 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 f85402999f0a6..4fa86dcac183d 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 @@ -44,7 +44,7 @@ public class WinHttpHandler : HttpMessageHandler private static readonly StringWithQualityHeaderValue s_gzipHeaderValue = new StringWithQualityHeaderValue("gzip"); private static readonly StringWithQualityHeaderValue s_deflateHeaderValue = new StringWithQualityHeaderValue("deflate"); - private static readonly Lazy s_supportsTls13 = new Lazy(() => CheckTls13Support()); + private static readonly Lazy s_supportsTls13 = new Lazy(CheckTls13Support); [ThreadStatic] private static StringBuilder? t_requestHeadersBuilder; diff --git a/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs b/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs index 80d18184ea93b..8ba5533841f11 100644 --- a/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs +++ b/src/libraries/System.Net.Requests/src/System/Net/WebRequest.cs @@ -548,7 +548,7 @@ public virtual void Abort() public static IWebProxy? DefaultWebProxy { - get => LazyInitializer.EnsureInitialized(ref s_DefaultWebProxy, ref s_DefaultWebProxyInitialized, ref s_internalSyncObject, () => GetSystemWebProxy()); + get => LazyInitializer.EnsureInitialized(ref s_DefaultWebProxy, ref s_DefaultWebProxyInitialized, ref s_internalSyncObject, GetSystemWebProxy); set { lock (s_internalSyncObject) diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs index 118afb963cfa6..50f7a5eff1305 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComponentActivator.cs @@ -194,7 +194,7 @@ private static IntPtr InternalGetFunctionPointer(AssemblyLoadContext alc, IntPtr delegateTypeNative) { // Create a resolver callback for types. - Func resolver = name => alc.LoadFromAssemblyName(name); + Func resolver = alc.LoadFromAssemblyName; // Determine the signature of the type. There are 3 possibilities: // * No delegate type was supplied - use the default (i.e. ComponentEntryPoint). diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs index b294ba0303c24..c552a897eecd2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs @@ -381,8 +381,7 @@ private List> GetSessions() List? liveSessionList = null; GetSessionInfo( - (int etwSessionId, long matchAllKeywords, ref List? sessionList) => - GetSessionInfoCallback(etwSessionId, matchAllKeywords, ref sessionList), + GetSessionInfoCallback, ref liveSessionList); List> changedSessionList = new List>(); diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs index a2aa1b070f227..24e00768edf93 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs @@ -35,7 +35,7 @@ public static void CopyFile(string sourceFullPath, string destFullPath, bool ove using SafeFileHandle src = SafeFileHandle.OpenReadOnly(sourceFullPath, FileOptions.None, out fileLength, out filePermissions); using SafeFileHandle dst = SafeFileHandle.Open(destFullPath, overwrite ? FileMode.Create : FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None, FileOptions.None, preallocationSize: 0, filePermissions, - (Interop.ErrorInfo error, Interop.Sys.OpenFlags flags, string path) => CreateOpenException(error, flags, path)); + CreateOpenException); Interop.CheckIo(Interop.Sys.CopyFile(src, dst, fileLength)); diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs index 47b6f31ccd421..e6af588406a6d 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/AccessorBuilder.cs @@ -71,10 +71,7 @@ public static Getter CreateGetter(MemberInfo memberInfo) } else { - return (obj) => - { - return propInfo.GetValue(obj); - }; + return propInfo.GetValue; } } else if (memberInfo is FieldInfo fieldInfo) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs index 25a89ebaaa383..08e4c7de03b70 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs @@ -169,7 +169,7 @@ private bool GenerateLiteralMembersElementInternal(MemberMapping[] mappings, boo { var xmlns = new XmlSerializerNamespaces(); p[index] = xmlns; - member.XmlnsSource = (ns, name) => xmlns.Add(ns, name); + member.XmlnsSource = xmlns.Add; } member.Source = source; @@ -198,10 +198,7 @@ private bool GenerateLiteralMembersElementInternal(MemberMapping[] mappings, boo { anyMember.Collection = new CollectionMember(); anyMember.ArraySource = anyMember.Source; - anyMember.Source = (item) => - { - anyMember.Collection.Add(item); - }; + anyMember.Source = anyMember.Collection.Add; anyAttribute = anyMember; } @@ -225,10 +222,7 @@ private bool GenerateLiteralMembersElementInternal(MemberMapping[] mappings, boo if (mapping.Attribute == null && mapping.Text == null) { anyMember.Collection = new CollectionMember(); - anyMember.ArraySource = (item) => - { - anyMember.Collection.Add(item); - }; + anyMember.ArraySource = anyMember.Collection.Add; textOrArrayMembersList.Add(anyMember); } @@ -247,10 +241,7 @@ private bool GenerateLiteralMembersElementInternal(MemberMapping[] mappings, boo && !(mapping.Elements!.Length == 1 && mapping.Elements[0].Mapping is ArrayMapping)) { anyMember.Collection = new CollectionMember(); - anyMember.ArraySource = (item) => - { - anyMember.Collection.Add(item); - }; + anyMember.ArraySource = anyMember.Collection.Add; membersList.Add(anyMember); textOrArrayMembersList.Add(anyMember); @@ -1163,10 +1154,7 @@ private static bool IsWildcard(SpecialMapping mapping) var arrayMember = new Member(memberMapping); arrayMember.Collection = new CollectionMember(); - arrayMember.ArraySource = (item) => - { - arrayMember.Collection.Add(item); - }; + arrayMember.ArraySource = arrayMember.Collection.Add; if ((readOnly && o == null) || Reader.IsEmptyElement) { @@ -1720,10 +1708,7 @@ void Wrapper(object? collection, object? collectionItems) var xmlSerializerNamespaces = new XmlSerializerNamespaces(); var setMemberValue = GetSetMemberValueDelegate(o!, member.Mapping.Name); setMemberValue(o, xmlSerializerNamespaces); - member.XmlnsSource = (ns, name) => - { - xmlSerializerNamespaces.Add(ns, name); - }; + member.XmlnsSource = xmlSerializerNamespaces.Add; } else { @@ -2126,17 +2111,11 @@ public static SetMemberValueDelegate GetSetMemberValueDelegateWithType)setMethod.CreateDelegate(typeof(Action)); diff --git a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs index d10edff2d38b1..7817703204ebe 100644 --- a/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs +++ b/src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs @@ -273,10 +273,7 @@ public static bool HasSameMetadataDefinitionAsCore(this M thisMember, MemberI MetadataLoadContext loader = defaultAssembly.Loader; Func assemblyResolver = - delegate (AssemblyName assemblyName) - { - return loader.LoadFromAssemblyName(assemblyName); - }; + loader.LoadFromAssemblyName; Func typeResolver = delegate (Assembly? assembly, string fullName, bool ignoreCase2) diff --git a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationEventsCache.cs b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationEventsCache.cs index 9e8d8d38f30b6..a11b6f6d6bfc7 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationEventsCache.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/src/System/Runtime/Serialization/SerializationEventsCache.cs @@ -99,7 +99,7 @@ internal static class SerializationEventsCache internal static SerializationEvents GetSerializationEventsForType( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type t) => - s_cache.GetOrAdd(t, type => CreateSerializationEvents(type)); + s_cache.GetOrAdd(t, CreateSerializationEvents); [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2067:UnrecognizedReflectionPattern", Justification = "The Type is annotated correctly, it just can't pass through the lambda method.")] 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 f636bcd998232..416dadb6d5e00 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 @@ -223,7 +223,7 @@ internal SignerInfoAsn Sign( SignedAttributesSet signedAttrsSet = default; signedAttrsSet.SignedAttributes = PkcsHelpers.NormalizeAttributeSet( signedAttrs.ToArray(), - normalized => hasher.AppendData(normalized)); + hasher.AppendData); // Since this contains user data in a context where BER is permitted, use BER. // There shouldn't be any observable difference here between BER and DER, though, diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsymmetricAlgorithm.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsymmetricAlgorithm.cs index 117480add15a8..7c1fb49a50274 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsymmetricAlgorithm.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/AsymmetricAlgorithm.cs @@ -117,8 +117,7 @@ public virtual byte[] ExportEncryptedPkcs8PrivateKey( return ExportArray( passwordBytes, pbeParameters, - (ReadOnlySpan span, PbeParameters parameters, Span destination, out int i) => - TryExportEncryptedPkcs8PrivateKey(span, parameters, destination, out i)); + TryExportEncryptedPkcs8PrivateKey); } public virtual byte[] ExportEncryptedPkcs8PrivateKey( @@ -128,17 +127,16 @@ public virtual byte[] ExportEncryptedPkcs8PrivateKey( return ExportArray( password, pbeParameters, - (ReadOnlySpan span, PbeParameters parameters, Span destination, out int i) => - TryExportEncryptedPkcs8PrivateKey(span, parameters, destination, out i)); + TryExportEncryptedPkcs8PrivateKey); } public virtual byte[] ExportPkcs8PrivateKey() => ExportArray( - (Span destination, out int i) => TryExportPkcs8PrivateKey(destination, out i)); + TryExportPkcs8PrivateKey); public virtual byte[] ExportSubjectPublicKeyInfo() => ExportArray( - (Span destination, out int i) => TryExportSubjectPublicKeyInfo(destination, out i)); + TryExportSubjectPublicKeyInfo); public virtual bool TryExportEncryptedPkcs8PrivateKey( ReadOnlySpan passwordBytes, diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ECDsaCertificateExtensions.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ECDsaCertificateExtensions.cs index de72605e29421..63c60b4e0a4ab 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ECDsaCertificateExtensions.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/ECDsaCertificateExtensions.cs @@ -16,7 +16,7 @@ public static class ECDsaCertificateExtensions /// public static ECDsa? GetECDsaPublicKey(this X509Certificate2 certificate) { - return certificate.GetPublicKey(cert => HasECDsaKeyUsage(cert)); + return certificate.GetPublicKey(HasECDsaKeyUsage); } /// @@ -24,7 +24,7 @@ public static class ECDsaCertificateExtensions /// public static ECDsa? GetECDsaPrivateKey(this X509Certificate2 certificate) { - return certificate.GetPrivateKey(cert => HasECDsaKeyUsage(cert)); + return certificate.GetPrivateKey(HasECDsaKeyUsage); } public static X509Certificate2 CopyWithPrivateKey(this X509Certificate2 certificate, ECDsa privateKey) diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslExportProvider.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslExportProvider.cs index e8dcae113b2fe..355dbc303865d 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslExportProvider.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslExportProvider.cs @@ -89,8 +89,8 @@ protected override byte[] ExportPkcs7() { Interop.Crypto.CheckValidOpenSslHandle(pkcs7); return Interop.Crypto.OpenSslEncode( - handle => Interop.Crypto.GetPkcs7DerSize(handle), - (handle, buf) => Interop.Crypto.EncodePkcs7(handle, buf), + Interop.Crypto.GetPkcs7DerSize, + Interop.Crypto.EncodePkcs7, pkcs7); } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs index 5ab92850cbd07..fe1fa8f95dd1e 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509CertificateReader.cs @@ -376,8 +376,8 @@ public byte[] RawData get { return Interop.Crypto.OpenSslEncode( - x => Interop.Crypto.GetX509DerSize(x), - (x, buf) => Interop.Crypto.EncodeX509(x, buf), + Interop.Crypto.GetX509DerSize, + Interop.Crypto.EncodeX509, _cert); } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs index ae0e37293191a..0b1d6dd3f7bec 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/OpenSslX509ChainProcessor.cs @@ -760,8 +760,8 @@ private Interop.Crypto.X509VerifyStatusCode CheckOcsp( using (SafeOcspRequestHandle req = Interop.Crypto.X509ChainBuildOcspRequest(_storeCtx, chainDepth)) { ArraySegment encoded = Interop.Crypto.OpenSslRentEncode( - handle => Interop.Crypto.GetOcspRequestDerSize(handle), - (handle, buf) => Interop.Crypto.EncodeOcspRequest(handle, buf), + Interop.Crypto.GetOcspRequestDerSize, + Interop.Crypto.EncodeOcspRequest, req); ArraySegment urlEncoded = UrlBase64Encoding.RentEncode(encoded); @@ -1303,7 +1303,7 @@ private static string GetErrorString(Interop.Crypto.X509VerifyStatusCode code) { return s_errorStrings.GetOrAdd( code.Code, - c => Interop.Crypto.GetX509VerifyCertErrorString(c)); + Interop.Crypto.GetX509VerifyCertErrorString); } private sealed class WorkingChain : IDisposable diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs index 9546c53bdacc6..4cfddb443df03 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs @@ -701,7 +701,7 @@ public bool Verify() /// public ECDiffieHellman? GetECDiffieHellmanPublicKey() { - return this.GetPublicKey(cert => HasECDiffieHellmanKeyUsage(cert)); + return this.GetPublicKey(HasECDiffieHellmanKeyUsage); } /// @@ -716,7 +716,7 @@ public bool Verify() /// public ECDiffieHellman? GetECDiffieHellmanPrivateKey() { - return this.GetPrivateKey(cert => HasECDiffieHellmanKeyUsage(cert)); + return this.GetPrivateKey(HasECDiffieHellmanKeyUsage); } /// diff --git a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs index 908ff31ec9db0..2a03f55f31706 100644 --- a/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs +++ b/src/libraries/System.ServiceModel.Syndication/src/System/ServiceModel/Syndication/AtomPub10CategoriesDocumentFormatter.cs @@ -159,8 +159,8 @@ private void ReadDocument(XmlReader reader) { SyndicationFeedFormatter.MoveToStartElement(reader); SetDocument(AtomPub10ServiceDocumentFormatter.ReadCategories(reader, null, - () => CreateInlineCategoriesDocument(), - () => CreateReferencedCategoriesDocument(), + CreateInlineCategoriesDocument, + CreateReferencedCategoriesDocument, Version, _maxExtensionSize)); } diff --git a/src/libraries/System.Speech/src/Internal/SapiInterop/SapiRecoContext.cs b/src/libraries/System.Speech/src/Internal/SapiInterop/SapiRecoContext.cs index 19c895c9d3bcd..c28b308aca981 100644 --- a/src/libraries/System.Speech/src/Internal/SapiInterop/SapiRecoContext.cs +++ b/src/libraries/System.Speech/src/Internal/SapiInterop/SapiRecoContext.cs @@ -74,7 +74,7 @@ internal EventNotify CreateEventNotify(AsyncSerializedWorker asyncWorker, bool s internal void DisposeEventNotify(EventNotify eventNotify) { - _proxy.Invoke2(delegate { eventNotify.Dispose(); }); + _proxy.Invoke2(eventNotify.Dispose); } internal void SetGrammarOptions(SPGRAMMAROPTIONS options) diff --git a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs index 86c38c3c45165..ce9ed21677861 100644 --- a/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs +++ b/src/libraries/System.Text.Json/gen/JsonSourceGenerator.Parser.cs @@ -552,7 +552,7 @@ private static bool TryGetClassDeclarationList(INamedTypeSymbol typeSymbol, [Not return typeGenerationSpec; } - internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is ClassDeclarationSyntax { AttributeLists: { Count: > 0 }, BaseList: { Types : {Count : > 0 } } }; + internal static bool IsSyntaxTargetForGeneration(SyntaxNode node) => node is ClassDeclarationSyntax { AttributeLists.Count: > 0, BaseList.Types.Count: > 0 }; internal static ClassDeclarationSyntax? GetSemanticTargetForGeneration(GeneratorSyntaxContext context, CancellationToken cancellationToken) { diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs index 8104729e1f148..d1d5ecbe0b36f 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs @@ -1365,7 +1365,7 @@ void EmitSwitchedBranches() { int numChars = RegexCharClass.GetSetChars(childStart.Str!, setChars); Debug.Assert(numChars != 0); - writer.WriteLine($"case {string.Join(" or ", setChars.Slice(0, numChars).ToArray().Select(c => Literal(c)))}:"); + writer.WriteLine($"case {string.Join(" or ", setChars.Slice(0, numChars).ToArray().Select(Literal))}:"); } else { diff --git a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs index 0829ccf42ff17..9fa9110e23afe 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Parser.cs @@ -23,7 +23,7 @@ public partial class RegexGenerator private static bool IsSyntaxTargetForGeneration(SyntaxNode node, CancellationToken cancellationToken) => // We don't have a semantic model here, so the best we can do is say whether there are any attributes. - node is MethodDeclarationSyntax { AttributeLists: { Count: > 0 } }; + node is MethodDeclarationSyntax { AttributeLists.Count: > 0 }; private static bool IsSemanticTargetForGeneration(SemanticModel semanticModel, MethodDeclarationSyntax methodDeclarationSyntax, CancellationToken cancellationToken) { diff --git a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs index 3cb92a392b178..56ee24cf48668 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/src/Blocks/BatchBlock.cs @@ -68,7 +68,7 @@ public BatchBlock(int batchSize, GroupingDataflowBlockOptions dataflowBlockOptio onItemsRemoved, itemCountingFunc); // Initialize target - _target = new BatchBlockTargetCore(this, batchSize, batch => _source.AddMessage(batch), dataflowBlockOptions); + _target = new BatchBlockTargetCore(this, batchSize, _source.AddMessage, dataflowBlockOptions); // When the target is done, let the source know it won't be getting any more data _target.Completion.ContinueWith(delegate { _source.Complete(); }, diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs index ba51ce0741def..df36076f46bac 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Metadata/MetadataUpdater.cs @@ -51,7 +51,7 @@ public static void ApplyUpdate(Assembly assembly, ReadOnlySpan metadataDel public static bool IsSupported { get; } = ApplyUpdateEnabled(justComponentCheck: 0) != 0; - private static Lazy s_ApplyUpdateCapabilities = new Lazy(() => InitializeApplyUpdateCapabilities()); + private static readonly Lazy s_ApplyUpdateCapabilities = new Lazy(InitializeApplyUpdateCapabilities); private static string InitializeApplyUpdateCapabilities() { diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 2baa2f2e02873..c480fd76f1a55 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -128,7 +128,7 @@ public bool TryResolve(DebugStore store) if (request == null || store == null) return false; - return store.AllSources().FirstOrDefault(source => TryResolve(source)) != null; + return store.AllSources().FirstOrDefault(TryResolve) != null; } public bool CompareRequest(JObject req) diff --git a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs index 6d639794d3289..12b4dafe6b467 100644 --- a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs +++ b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs @@ -522,7 +522,7 @@ all assigned to that one partition. ParallelLoopResult result = Parallel.ForEach( Partitioner.Create(argsList, EnumerablePartitionerOptions.NoBuffering), new ParallelOptions { MaxDegreeOfParallelism = allowedParallelism }, - (args, state) => PrecompileLibraryParallel(args, state)); + PrecompileLibraryParallel); if (result.IsCompleted) {