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 bbdccc6cd2eed4..64669dd5458f78 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 @@ -21,7 +21,7 @@ public static partial class Marshal /// /// IUnknown is {00000000-0000-0000-C000-000000000046} /// - internal static Guid IID_IUnknown = new Guid(0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46); + internal static readonly Guid IID_IUnknown = new Guid(0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46); #endif //FEATURE_COMINTEROP internal static int SizeOfHelper(RuntimeType t, [MarshalAs(UnmanagedType.Bool)] bool throwIfNotMarshalable) @@ -929,7 +929,7 @@ public static object BindToMoniker(string monikerName) ThrowExceptionForHR(MkParseDisplayName(bindctx, monikerName, out _, out IntPtr pmoniker)); try { - ThrowExceptionForHR(BindMoniker(pmoniker, 0, ref IID_IUnknown, out IntPtr ptr)); + ThrowExceptionForHR(BindMoniker(pmoniker, 0, in IID_IUnknown, out IntPtr ptr)); try { return GetObjectForIUnknown(ptr); @@ -956,7 +956,7 @@ public static object BindToMoniker(string monikerName) private static partial int MkParseDisplayName(IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IntPtr ppmk); [LibraryImport(Interop.Libraries.Ole32)] - private static partial int BindMoniker(IntPtr pmk, uint grfOpt, ref Guid iidResult, out IntPtr ppvResult); + private static partial int BindMoniker(IntPtr pmk, uint grfOpt, in Guid iidResult, out IntPtr ppvResult); [SupportedOSPlatform("windows")] public static void ChangeWrapperHandleStrength(object otp, bool fIsWeak) diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs index 7ce239610a7ab6..b2140c6b00cb69 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/ExceptionHandling.cs @@ -405,7 +405,7 @@ public static void FailedAllocation(MethodTable* pEEType, bool fIsOverflow) } #if !INPLACE_RUNTIME - private static OutOfMemoryException s_theOOMException = new OutOfMemoryException(); + private static readonly OutOfMemoryException s_theOOMException = new OutOfMemoryException(); // MRT exports GetRuntimeException for the few cases where we have a helper that throws an exception // and may be called by either MRT or other classlibs and that helper needs to throw an exception. diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs index 0161e8c47c1508..6c371a83d687f3 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/TypeCast.cs @@ -35,7 +35,7 @@ internal static class TypeCast private const int MaximumCacheSize = 4096; // 4096 * sizeof(CastCacheEntry) is 98304 bytes on 64bit. We will rarely need this much though. #endif // DEBUG - private static CastCache s_castCache = new CastCache(InitialCacheSize, MaximumCacheSize); + private static readonly CastCache s_castCache = new CastCache(InitialCacheSize, MaximumCacheSize); [Flags] internal enum AssignmentVariation diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs index e5bfe42e497694..6b246e4ee4567e 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/InteropHelpers.cs @@ -695,7 +695,7 @@ public override int GetHashCode() internal sealed class CustomMarshallerTable : ConcurrentUnifier { - internal static CustomMarshallerTable s_customMarshallersTable = new CustomMarshallerTable(); + internal static readonly CustomMarshallerTable s_customMarshallersTable = new CustomMarshallerTable(); protected override unsafe object Factory(CustomMarshallerKey key) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs index 90b0f242a4188b..41aa17cdcbfdae 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/RuntimeMethodHandleInfo.cs @@ -12,8 +12,8 @@ namespace Internal.Runtime.CompilerServices { public class MethodNameAndSignature { - public string Name { get; private set; } - public RuntimeSignature Signature { get; private set; } + public string Name { get; } + public RuntimeSignature Signature { get; } public MethodNameAndSignature(string name, RuntimeSignature signature) { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs index 9589edaab42b3d..7db1728b3128e1 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Type.NativeAot.cs @@ -31,7 +31,7 @@ internal static unsafe RuntimeType GetTypeFromMethodTable(MethodTable* pMT) private static class AllocationLockHolder { - public static Lock AllocationLock = new Lock(useTrivialWaits: true); + public static readonly Lock AllocationLock = new Lock(useTrivialWaits: true); } [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs index df5715e2d119d6..6bff16c340a92d 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Execution/src/Internal/Reflection/Execution/MethodInvokers/MethodInvokerWithMethodInvokeInfo.cs @@ -62,6 +62,6 @@ internal static MethodBaseInvoker CreateMethodInvoker(RuntimeTypeHandle declarin return new InstanceMethodInvoker(methodInvokeInfo, declaringTypeHandle); } - internal MethodInvokeInfo MethodInvokeInfo { get; private set; } + internal MethodInvokeInfo MethodInvokeInfo { get; } } } diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs index 52593e30bb48dd..e4897f9854e33a 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/LockFreeObjectInterner.cs @@ -8,7 +8,7 @@ namespace Internal.TypeSystem { public class LockFreeObjectInterner : LockFreeReaderHashtableOfPointers { - private static LockFreeObjectInterner s_interner = new LockFreeObjectInterner(); + private static readonly LockFreeObjectInterner s_interner = new LockFreeObjectInterner(); public static GCHandle GetInternedObjectHandle(object obj) { return s_interner.GetOrCreateValue(obj); diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ModuleList.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ModuleList.cs index 3aff8131b762aa..c484eb6e5afded 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ModuleList.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/ModuleList.cs @@ -20,7 +20,7 @@ public unsafe class ModuleInfo /// /// Module handle is the TypeManager associated with this module. /// - public TypeManagerHandle Handle { get; private set; } + public TypeManagerHandle Handle { get; } /// /// Initialize module info and construct per-module metadata reader. @@ -49,7 +49,7 @@ internal NativeFormatModuleInfo(TypeManagerHandle moduleHandle, IntPtr pBlob, in /// /// Module metadata reader for NativeFormat metadata /// - public MetadataReader MetadataReader { get; private set; } + public MetadataReader MetadataReader { get; } internal unsafe bool TryFindBlob(ReflectionMapBlob blobId, out byte* pBlob, out uint cbBlob) { diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeSystemContextFactory.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeSystemContextFactory.cs index 410296beaf0b90..06db5253c590c2 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeSystemContextFactory.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeSystemContextFactory.cs @@ -18,7 +18,7 @@ public static class TypeSystemContextFactory // This allows us to avoid recreating the type resolution context again and again, but still allows it to go away once the types are no longer being built private static GCHandle s_cachedContext = GCHandle.Alloc(null, GCHandleType.Weak); - private static Lock s_lock = new Lock(useTrivialWaits: true); + private static readonly Lock s_lock = new Lock(useTrivialWaits: true); public static TypeSystemContext Create() { diff --git a/src/coreclr/tools/Common/Pgo/PgoFormat.cs b/src/coreclr/tools/Common/Pgo/PgoFormat.cs index b623835845838f..b0222f8a0c8f9a 100644 --- a/src/coreclr/tools/Common/Pgo/PgoFormat.cs +++ b/src/coreclr/tools/Common/Pgo/PgoFormat.cs @@ -516,7 +516,7 @@ public static void EncodePgoData(IEnumerable sche private sealed class PgoSchemaMergeComparer : IComparer, IEqualityComparer { - public static PgoSchemaMergeComparer Singleton = new PgoSchemaMergeComparer(); + public static readonly PgoSchemaMergeComparer Singleton = new PgoSchemaMergeComparer(); public int Compare(PgoSchemaElem x, PgoSchemaElem y) { diff --git a/src/coreclr/tools/Common/TypeSystem/Common/BaseTypeRuntimeInterfacesAlgorithm.cs b/src/coreclr/tools/Common/TypeSystem/Common/BaseTypeRuntimeInterfacesAlgorithm.cs index 0835048af5f962..deebe50f195ceb 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/BaseTypeRuntimeInterfacesAlgorithm.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/BaseTypeRuntimeInterfacesAlgorithm.cs @@ -9,7 +9,7 @@ namespace Internal.TypeSystem /// public sealed class BaseTypeRuntimeInterfacesAlgorithm : RuntimeInterfacesAlgorithm { - private static RuntimeInterfacesAlgorithm _singleton = new BaseTypeRuntimeInterfacesAlgorithm(); + private static readonly RuntimeInterfacesAlgorithm _singleton = new BaseTypeRuntimeInterfacesAlgorithm(); private BaseTypeRuntimeInterfacesAlgorithm() { } diff --git a/src/coreclr/tools/Common/TypeSystem/MetadataEmitter/TypeSystemMetadataEmitter.cs b/src/coreclr/tools/Common/TypeSystem/MetadataEmitter/TypeSystemMetadataEmitter.cs index 62b86c968c6070..395c1045e2fef4 100644 --- a/src/coreclr/tools/Common/TypeSystem/MetadataEmitter/TypeSystemMetadataEmitter.cs +++ b/src/coreclr/tools/Common/TypeSystem/MetadataEmitter/TypeSystemMetadataEmitter.cs @@ -489,7 +489,7 @@ private sealed class EmbeddedSignatureDataEmitter private Stack _indexStack = new Stack(); private TypeSystemMetadataEmitter _metadataEmitter; - public static EmbeddedSignatureDataEmitter EmptySingleton = new EmbeddedSignatureDataEmitter(null, null); + public static readonly EmbeddedSignatureDataEmitter EmptySingleton = new EmbeddedSignatureDataEmitter(null, null); public EmbeddedSignatureDataEmitter(EmbeddedSignatureData[] embeddedData, TypeSystemMetadataEmitter metadataEmitter) { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeFieldHandleNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeFieldHandleNode.cs index 644bc136b590cb..6e7631cc1117ec 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeFieldHandleNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeFieldHandleNode.cs @@ -38,7 +38,7 @@ protected override ObjectNodeSection GetDehydratedSection(NodeFactory factory) return ObjectNodeSection.DataSection; } - private static Utf8String s_NativeLayoutSignaturePrefix = new Utf8String("__RFHSignature_"); + private static readonly Utf8String s_NativeLayoutSignaturePrefix = new Utf8String("__RFHSignature_"); protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFactory factory) { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeMethodHandleNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeMethodHandleNode.cs index eab08b1bcafd2c..c1015fc803d42a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeMethodHandleNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeMethodHandleNode.cs @@ -66,7 +66,7 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact return dependencies; } - private static Utf8String s_NativeLayoutSignaturePrefix = new Utf8String("__RMHSignature_"); + private static readonly Utf8String s_NativeLayoutSignaturePrefix = new Utf8String("__RMHSignature_"); protected override ObjectData GetDehydratableData(NodeFactory factory, bool relocsOnly = false) { diff --git a/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/NoLogStrategy.cs b/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/NoLogStrategy.cs index 55cf4174fd129d..fefb9dbad8916b 100644 --- a/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/NoLogStrategy.cs +++ b/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/NoLogStrategy.cs @@ -11,7 +11,7 @@ namespace ILCompiler.DependencyAnalysisFramework /// public struct NoLogStrategy : IDependencyAnalysisMarkStrategy { - private static object s_singleton = new object(); + private static readonly object s_singleton = new object(); bool IDependencyAnalysisMarkStrategy.MarkNode( DependencyNodeCore node, diff --git a/src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs b/src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs index 011087bba391a7..d87b5c14c33f07 100644 --- a/src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs +++ b/src/libraries/Common/src/Interop/Windows/HttpApi/Interop.HttpApi.cs @@ -16,8 +16,8 @@ internal static partial class HttpApi { internal static readonly HTTPAPI_VERSION s_version = new HTTPAPI_VERSION() { HttpApiMajorVersion = 2, HttpApiMinorVersion = 0 }; internal static readonly bool s_supported = InitHttpApi(s_version); - internal static IPEndPoint s_any = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort); - internal static IPEndPoint s_ipv6Any = new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MinPort); + internal static readonly IPEndPoint s_any = new IPEndPoint(IPAddress.Any, IPEndPoint.MinPort); + internal static readonly IPEndPoint s_ipv6Any = new IPEndPoint(IPAddress.IPv6Any, IPEndPoint.MinPort); internal const int IPv4AddressSize = 16; internal const int IPv6AddressSize = 28; diff --git a/src/libraries/Common/src/System/Security/Cryptography/Oids.Shared.cs b/src/libraries/Common/src/System/Security/Cryptography/Oids.Shared.cs index 59ad3a9e71c307..69f5b96dee02db 100644 --- a/src/libraries/Common/src/System/Security/Cryptography/Oids.Shared.cs +++ b/src/libraries/Common/src/System/Security/Cryptography/Oids.Shared.cs @@ -72,10 +72,10 @@ internal static partial class Oids internal static Oid CommonNameOid => s_commonNameOid ??= InitializeOid(CommonName); internal static Oid CountryOrRegionNameOid => s_countryOrRegionOid ??= InitializeOid(CountryOrRegionName); internal static Oid LocalityNameOid => s_localityNameOid ??= InitializeOid(LocalityName); - internal static Oid StateOrProvinceNameOid = s_stateOrProvinceNameOid ??= InitializeOid(StateOrProvinceName); - internal static Oid OrganizationOid = s_organizationOid ??= InitializeOid(Organization); - internal static Oid OrganizationalUnitOid = s_organizationalUnitOid ??= InitializeOid(OrganizationalUnit); - internal static Oid EmailAddressOid = s_emailAddressOid ??= InitializeOid(EmailAddress); + internal static Oid StateOrProvinceNameOid => s_stateOrProvinceNameOid ??= InitializeOid(StateOrProvinceName); + internal static Oid OrganizationOid => s_organizationOid ??= InitializeOid(Organization); + internal static Oid OrganizationalUnitOid => s_organizationalUnitOid ??= InitializeOid(OrganizationalUnit); + internal static Oid EmailAddressOid => s_emailAddressOid ??= InitializeOid(EmailAddress); private static Oid InitializeOid(string oidValue) { diff --git a/src/libraries/Microsoft.Bcl.Numerics/src/System/MathF.cs b/src/libraries/Microsoft.Bcl.Numerics/src/System/MathF.cs index 128a3174ad0c4e..505bc6668897da 100644 --- a/src/libraries/Microsoft.Bcl.Numerics/src/System/MathF.cs +++ b/src/libraries/Microsoft.Bcl.Numerics/src/System/MathF.cs @@ -38,7 +38,7 @@ public static class MathF /// public const float E = 2.71828183f; - private static float NegativeZero = Int32BitsToSingle(unchecked((int)0x80000000)); + private static readonly float NegativeZero = Int32BitsToSingle(unchecked((int)0x80000000)); private static unsafe float Int32BitsToSingle(int value) { diff --git a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs index e938472f476cf7..8877a3086b2393 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/CommandLineConfigurationProvider.cs @@ -33,7 +33,7 @@ public CommandLineConfigurationProvider(IEnumerable args, IDictionary /// The command line arguments. /// - protected IEnumerable Args { get; private set; } + protected IEnumerable Args { get; } /// /// Loads the configuration data from the command line args. diff --git a/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs b/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs index 5702d1795f9215..37520c3d1127bc 100644 --- a/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs +++ b/src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs @@ -9,7 +9,7 @@ namespace Microsoft.Extensions.DependencyInjection { internal sealed class CallSiteJsonFormatter : CallSiteVisitor { - internal static CallSiteJsonFormatter Instance = new CallSiteJsonFormatter(); + internal static readonly CallSiteJsonFormatter Instance = new CallSiteJsonFormatter(); private CallSiteJsonFormatter() { diff --git a/src/libraries/Microsoft.Extensions.DependencyModel/src/EnvironmentWrapper.cs b/src/libraries/Microsoft.Extensions.DependencyModel/src/EnvironmentWrapper.cs index d61aed3e622ead..01510386027730 100644 --- a/src/libraries/Microsoft.Extensions.DependencyModel/src/EnvironmentWrapper.cs +++ b/src/libraries/Microsoft.Extensions.DependencyModel/src/EnvironmentWrapper.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.DependencyModel { internal sealed class EnvironmentWrapper : IEnvironment { - public static IEnvironment Default = new EnvironmentWrapper(); + public static readonly IEnvironment Default = new EnvironmentWrapper(); public string? GetEnvironmentVariable(string name) => Environment.GetEnvironmentVariable(name); diff --git a/src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs b/src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs index 54453271946e8b..c6e78a4d67d837 100644 --- a/src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs +++ b/src/libraries/Microsoft.Extensions.Http/src/ActiveHandlerTrackingEntry.cs @@ -33,7 +33,7 @@ public ActiveHandlerTrackingEntry( _lock = new object(); } - public LifetimeTrackingHttpMessageHandler Handler { get; private set; } + public LifetimeTrackingHttpMessageHandler Handler { get; } public TimeSpan Lifetime { get; } diff --git a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs index fb92b7bbd1e219..69707c14c3f2d4 100644 --- a/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs +++ b/src/libraries/Microsoft.Extensions.Logging.Abstractions/src/LogValuesFormatter.cs @@ -82,7 +82,7 @@ public LogValuesFormatter(string format) #endif } - public string OriginalFormat { get; private set; } + public string OriginalFormat { get; } public List ValueNames => _valueNames; private static int FindBraceIndex(string format, char brace, int startIndex, int endIndex) diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs index dc3c47eae3b8e8..2165c3344f5eee 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/CDSCollectionETWBCLProvider.cs @@ -28,7 +28,7 @@ internal sealed class CDSCollectionETWBCLProvider : EventSource /// Defines the singleton instance for the collection ETW provider. /// The collection provider GUID is {35167F8E-49B2-4b96-AB86-435B59336B5E}. /// - public static CDSCollectionETWBCLProvider Log = new CDSCollectionETWBCLProvider(); + public static readonly CDSCollectionETWBCLProvider Log = new CDSCollectionETWBCLProvider(); /// Prevent external instantiation. All logging should go through the Log instance. private CDSCollectionETWBCLProvider() { } diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/OrderablePartitioner.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/OrderablePartitioner.cs index 964cf4a9f37467..675d54776ac103 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/OrderablePartitioner.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/OrderablePartitioner.cs @@ -131,7 +131,7 @@ public virtual IEnumerable> GetOrderableDynamicParti /// /// Gets whether elements in each partition are yielded in the order of increasing keys. /// - public bool KeysOrderedInEachPartition { get; private set; } + public bool KeysOrderedInEachPartition { get; } /// /// Gets whether elements in an earlier partition always come before elements in a later partition. @@ -141,7 +141,7 @@ public virtual IEnumerable> GetOrderableDynamicParti /// smaller order key than any element in partition 1, each element in partition 1 has a smaller /// order key than any element in partition 2, and so on. /// - public bool KeysOrderedAcrossPartitions { get; private set; } + public bool KeysOrderedAcrossPartitions { get; } /// /// Gets whether order keys are normalized. @@ -151,7 +151,7 @@ public virtual IEnumerable> GetOrderableDynamicParti /// [0 .. numberOfElements-1]. If the property returns false, order keys must still be distinct, but /// only their relative order is considered, not their absolute values. /// - public bool KeysNormalized { get; private set; } + public bool KeysNormalized { get; } /// /// Partitions the underlying collection into the given number of ordered partitions. diff --git a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs index a3a52c86d1dbda..9c9fcc88424f83 100644 --- a/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs +++ b/src/libraries/System.Collections.Concurrent/src/System/Collections/Concurrent/PartitionerStatic.cs @@ -308,7 +308,7 @@ private abstract class DynamicPartitionEnumerator_Abstract(); + protected static readonly int s_defaultMaxChunkSize = GetDefaultChunkSize(); //deferred allocating in MoveNext() with initial value 0, to avoid false sharing //we also use the fact that: (_currentChunkSize==null) means MoveNext is never called on this enumerator diff --git a/src/libraries/System.ComponentModel.Composition.Registration/src/System/ComponentModel/Composition/Registration/PartBuilder.cs b/src/libraries/System.ComponentModel.Composition.Registration/src/System/ComponentModel/Composition/Registration/PartBuilder.cs index 2ad43f582629d5..e0f9cb29774dd5 100644 --- a/src/libraries/System.ComponentModel.Composition.Registration/src/System/ComponentModel/Composition/Registration/PartBuilder.cs +++ b/src/libraries/System.ComponentModel.Composition.Registration/src/System/ComponentModel/Composition/Registration/PartBuilder.cs @@ -29,7 +29,7 @@ public class PartBuilder private readonly List, Action, Type>> _propertyImports; private readonly List, Action>> _interfaceExports; - internal Predicate SelectType { get; private set; } + internal Predicate SelectType { get; } internal PartBuilder(Predicate selectType) { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ExportAttribute.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ExportAttribute.cs index 9e9fc64243622d..bdfdd0b3b6d974 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ExportAttribute.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ExportAttribute.cs @@ -126,7 +126,7 @@ public ExportAttribute(string? contractName, Type? contractType) /// A containing the contract name to export the type or member /// marked with this attribute, under. The default value is an empty string (""). /// - public string? ContractName { get; private set; } + public string? ContractName { get; } /// /// Get the contract type that is exported by the member that this attribute is attached to. @@ -136,6 +136,6 @@ public ExportAttribute(string? contractName, Type? contractType) /// which means that the type will be obtained by looking at the type on /// the member that this export is attached to. /// - public Type? ContractType { get; private set; } + public Type? ContractType { get; } } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs index 879e5a1dd289cf..8b465a5e0f0f35 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/CatalogExportProvider.cs @@ -1025,7 +1025,7 @@ public CatalogPart(ComposablePart part) { Part = part; } - public ComposablePart Part { get; private set; } + public ComposablePart Part { get; } public bool ImportsSatisfied { diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartCatalogChangeEventArgs.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartCatalogChangeEventArgs.cs index b1b948fcdd3104..660db0d7416988 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartCatalogChangeEventArgs.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ComposablePartCatalogChangeEventArgs.cs @@ -95,6 +95,6 @@ public IEnumerable RemovedDefinitions /// When the value is non-null it should be used to record temporary changed state /// and actions that will be executed when the atomicComposition is completeed. /// - public AtomicComposition? AtomicComposition { get; private set; } + public AtomicComposition? AtomicComposition { get; } } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportsChangeEventArgs.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportsChangeEventArgs.cs index 0e0cbedfd01de4..3fed9029fdd070 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportsChangeEventArgs.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/Hosting/ExportsChangeEventArgs.cs @@ -113,6 +113,6 @@ public IEnumerable RemovedExports /// When the value is non-null it should be used to record temporary changed state /// and actions that will be executed when the atomicComposition is completeed. /// - public AtomicComposition? AtomicComposition { get; private set; } + public AtomicComposition? AtomicComposition { get; } } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportAttribute.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportAttribute.cs index 6357021ed54d23..c9e3e11e071f5e 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportAttribute.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportAttribute.cs @@ -99,7 +99,7 @@ public ImportAttribute(string? contractName, Type? contractType) /// A containing the contract name of the export to import. The /// default value is an empty string (""). /// - public string? ContractName { get; private set; } + public string? ContractName { get; } /// /// Get the contract type of the export to import. @@ -110,7 +110,7 @@ public ImportAttribute(string? contractName, Type? contractType) /// the member that this import is attached to. If the type is then the /// importer is delaring they can accept any exported type. /// - public Type? ContractType { get; private set; } + public Type? ContractType { get; } /// /// Gets or sets a value indicating whether the property, field or parameter will be set diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportManyAttribute.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportManyAttribute.cs index 918cb09cedb51e..687c794c7d1fe6 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportManyAttribute.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/ImportManyAttribute.cs @@ -99,7 +99,7 @@ public ImportManyAttribute(string? contractName, Type? contractType) /// A containing the contract name of the exports to import. The /// default value is an empty string (""). /// - public string? ContractName { get; private set; } + public string? ContractName { get; } /// /// Get the contract type of the export to import. @@ -110,7 +110,7 @@ public ImportManyAttribute(string? contractName, Type? contractType) /// the member that this import is attached to. If the type is then the /// importer is delaring they can accept any exported type. /// - public Type? ContractType { get; private set; } + public Type? ContractType { get; } /// /// Gets or sets a value indicating whether the property or field will be recomposed diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataViewImplementationAttribute.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataViewImplementationAttribute.cs index 7f70310ff98034..557ab0a65c6628 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataViewImplementationAttribute.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/MetadataViewImplementationAttribute.cs @@ -36,6 +36,6 @@ public MetadataViewImplementationAttribute(Type? implementationType) /// which means that the type will be obtained by looking at the type on /// the member that this export is attached to. /// - public Type? ImplementationType { get; private set; } + public Type? ImplementationType { get; } } } diff --git a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/PartCreationPolicyAttribute.cs b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/PartCreationPolicyAttribute.cs index a1b151c4835874..fa06489b1b604a 100644 --- a/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/PartCreationPolicyAttribute.cs +++ b/src/libraries/System.ComponentModel.Composition/src/System/ComponentModel/Composition/PartCreationPolicyAttribute.cs @@ -9,8 +9,8 @@ namespace System.ComponentModel.Composition [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public sealed class PartCreationPolicyAttribute : Attribute { - internal static PartCreationPolicyAttribute Default = new PartCreationPolicyAttribute(CreationPolicy.Any); - internal static PartCreationPolicyAttribute Shared = new PartCreationPolicyAttribute(CreationPolicy.Shared); + internal static readonly PartCreationPolicyAttribute Default = new PartCreationPolicyAttribute(CreationPolicy.Any); + internal static readonly PartCreationPolicyAttribute Shared = new PartCreationPolicyAttribute(CreationPolicy.Shared); /// /// Initializes a new instance of the class. @@ -28,6 +28,6 @@ public PartCreationPolicyAttribute(CreationPolicy creationPolicy) /// attributed part. The default is /// . /// - public CreationPolicy CreationPolicy { get; private set; } + public CreationPolicy CreationPolicy { get; } } } diff --git a/src/libraries/System.Composition.Convention/src/System/Composition/Convention/PartConventionBuilder.cs b/src/libraries/System.Composition.Convention/src/System/Composition/Convention/PartConventionBuilder.cs index fa7b93bc989baf..76b0efd4898ecd 100644 --- a/src/libraries/System.Composition.Convention/src/System/Composition/Convention/PartConventionBuilder.cs +++ b/src/libraries/System.Composition.Convention/src/System/Composition/Convention/PartConventionBuilder.cs @@ -35,7 +35,7 @@ public class PartConventionBuilder private readonly List, Action>> _interfaceExports; private readonly List> _methodImportsSatisfiedNotifications; - internal Predicate SelectType { get; private set; } + internal Predicate SelectType { get; } internal PartConventionBuilder(Predicate selectType) { diff --git a/src/libraries/System.Data.Common/src/System/Data/DataView.cs b/src/libraries/System.Data.Common/src/System/Data/DataView.cs index 8babfcf6c4984e..90228062426260 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataView.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataView.cs @@ -53,7 +53,7 @@ public class DataView : MarshalByValueComponent, IBindingListView, System.Compon private ListChangedEventArgs? _addNewMoved; private System.ComponentModel.ListChangedEventHandler? _onListChanged; - internal static ListChangedEventArgs s_resetEventArgs = new ListChangedEventArgs(ListChangedType.Reset, -1); + internal static readonly ListChangedEventArgs s_resetEventArgs = new ListChangedEventArgs(ListChangedType.Reset, -1); private DataTable? _delayedTable; private string? _delayedRowFilter; diff --git a/src/libraries/System.Data.Common/src/System/Data/Filter/Operators.cs b/src/libraries/System.Data.Common/src/System/Data/Filter/Operators.cs index bf84ba65ec3e06..ca33c626fa7844 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Filter/Operators.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Filter/Operators.cs @@ -37,9 +37,9 @@ internal static class Operators internal const int Minus = 16; // - internal const int Multiply = 17; // * internal const int Divide = 18; // / - //internal final static int IntegerDiv = 19; // \ + //internal const int IntegerDiv = 19; // \ internal const int Modulo = 20; // % - //internal final static int Exponent = 21; // ** + //internal const int Exponent = 21; // ** /* End of arithmetic operators */ /* Beginning of bitwise operators */ diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbConnectionPool.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbConnectionPool.cs index bceb5f5c4a6329..33d522bbe12868 100644 --- a/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbConnectionPool.cs +++ b/src/libraries/System.Data.Odbc/src/Common/System/Data/ProviderBase/DbConnectionPool.cs @@ -28,9 +28,9 @@ public PendingGetConnection(long dueTime, DbConnection owner, TaskCompletionSour Owner = owner; Completion = completion; } - public long DueTime { get; private set; } - public DbConnection Owner { get; private set; } - public TaskCompletionSource Completion { get; private set; } + public long DueTime { get; } + public DbConnection Owner { get; } + public TaskCompletionSource Completion { get; } } diff --git a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs index 5e0c0371793135..81ed633271852d 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbCommand.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbCommand.cs @@ -857,7 +857,7 @@ private int ExecuteCommandTextForMultpleResults(tagDBPARAMS dbParams, out object { Debug.Assert(0 == (CommandBehavior.SingleRow & this.commandBehavior), "SingleRow implies SingleResult"); OleDbHResult hr; - hr = _icommandText!.Execute(IntPtr.Zero, ref ODB.IID_IMultipleResults, dbParams, out _recordsAffected, out executeResult); + hr = _icommandText!.Execute(IntPtr.Zero, in ODB.IID_IMultipleResults, dbParams, out _recordsAffected, out executeResult); if (OleDbHResult.E_NOINTERFACE != hr) { @@ -875,11 +875,11 @@ private int ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, out object e // (Microsoft.Jet.OLEDB.4.0 returns 0 for recordsAffected instead of -1) if (_executeQuery) { - hr = _icommandText!.Execute(IntPtr.Zero, ref ODB.IID_IRowset, dbParams, out _recordsAffected, out executeResult); + hr = _icommandText!.Execute(IntPtr.Zero, in ODB.IID_IRowset, dbParams, out _recordsAffected, out executeResult); } else { - hr = _icommandText!.Execute(IntPtr.Zero, ref ODB.IID_NULL, dbParams, out _recordsAffected, out executeResult); + hr = _icommandText!.Execute(IntPtr.Zero, in ODB.IID_NULL, dbParams, out _recordsAffected, out executeResult); } ExecuteCommandTextErrorHandling(hr); return ODB.ExecutedIRowset; @@ -892,7 +892,7 @@ private int ExecuteCommandTextForSingleRow(tagDBPARAMS dbParams, out object exec if (_connection!.SupportIRow(this)) { OleDbHResult hr; - hr = _icommandText!.Execute(IntPtr.Zero, ref ODB.IID_IRow, dbParams, out _recordsAffected, out executeResult); + hr = _icommandText!.Execute(IntPtr.Zero, in ODB.IID_IRow, dbParams, out _recordsAffected, out executeResult); if (OleDbHResult.DB_E_NOTFOUND == hr) { @@ -993,7 +993,7 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu try { propSet.DangerousAddRef(ref mustRelease); - hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, ref ODB.IID_IRowset, propSet.PropertySetCount, propSet.DangerousGetHandle(), out executeResult); + hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, in ODB.IID_IRowset, propSet.PropertySetCount, propSet.DangerousGetHandle(), out executeResult); } finally { @@ -1005,12 +1005,12 @@ private int ExecuteTableDirect(CommandBehavior behavior, out object? executeResu if (OleDbHResult.DB_E_ERRORSOCCURRED == hr) { - hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); + hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, in ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); } } else { - hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, ref ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); + hr = iopenRowset.Value.OpenRowset(IntPtr.Zero, tableID, IntPtr.Zero, in ODB.IID_IRowset, 0, IntPtr.Zero, out executeResult); } } } @@ -1163,7 +1163,7 @@ private bool InitializeCommand(CommandBehavior behavior) string commandText = ExpandCommandText(); - hr = _icommandText!.SetCommandText(ref ODB.DBGUID_DEFAULT, commandText); + hr = _icommandText!.SetCommandText(in ODB.DBGUID_DEFAULT, commandText); if (hr < 0) { diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs index 01745446f6b11c..e5635abaf90af6 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionInternal.cs @@ -624,7 +624,7 @@ internal DataTable BuildSchemaGuids() UnsafeNativeMethods.IRowset? rowset = null; OleDbHResult hr; - hr = dbSchemaRowset.GetRowset(IntPtr.Zero, ref schema, restrictions.Length, restrictions, ref ODB.IID_IRowset, 0, IntPtr.Zero, out rowset); + hr = dbSchemaRowset.GetRowset(IntPtr.Zero, in schema, restrictions.Length, restrictions, in ODB.IID_IRowset, 0, IntPtr.Zero, out rowset); if (hr < 0) { // ignore infomsg diff --git a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs index e86ae13f940e62..4f5ea1101d0e88 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbConnectionString.cs @@ -51,7 +51,7 @@ private static class UDL internal static int _PoolSize; internal static volatile Dictionary? _Pool; - internal static object _PoolLock = new object(); + internal static readonly object _PoolLock = new object(); } private static class VALUES diff --git a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs index a0eaeef4acb7a0..6f1e90f05be064 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbDataReader.cs @@ -611,7 +611,7 @@ private void BuildSchemaTableRowset(object handle) using (DualCoTaskMem prgOptColumns = new DualCoTaskMem(icolumnsRowset, out cOptColumns, out hr)) { Debug.Assert((0 == hr) || prgOptColumns.IsInvalid, "GetAvailableCOlumns: unexpected return"); - hr = icolumnsRowset.GetColumnsRowset(IntPtr.Zero, cOptColumns, prgOptColumns, ref ODB.IID_IRowset, 0, IntPtr.Zero, out rowset); + hr = icolumnsRowset.GetColumnsRowset(IntPtr.Zero, cOptColumns, prgOptColumns, in ODB.IID_IRowset, 0, IntPtr.Zero, out rowset); } Debug.Assert((0 <= hr) || (null == rowset), "if GetColumnsRowset failed, rowset should be null"); @@ -952,7 +952,7 @@ private OleDbDataReader GetDataForReader(IntPtr ordinal, RowBinding rowbinding, UnsafeNativeMethods.IRowsetInfo rowsetInfo = IRowsetInfo(); UnsafeNativeMethods.IRowset? result; OleDbHResult hr; - hr = rowsetInfo.GetReferencedRowset((IntPtr)ordinal, ref ODB.IID_IRowset, out result); + hr = rowsetInfo.GetReferencedRowset((IntPtr)ordinal, in ODB.IID_IRowset, out result); ProcessResults(hr); // Per docs result can be null only when hr is DB_E_NOTAREFERENCECOLUMN which in most of the cases will cause the exception in ProcessResult @@ -1236,7 +1236,7 @@ internal void HasRowsRead() { break; } - hr = imultipleResults.GetResult(IntPtr.Zero, ODB.DBRESULTFLAG_DEFAULT, ref ODB.IID_NULL, out affected, out _); + hr = imultipleResults.GetResult(IntPtr.Zero, ODB.DBRESULTFLAG_DEFAULT, in ODB.IID_NULL, out affected, out _); // If a provider doesn't support IID_NULL and returns E_NOINTERFACE we want to break out // of the loop without throwing an exception. Our behavior will match ADODB in that scenario @@ -1327,7 +1327,7 @@ public override bool NextResult() Close(); break; } - hr = imultipleResults.GetResult(IntPtr.Zero, ODB.DBRESULTFLAG_DEFAULT, ref ODB.IID_IRowset, out affected, out result); + hr = imultipleResults.GetResult(IntPtr.Zero, ODB.DBRESULTFLAG_DEFAULT, in ODB.IID_IRowset, out affected, out result); if ((0 <= hr) && (null != result)) { diff --git a/src/libraries/System.Data.OleDb/src/OleDbError.cs b/src/libraries/System.Data.OleDb/src/OleDbError.cs index db1968fb844ac0..6497414fd49628 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbError.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbError.cs @@ -61,7 +61,7 @@ internal OleDbError(UnsafeNativeMethods.IErrorRecords errorRecords, int index) } UnsafeNativeMethods.ISQLErrorInfo sqlErrorInfo; - errorRecords.GetCustomErrorObject(index, ref ODB.IID_ISQLErrorInfo, out sqlErrorInfo); + errorRecords.GetCustomErrorObject(index, in ODB.IID_ISQLErrorInfo, out sqlErrorInfo); if (null != sqlErrorInfo) { diff --git a/src/libraries/System.Data.OleDb/src/OleDb_Util.cs b/src/libraries/System.Data.OleDb/src/OleDb_Util.cs index d42b00151beb6a..b35087409aebe4 100644 --- a/src/libraries/System.Data.OleDb/src/OleDb_Util.cs +++ b/src/libraries/System.Data.OleDb/src/OleDb_Util.cs @@ -580,24 +580,24 @@ internal static InvalidOperationException IDBInfoNotSupported() internal static readonly int OffsetOf_tagDBBINDING_obValue = Marshal.OffsetOf(typeof(tagDBBINDING), "obValue").ToInt32(); internal static readonly int OffsetOf_tagDBBINDING_wType = Marshal.OffsetOf(typeof(tagDBBINDING), "wType").ToInt32(); - internal static Guid IID_NULL = Guid.Empty; - internal static Guid IID_IUnknown = new Guid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); - internal static Guid IID_IDBInitialize = new Guid(0x0C733A8B, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_IDBCreateSession = new Guid(0x0C733A5D, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_IDBCreateCommand = new Guid(0x0C733A1D, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_ICommandText = new Guid(0x0C733A27, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_IMultipleResults = new Guid(0x0C733A90, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_IRow = new Guid(0x0C733AB4, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_IRowset = new Guid(0x0C733A7C, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - internal static Guid IID_ISQLErrorInfo = new Guid(0x0C733A74, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); - - internal static Guid CLSID_DataLinks = new Guid(0x2206CDB2, 0x19C1, 0x11D1, 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29); - - internal static Guid DBGUID_DEFAULT = new Guid(0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); - internal static Guid DBGUID_ROWSET = new Guid(0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); - internal static Guid DBGUID_ROW = new Guid(0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); - - internal static Guid DBGUID_ROWDEFAULTSTREAM = new Guid(0x0C733AB7, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_NULL = Guid.Empty; + internal static readonly Guid IID_IUnknown = new Guid(0x00000000, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); + internal static readonly Guid IID_IDBInitialize = new Guid(0x0C733A8B, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_IDBCreateSession = new Guid(0x0C733A5D, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_IDBCreateCommand = new Guid(0x0C733A1D, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_ICommandText = new Guid(0x0C733A27, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_IMultipleResults = new Guid(0x0C733A90, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_IRow = new Guid(0x0C733AB4, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_IRowset = new Guid(0x0C733A7C, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + internal static readonly Guid IID_ISQLErrorInfo = new Guid(0x0C733A74, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); + + internal static readonly Guid CLSID_DataLinks = new Guid(0x2206CDB2, 0x19C1, 0x11D1, 0x89, 0xE0, 0x00, 0xC0, 0x4F, 0xD7, 0xA8, 0x29); + + internal static readonly Guid DBGUID_DEFAULT = new Guid(0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); + internal static readonly Guid DBGUID_ROWSET = new Guid(0xc8b522f6, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); + internal static readonly Guid DBGUID_ROW = new Guid(0xc8b522f7, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); + + internal static readonly Guid DBGUID_ROWDEFAULTSTREAM = new Guid(0x0C733AB7, 0x2A1C, 0x11CE, 0xAD, 0xE5, 0x00, 0xAA, 0x00, 0x44, 0x77, 0x3D); internal static readonly Guid CLSID_MSDASQL = new Guid(0xc8b522cb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d); diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs index 4e3b0e9f13e7fa..4bffaa74980f32 100644 --- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs +++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPool.cs @@ -50,10 +50,10 @@ public PendingGetConnection(long dueTime, DbConnection owner, TaskCompletionSour Owner = owner; Completion = completion; } - public long DueTime { get; private set; } - public DbConnection Owner { get; private set; } - public TaskCompletionSource Completion { get; private set; } - public DbConnectionOptions? UserOptions { get; private set; } + public long DueTime { get; } + public DbConnection Owner { get; } + public TaskCompletionSource Completion { get; } + public DbConnectionOptions? UserOptions { get; } } private sealed class TransactedConnectionPool diff --git a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs index db5a7d27e542bc..474d677280e596 100644 --- a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs +++ b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs @@ -299,7 +299,7 @@ System.Data.OleDb.OleDbHResult GetColumnsRowset( [In] IntPtr pUnkOuter, [In] IntPtr cOptColumns, [In] SafeHandle rgOptColumns, - [In] ref Guid riid, + [In] in Guid riid, [In] int cPropertySets, [In] IntPtr rgPropertySets, [Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppColRowset); @@ -367,7 +367,7 @@ HRESULT Execute( [PreserveSig] System.Data.OleDb.OleDbHResult Execute( [In] IntPtr pUnkOuter, - [In] ref Guid riid, + [In] in Guid riid, [In] System.Data.OleDb.tagDBPARAMS? pDBParams, [Out] out IntPtr pcRowsAffected, [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset); @@ -383,7 +383,7 @@ HRESULT SetCommandText( );*/ [PreserveSig] System.Data.OleDb.OleDbHResult SetCommandText( - [In] ref Guid rguidDialect, + [In] in Guid rguidDialect, [In, MarshalAs(UnmanagedType.LPWStr)] string pwszCommand); } @@ -486,10 +486,10 @@ HRESULT GetRowset( [PreserveSig] System.Data.OleDb.OleDbHResult GetRowset( [In] IntPtr pUnkOuter, - [In] ref Guid rguidSchema, + [In] in Guid rguidSchema, [In] int cRestrictions, [In, MarshalAs(UnmanagedType.LPArray)] object?[] rgRestrictions, - [In] ref Guid riid, + [In] in Guid riid, [In] int cPropertySets, [In] IntPtr rgPropertySets, [Out, MarshalAs(UnmanagedType.Interface)] out IRowset ppRowset); @@ -549,7 +549,7 @@ internal interface IErrorRecords [PreserveSig] System.Data.OleDb.OleDbHResult GetCustomErrorObject( // may return E_NOINTERFACE when asking for IID_ISQLErrorInfo [In] int ulRecordNum, - [In] ref Guid riid, + [In] in Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out ISQLErrorInfo ppObject); [return: MarshalAs(UnmanagedType.Interface)] @@ -603,7 +603,7 @@ HRESULT GetResult( System.Data.OleDb.OleDbHResult GetResult( [In] IntPtr pUnkOuter, [In] IntPtr lResultFlag, - [In] ref Guid riid, + [In] in Guid riid, [Out] out IntPtr pcRowsAffected, [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset); } @@ -631,7 +631,7 @@ System.Data.OleDb.OleDbHResult OpenRowset( [In] IntPtr pUnkOuter, [In] System.Data.OleDb.tagDBID pTableID, [In] IntPtr pIndexID, - [In] ref Guid riid, + [In] in Guid riid, [In] int cPropertySets, [In] IntPtr rgPropertySets, [Out, MarshalAs(UnmanagedType.Interface)] out object ppRowset); @@ -718,7 +718,7 @@ System.Data.OleDb.OleDbHResult GetProperties( [PreserveSig] System.Data.OleDb.OleDbHResult GetReferencedRowset( [In] IntPtr iOrdinal, - [In] ref Guid riid, + [In] in Guid riid, [Out, MarshalAs(UnmanagedType.Interface)] out IRowset? ppRowset); //[PreserveSig] diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md b/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md index bcd4e96cb8aa98..15ee7fce3a663d 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/DiagnosticSourceUsersGuide.md @@ -61,7 +61,7 @@ Thus the first step in instrumenting code with `DiagnosticSource` is to create a `DiagnosticListener`. For example: ```C# - private static DiagnosticSource httpLogger = new DiagnosticListener("System.Net.Http"); + private static readonly DiagnosticSource httpLogger = new DiagnosticListener("System.Net.Http"); ``` Notice that httpLogger is typed as a `DiagnosticSource`. This is because this code only cares about writing events and thus only cares about the `DiagnosticSource` methods that @@ -104,7 +104,7 @@ Already some of the architectural elements are being exposed, namely: Perhaps confusingly you make a `DiagnosticSource` by creating a `DiagnosticListener`: ```C# - static DiagnosticSource mySource = new DiagnosticListener("System.Net.Http"); + static readonly DiagnosticSource mySource = new DiagnosticListener("System.Net.Http"); ``` Basically a `DiagnosticListener` is a named place where a source sends its information (events). @@ -248,7 +248,7 @@ A typical use of the `AllListeners` static property looks like this: ```C# // We are using AllListeners to turn an Action into an IObserver - static IDisposable listenerSubscription = DiagnosticListener.AllListeners.Subscribe(delegate (DiagnosticListener listener) + static readonly IDisposable listenerSubscription = DiagnosticListener.AllListeners.Subscribe(delegate (DiagnosticListener listener) { // We get a callback of every Diagnostics Listener that is active in the system (past present or future) if (listener.Name == "System.Net.Http") @@ -290,7 +290,7 @@ call `Subscribe()` on it as well. Thus we can fill out the previous example a bi ```C# static IDisposable networkSubscription = null; - static IDisposable listenerSubscription = DiagnosticListener.AllListeners.Subscribe(delegate (DiagnosticListener listener) + static readonly IDisposable listenerSubscription = DiagnosticListener.AllListeners.Subscribe(delegate (DiagnosticListener listener) { if (listener.Name == "System.Net.Http") { diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs index 1a58f827851cec..7e287c30123a64 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticListener.cs @@ -195,7 +195,7 @@ public virtual void Dispose() /// /// When a DiagnosticListener is created it is given a name. Return this. /// - public string Name { get; private set; } + public string Name { get; } /// /// Return the name for the ToString() to aid in debugging. diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs index fbb13c9c9b6db7..e1678dc3dda86a 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/DiagnosticSourceEventSource.cs @@ -174,7 +174,7 @@ namespace System.Diagnostics "EnsureDescriptorsInitialized does not access these members and is safe to call.")] internal sealed class DiagnosticSourceEventSource : EventSource { - public static DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource(); + public static readonly DiagnosticSourceEventSource Log = new DiagnosticSourceEventSource(); public static class Keywords { @@ -1240,7 +1240,7 @@ public PropertySpec(string propertyName, PropertySpec? next) } } - public bool IsStatic { get; private set; } + public bool IsStatic { get; } /// /// Given an object fetch the property that this PropertySpec represents. diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/HttpHandlerDiagnosticListener.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/HttpHandlerDiagnosticListener.cs index 94d4192721ca54..ef1b21f8cda134 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/HttpHandlerDiagnosticListener.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/HttpHandlerDiagnosticListener.cs @@ -792,7 +792,7 @@ private static Func CreateFieldGetter(Type classType, st #endregion - internal static HttpHandlerDiagnosticListener s_instance = new HttpHandlerDiagnosticListener(); + internal static readonly HttpHandlerDiagnosticListener s_instance = new HttpHandlerDiagnosticListener(); #region private fields private const string DiagnosticListenerName = "System.Net.Http.Desktop"; diff --git a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs index 3fbe68f5545499..a3c443b0a38f11 100644 --- a/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs +++ b/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs @@ -298,7 +298,7 @@ public CommandHandler(MetricsEventSource parent) Parent = parent; } - public MetricsEventSource Parent { get; private set; } + public MetricsEventSource Parent { get; } public bool IsSharedSession(string commandSessionId) { @@ -754,8 +754,8 @@ private static string FormatQuantiles(QuantileValue[] quantiles) private sealed class MetricSpec { private const char MeterInstrumentSeparator = '\\'; - public string MeterName { get; private set; } - public string? InstrumentName { get; private set; } + public string MeterName { get; } + public string? InstrumentName { get; } public MetricSpec(string meterName, string? instrumentName) { diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/constants.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/constants.cs index 98be922fbe23c7..8fe028226b4b23 100644 --- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/constants.cs +++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/constants.cs @@ -20,15 +20,15 @@ internal enum LoadState // These are the default options used when a user does not specify a context option to connect to the store. internal static class DefaultContextOptions { - internal static ContextOptions MachineDefaultContextOption = ContextOptions.Negotiate; - internal static ContextOptions ADDefaultContextOption = ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing; + internal const ContextOptions MachineDefaultContextOption = ContextOptions.Negotiate; + internal const ContextOptions ADDefaultContextOption = ContextOptions.Negotiate | ContextOptions.Signing | ContextOptions.Sealing; } internal static class LdapConstants { - public static int LDAP_SSL_PORT = 636; - public static int LDAP_PORT = 389; - internal static DateTime defaultUtcTime = new DateTime(1601, 1, 1, 0, 0, 0); + public const int LDAP_SSL_PORT = 636; + public const int LDAP_PORT = 389; + internal static readonly DateTime defaultUtcTime = new DateTime(1601, 1, 1, 0, 0, 0); } // The string constants used internally to specify each property internal static class PropertyNames diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.cs index 3dc2a589a8d5d0..012f137b7df842 100644 --- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.cs +++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/SafeHandles.cs @@ -8,7 +8,7 @@ namespace System.DirectoryServices.Protocols { internal sealed class HGlobalMemHandle : SafeHandleZeroOrMinusOneIsInvalid { - internal static IntPtr _dummyPointer = new IntPtr(1); + internal const IntPtr _dummyPointer = 1; internal HGlobalMemHandle(IntPtr value) : base(true) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs index 278aa9cdad7522..9d08baf2f767db 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/PropertyManager.cs @@ -8,121 +8,103 @@ namespace System.DirectoryServices.ActiveDirectory { internal static class PropertyManager { - public static string DefaultNamingContext = "defaultNamingContext"; - public static string SchemaNamingContext = "schemaNamingContext"; - public static string ConfigurationNamingContext = "configurationNamingContext"; - public static string RootDomainNamingContext = "rootDomainNamingContext"; - public static string MsDSBehaviorVersion = "msDS-Behavior-Version"; - public static string FsmoRoleOwner = "fsmoRoleOwner"; - public static string ForestFunctionality = "forestFunctionality"; - public static string NTMixedDomain = "ntMixedDomain"; - public static string DomainFunctionality = "domainFunctionality"; - public static string ObjectCategory = "objectCategory"; - public static string SystemFlags = "systemFlags"; - public static string DnsRoot = "dnsRoot"; - public static string DistinguishedName = "distinguishedName"; - public static string TrustParent = "trustParent"; + public const string DefaultNamingContext = "defaultNamingContext"; + public const string SchemaNamingContext = "schemaNamingContext"; + public const string ConfigurationNamingContext = "configurationNamingContext"; + public const string RootDomainNamingContext = "rootDomainNamingContext"; + public const string MsDSBehaviorVersion = "msDS-Behavior-Version"; + public const string FsmoRoleOwner = "fsmoRoleOwner"; + public const string ForestFunctionality = "forestFunctionality"; + public const string NTMixedDomain = "ntMixedDomain"; + public const string DomainFunctionality = "domainFunctionality"; + public const string ObjectCategory = "objectCategory"; + public const string SystemFlags = "systemFlags"; + public const string DnsRoot = "dnsRoot"; + public const string DistinguishedName = "distinguishedName"; + public const string TrustParent = "trustParent"; // disable csharp compiler warning #0414: field assigned unused value #pragma warning disable 0414 - public static string FlatName = "flatName"; - public static string Name = "name"; - public static string Flags = "flags"; - public static string TrustType = "trustType"; - public static string TrustAttributes = "trustAttributes"; + public const string FlatName = "flatName"; + public const string Name = "name"; + public const string Flags = "flags"; + public const string TrustType = "trustType"; + public const string TrustAttributes = "trustAttributes"; #pragma warning restore 0414 - public static string BecomeSchemaMaster = "becomeSchemaMaster"; - public static string BecomeDomainMaster = "becomeDomainMaster"; - public static string BecomePdc = "becomePdc"; - public static string BecomeRidMaster = "becomeRidMaster"; - public static string BecomeInfrastructureMaster = "becomeInfrastructureMaster"; - public static string DnsHostName = "dnsHostName"; - public static string Options = "options"; - public static string CurrentTime = "currentTime"; - public static string HighestCommittedUSN = "highestCommittedUSN"; - public static string OperatingSystem = "operatingSystem"; - public static string HasMasterNCs = "hasMasterNCs"; - public static string MsDSHasMasterNCs = "msDS-HasMasterNCs"; - public static string MsDSHasFullReplicaNCs = "msDS-hasFullReplicaNCs"; - public static string NCName = "nCName"; - public static string Cn = "cn"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string NETBIOSName = "nETBIOSName"; -#pragma warning restore 0414 - public static string DomainDNS = "domainDNS"; - public static string InstanceType = "instanceType"; - public static string MsDSSDReferenceDomain = "msDS-SDReferenceDomain"; - public static string MsDSPortLDAP = "msDS-PortLDAP"; - public static string MsDSPortSSL = "msDS-PortSSL"; - public static string MsDSNCReplicaLocations = "msDS-NC-Replica-Locations"; - public static string MsDSNCROReplicaLocations = "msDS-NC-RO-Replica-Locations"; - public static string SupportedCapabilities = "supportedCapabilities"; - public static string ServerName = "serverName"; - public static string Enabled = "Enabled"; - public static string ObjectGuid = "objectGuid"; - public static string Keywords = "keywords"; - public static string ServiceBindingInformation = "serviceBindingInformation"; - public static string MsDSReplAuthenticationMode = "msDS-ReplAuthenticationMode"; - public static string HasPartialReplicaNCs = "hasPartialReplicaNCs"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string Container = "container"; -#pragma warning restore 0414 - public static string LdapDisplayName = "ldapDisplayName"; - public static string AttributeID = "attributeID"; - public static string AttributeSyntax = "attributeSyntax"; - public static string Description = "description"; - public static string SearchFlags = "searchFlags"; - public static string OMSyntax = "oMSyntax"; - public static string OMObjectClass = "oMObjectClass"; - public static string IsSingleValued = "isSingleValued"; - public static string IsDefunct = "isDefunct"; - public static string RangeUpper = "rangeUpper"; - public static string RangeLower = "rangeLower"; - public static string IsMemberOfPartialAttributeSet = "isMemberOfPartialAttributeSet"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string ObjectVersion = "objectVersion"; -#pragma warning restore 0414 - public static string LinkID = "linkID"; - public static string ObjectClassCategory = "objectClassCategory"; - public static string SchemaUpdateNow = "schemaUpdateNow"; - public static string SubClassOf = "subClassOf"; - public static string SchemaIDGuid = "schemaIDGUID"; - public static string PossibleSuperiors = "possSuperiors"; - public static string PossibleInferiors = "possibleInferiors"; - public static string MustContain = "mustContain"; - public static string MayContain = "mayContain"; - public static string SystemMustContain = "systemMustContain"; - public static string SystemMayContain = "systemMayContain"; - public static string GovernsID = "governsID"; - public static string IsGlobalCatalogReady = "isGlobalCatalogReady"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string NTSecurityDescriptor = "ntSecurityDescriptor"; -#pragma warning restore 0414 - public static string DsServiceName = "dsServiceName"; - public static string ReplicateSingleObject = "replicateSingleObject"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string MsDSMasteredBy = "msDS-masteredBy"; -#pragma warning restore 0414 - public static string DefaultSecurityDescriptor = "defaultSecurityDescriptor"; - public static string NamingContexts = "namingContexts"; - public static string MsDSDefaultNamingContext = "msDS-DefaultNamingContext"; - public static string OperatingSystemVersion = "operatingSystemVersion"; - public static string AuxiliaryClass = "auxiliaryClass"; - public static string SystemAuxiliaryClass = "systemAuxiliaryClass"; - public static string SystemPossibleSuperiors = "systemPossSuperiors"; - public static string InterSiteTopologyGenerator = "interSiteTopologyGenerator"; - public static string FromServer = "fromServer"; - public static string RIDAvailablePool = "rIDAvailablePool"; + public const string BecomeSchemaMaster = "becomeSchemaMaster"; + public const string BecomeDomainMaster = "becomeDomainMaster"; + public const string BecomePdc = "becomePdc"; + public const string BecomeRidMaster = "becomeRidMaster"; + public const string BecomeInfrastructureMaster = "becomeInfrastructureMaster"; + public const string DnsHostName = "dnsHostName"; + public const string Options = "options"; + public const string CurrentTime = "currentTime"; + public const string HighestCommittedUSN = "highestCommittedUSN"; + public const string OperatingSystem = "operatingSystem"; + public const string HasMasterNCs = "hasMasterNCs"; + public const string MsDSHasMasterNCs = "msDS-HasMasterNCs"; + public const string MsDSHasFullReplicaNCs = "msDS-hasFullReplicaNCs"; + public const string NCName = "nCName"; + public const string Cn = "cn"; + public const string NETBIOSName = "nETBIOSName"; + public const string DomainDNS = "domainDNS"; + public const string InstanceType = "instanceType"; + public const string MsDSSDReferenceDomain = "msDS-SDReferenceDomain"; + public const string MsDSPortLDAP = "msDS-PortLDAP"; + public const string MsDSPortSSL = "msDS-PortSSL"; + public const string MsDSNCReplicaLocations = "msDS-NC-Replica-Locations"; + public const string MsDSNCROReplicaLocations = "msDS-NC-RO-Replica-Locations"; + public const string SupportedCapabilities = "supportedCapabilities"; + public const string ServerName = "serverName"; + public const string Enabled = "Enabled"; + public const string ObjectGuid = "objectGuid"; + public const string Keywords = "keywords"; + public const string ServiceBindingInformation = "serviceBindingInformation"; + public const string MsDSReplAuthenticationMode = "msDS-ReplAuthenticationMode"; + public const string HasPartialReplicaNCs = "hasPartialReplicaNCs"; + public const string Container = "container"; + public const string LdapDisplayName = "ldapDisplayName"; + public const string AttributeID = "attributeID"; + public const string AttributeSyntax = "attributeSyntax"; + public const string Description = "description"; + public const string SearchFlags = "searchFlags"; + public const string OMSyntax = "oMSyntax"; + public const string OMObjectClass = "oMObjectClass"; + public const string IsSingleValued = "isSingleValued"; + public const string IsDefunct = "isDefunct"; + public const string RangeUpper = "rangeUpper"; + public const string RangeLower = "rangeLower"; + public const string IsMemberOfPartialAttributeSet = "isMemberOfPartialAttributeSet"; + public const string ObjectVersion = "objectVersion"; + public const string LinkID = "linkID"; + public const string ObjectClassCategory = "objectClassCategory"; + public const string SchemaUpdateNow = "schemaUpdateNow"; + public const string SubClassOf = "subClassOf"; + public const string SchemaIDGuid = "schemaIDGUID"; + public const string PossibleSuperiors = "possSuperiors"; + public const string PossibleInferiors = "possibleInferiors"; + public const string MustContain = "mustContain"; + public const string MayContain = "mayContain"; + public const string SystemMustContain = "systemMustContain"; + public const string SystemMayContain = "systemMayContain"; + public const string GovernsID = "governsID"; + public const string IsGlobalCatalogReady = "isGlobalCatalogReady"; + public const string NTSecurityDescriptor = "ntSecurityDescriptor"; + public const string DsServiceName = "dsServiceName"; + public const string ReplicateSingleObject = "replicateSingleObject"; + public const string MsDSMasteredBy = "msDS-masteredBy"; + public const string DefaultSecurityDescriptor = "defaultSecurityDescriptor"; + public const string NamingContexts = "namingContexts"; + public const string MsDSDefaultNamingContext = "msDS-DefaultNamingContext"; + public const string OperatingSystemVersion = "operatingSystemVersion"; + public const string AuxiliaryClass = "auxiliaryClass"; + public const string SystemAuxiliaryClass = "systemAuxiliaryClass"; + public const string SystemPossibleSuperiors = "systemPossSuperiors"; + public const string InterSiteTopologyGenerator = "interSiteTopologyGenerator"; + public const string FromServer = "fromServer"; + public const string RIDAvailablePool = "rIDAvailablePool"; - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - public static string SiteList = "siteList"; -#pragma warning restore 0414 - public static string MsDSHasInstantiatedNCs = "msDS-HasInstantiatedNCs"; + public const string SiteList = "siteList"; + public const string MsDSHasInstantiatedNCs = "msDS-HasInstantiatedNCs"; public static object? GetPropertyValue(DirectoryEntry directoryEntry, string propertyName) { diff --git a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs index 56412ca15b0279..19a6879f635a2e 100644 --- a/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs +++ b/src/libraries/System.DirectoryServices/src/System/DirectoryServices/ActiveDirectory/Utils.cs @@ -34,8 +34,8 @@ internal enum SidType internal struct SupportedCapability { - public static string ADOid = "1.2.840.113556.1.4.800"; - public static string ADAMOid = "1.2.840.113556.1.4.1851"; + public const string ADOid = "1.2.840.113556.1.4.800"; + public const string ADAMOid = "1.2.840.113556.1.4.1851"; } internal sealed class Utils diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index df77341be9a039..a3e1bd82d25918 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -81,7 +81,7 @@ public TarWriter(Stream archiveStream, TarEntryFormat format = TarEntryFormat.Pa /// /// The format of the entries when writing entries to the archive using the method. /// - public TarEntryFormat Format { get; private set; } + public TarEntryFormat Format { get; } /// /// Disposes the current instance, and closes the archive stream if the leaveOpen argument was set to in the constructor. diff --git a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriterOptions.cs b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriterOptions.cs index 35c1da235f8662..15dfc3b0292c85 100644 --- a/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriterOptions.cs +++ b/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/StreamPipeWriterOptions.cs @@ -10,7 +10,7 @@ public class StreamPipeWriterOptions { private const int DefaultMinimumBufferSize = 4096; - internal static StreamPipeWriterOptions s_default = new StreamPipeWriterOptions(); + internal static readonly StreamPipeWriterOptions s_default = new StreamPipeWriterOptions(); /// Initializes a instance, optionally specifying a memory pool, a minimum buffer size, and whether the underlying stream should be left open after the completes. /// The memory pool to use when allocating memory. The default value is . diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialDataReceivedEventArgs.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialDataReceivedEventArgs.cs index 5a8c2a1a65079f..7027f0212d5ea5 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialDataReceivedEventArgs.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialDataReceivedEventArgs.cs @@ -10,6 +10,6 @@ internal SerialDataReceivedEventArgs(SerialData eventCode) EventType = eventCode; } - public SerialData EventType { get; private set; } + public SerialData EventType { get; } } } diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialErrorReceivedEventArgs.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialErrorReceivedEventArgs.cs index 972783912ae442..d959a853033836 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialErrorReceivedEventArgs.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialErrorReceivedEventArgs.cs @@ -10,6 +10,6 @@ internal SerialErrorReceivedEventArgs(SerialError eventCode) EventType = eventCode; } - public SerialError EventType { get; private set; } + public SerialError EventType { get; } } } diff --git a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPinChangedEventArgs.cs b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPinChangedEventArgs.cs index 46bdf9ef88092f..41f2e0e2556d8b 100644 --- a/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPinChangedEventArgs.cs +++ b/src/libraries/System.IO.Ports/src/System/IO/Ports/SerialPinChangedEventArgs.cs @@ -10,6 +10,6 @@ internal SerialPinChangedEventArgs(SerialPinChange eventCode) EventType = eventCode; } - public SerialPinChange EventType { get; private set; } + public SerialPinChange EventType { get; } } } diff --git a/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs b/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs index 46905a8a0b1f91..288d01c185dbf5 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs @@ -1026,7 +1026,7 @@ private BindingRestrictions GetRestrictions() /// private sealed class ExpandoData { - internal static ExpandoData Empty = new ExpandoData(); + internal static readonly ExpandoData Empty = new ExpandoData(); /// /// the dynamically assigned class associated with the Expando object diff --git a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/DelegateHelpers.Generated.cs b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/DelegateHelpers.Generated.cs index 1ebd36b069882e..9c1a1fe7c6d2d7 100644 --- a/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/DelegateHelpers.Generated.cs +++ b/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Compiler/DelegateHelpers.Generated.cs @@ -55,7 +55,7 @@ internal static TypeInfo GetNextTypeInfo(Type initialArg, TypeInfo curTypeInfo) } } - private static TypeInfo _DelegateCache = new TypeInfo(); + private static readonly TypeInfo _DelegateCache = new TypeInfo(); private const int MaximumArity = 17; diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/Scheduling.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/Scheduling.cs index acc5c8f1703711..142ecda782b5ce 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/Scheduling.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Scheduling/Scheduling.cs @@ -30,9 +30,8 @@ internal static class Scheduling // Whether to preserve order by default, when neither AsOrdered nor AsUnordered is used. internal const bool DefaultPreserveOrder = false; - // The default degree of parallelism, or -1 if unspecified. Dev unit tests set this value - // to change the default DOP. - internal static int DefaultDegreeOfParallelism = Math.Min(Environment.ProcessorCount, MAX_SUPPORTED_DOP); + // The default degree of parallelism. + internal static readonly int DefaultDegreeOfParallelism = Math.Min(Environment.ProcessorCount, MAX_SUPPORTED_DOP); // The size to use for bounded buffers. internal const int DEFAULT_BOUNDED_BUFFER_CAPACITY = 512; diff --git a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs index 7cf1ba84e8536a..590dbce5a518cc 100644 --- a/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs +++ b/src/libraries/System.Linq.Parallel/src/System/Linq/Parallel/Utils/PLINQETWProvider.cs @@ -28,7 +28,7 @@ internal sealed class PlinqEtwProvider : EventSource /// Defines the singleton instance for the PLINQ ETW provider. /// The PLINQ Event provider GUID is {159eeeec-4a14-4418-a8fe-faabcd987887}. /// - internal static PlinqEtwProvider Log = new PlinqEtwProvider(); + internal static readonly PlinqEtwProvider Log = new PlinqEtwProvider(); /// Prevent external instantiation. All logging should go through the Log instance. private PlinqEtwProvider() { } diff --git a/src/libraries/System.Management/src/System/Management/InteropClasses/WMIInterop.cs b/src/libraries/System.Management/src/System/Management/InteropClasses/WMIInterop.cs index 8dd98bd0f5688b..8ef0deb6551d5f 100644 --- a/src/libraries/System.Management/src/System/Management/InteropClasses/WMIInterop.cs +++ b/src/libraries/System.Management/src/System/Management/InteropClasses/WMIInterop.cs @@ -366,7 +366,7 @@ private enum MSHLFLAGS internal sealed class IWbemQualifierSetFreeThreaded : IDisposable { private static readonly string name = typeof(IWbemQualifierSetFreeThreaded).FullName; - public static Guid IID_IWbemClassObject = new Guid("DC12A681-737F-11CF-884D-00AA004B2E24"); + public static readonly Guid IID_IWbemClassObject = new Guid("DC12A681-737F-11CF-884D-00AA004B2E24"); private IntPtr pWbemQualifierSet = IntPtr.Zero; public IWbemQualifierSetFreeThreaded(IntPtr pWbemQualifierSet) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderParser.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderParser.cs index 711e37cf14694a..25449e6b5d36b8 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderParser.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaderParser.cs @@ -13,11 +13,11 @@ internal abstract class HttpHeaderParser public const string DefaultSeparator = ", "; public static readonly byte[] DefaultSeparatorBytes = ", "u8.ToArray(); - public bool SupportsMultipleValues { get; private set; } + public bool SupportsMultipleValues { get; } - public string Separator { get; private set; } + public string Separator { get; } - public byte[] SeparatorBytes { get; private set; } + public byte[] SeparatorBytes { get; } // If ValueType implements Equals() as required, there is no need to provide a comparer. A comparer is needed // e.g. if we want to compare strings using case-insensitive comparison. diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerContext.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerContext.Windows.cs index 010b702d6225fc..2c76626a75b54c 100644 --- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerContext.Windows.cs +++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListenerContext.Windows.cs @@ -15,7 +15,7 @@ namespace System.Net public sealed unsafe partial class HttpListenerContext { private string? _mutualAuthentication; - internal HttpListenerSession ListenerSession { get; private set; } + internal HttpListenerSession ListenerSession { get; } internal HttpListenerContext(HttpListenerSession session, RequestContextBase memoryBlob) { diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs index 5d062e94fd80a9..2385e4d9800849 100644 --- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs +++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/NetworkAddressChange.OSX.cs @@ -17,7 +17,7 @@ namespace System.Net.NetworkInformation // the documentation for CFRunLoop for more information on the components involved. public partial class NetworkChange { - private static object s_lockObj = new object(); + private static readonly object s_lockObj = new object(); // The dynamic store. We listen to changes in the IPv4 and IPv6 address keys. // When those keys change, our callback below is called (OnAddressChanged). diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs index 4b284284f5262c..829c279969c2ea 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs @@ -54,7 +54,7 @@ private MsQuicApi(QUIC_API_TABLE* apiTable) private static readonly Lazy _api = new Lazy(AllocateMsQuicApi); internal static MsQuicApi Api => _api.Value; - internal static Version? Version { get; private set; } + internal static Version? Version { get; } internal static bool IsQuicSupported { get; } diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.Counters.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.Counters.cs index 93ec7e7532c7f3..a7a392858c89a6 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.Counters.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/NetEventSource.Quic.Counters.cs @@ -14,7 +14,7 @@ namespace System.Net { internal sealed partial class NetEventSource { - private static Meter s_meter = new Meter("Private.InternalDiagnostics.System.Net.Quic.MsQuic"); + private static readonly Meter s_meter = new Meter("Private.InternalDiagnostics.System.Net.Quic.MsQuic"); private static long s_countersLastFetched; private static readonly long[] s_counters = new long[(int)QUIC_PERFORMANCE_COUNTERS.MAX]; public static readonly ObservableCounter s_CONN_CREATED = s_meter.CreateObservableCounter( diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicDefaults.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicDefaults.cs index e31bc1d21c20dd..f2248431d05dad 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicDefaults.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/QuicDefaults.cs @@ -41,10 +41,10 @@ internal static partial class QuicDefaults /// /// Default initial_max_data value. /// - public static int DefaultConnectionMaxData = 16 * 1024 * 1024; + public const int DefaultConnectionMaxData = 16 * 1024 * 1024; /// /// Default initial_max_stream_data_* value. /// - public static int DefaultStreamMaxData = 64 * 1024; + public const int DefaultStreamMaxData = 64 * 1024; } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicy.cs b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicy.cs index 8b3d6a0aaf1f5d..2dd83bfe4d20b1 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicy.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicy.cs @@ -13,7 +13,7 @@ namespace System.Net.Security [UnsupportedOSPlatform("android")] public sealed partial class CipherSuitesPolicy { - internal CipherSuitesPolicyPal Pal { get; private set; } + internal CipherSuitesPolicyPal Pal { get; } [CLSCompliant(false)] public CipherSuitesPolicy(IEnumerable allowedCipherSuites) diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.Android.cs b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.Android.cs index b96c301c7d5125..064d5a76fce06f 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.Android.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.Android.cs @@ -8,7 +8,7 @@ namespace System.Net.Security { internal sealed class CipherSuitesPolicyPal { - internal TlsCipherSuite[] TlsCipherSuites { get; private set; } + internal TlsCipherSuite[] TlsCipherSuites { get; } internal CipherSuitesPolicyPal(IEnumerable allowedCipherSuites) { diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.OSX.cs b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.OSX.cs index 4838e4738a399e..bd042c16757105 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.OSX.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/CipherSuitesPolicyPal.OSX.cs @@ -8,7 +8,7 @@ namespace System.Net.Security { internal sealed class CipherSuitesPolicyPal { - internal uint[] TlsCipherSuites { get; private set; } + internal uint[] TlsCipherSuites { get; } internal CipherSuitesPolicyPal(IEnumerable allowedCipherSuites) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs index 548f792b524311..f54eae0969803f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeEventDispatcher.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.Win32.SafeHandles; namespace System.Diagnostics.Tracing { @@ -11,8 +10,8 @@ internal sealed class EventPipeEventDispatcher { internal sealed class EventListenerSubscription { - internal EventKeywords MatchAnyKeywords { get; private set; } - internal EventLevel Level { get; private set; } + internal EventKeywords MatchAnyKeywords { get; } + internal EventLevel Level { get; } internal EventListenerSubscription(EventKeywords matchAnyKeywords, EventLevel level) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs index ed19ea2178e38d..efdb735b7b12c9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventPipeMetadataGenerator.cs @@ -13,7 +13,7 @@ private enum MetadataTag ParameterPayload = 2 } - public static EventPipeMetadataGenerator Instance = new EventPipeMetadataGenerator(); + public static readonly EventPipeMetadataGenerator Instance = new EventPipeMetadataGenerator(); private EventPipeMetadataGenerator() { } diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs index 61c7d5218bc67a..265035996eee0b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs @@ -212,7 +212,7 @@ internal sealed class EventSourceAutoGenerateAttribute : Attribute /// [EventSource(Name="Samples.Demos.Minimal")] /// sealed class MinimalEventSource : EventSource /// { - /// public static MinimalEventSource Log = new MinimalEventSource(); + /// public static readonly MinimalEventSource Log = new MinimalEventSource(); /// public void Load(long ImageBase, string Name) { WriteEvent(1, ImageBase, Name); } /// public void Unload(long ImageBase) { WriteEvent(2, ImageBase); } /// private MinimalEventSource() {} @@ -4851,12 +4851,12 @@ public sealed class EventAttribute : Attribute /// ID of the ETW event (an integer between 1 and 65535) public EventAttribute(int eventId) { - this.EventId = eventId; + EventId = eventId; Level = EventLevel.Informational; } /// Event's ID - public int EventId { get; private set; } + public int EventId { get; } /// Event's severity level: indicates the severity or verbosity of the event public EventLevel Level { get; set; } /// Event's keywords: allows classification of events by "categories" @@ -4867,8 +4867,8 @@ public EventOpcode Opcode get => m_opcode; set { - this.m_opcode = value; - this.m_opcodeSet = true; + m_opcode = value; + m_opcodeSet = true; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/LocalDataStoreSlot.cs b/src/libraries/System.Private.CoreLib/src/System/LocalDataStoreSlot.cs index 257fe85bfeabf8..23adf4a566eb65 100644 --- a/src/libraries/System.Private.CoreLib/src/System/LocalDataStoreSlot.cs +++ b/src/libraries/System.Private.CoreLib/src/System/LocalDataStoreSlot.cs @@ -14,7 +14,7 @@ internal LocalDataStoreSlot(ThreadLocal data) GC.SuppressFinalize(this); } - internal ThreadLocal Data { get; private set; } + internal ThreadLocal Data { get; } [SuppressMessage("Microsoft.Security", "CA1821", Justification = "Finalizer preserved for compat, it is suppressed by the constructor.")] ~LocalDataStoreSlot() diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs index f3b28edf11123d..f76e4f0eebd14e 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/ClassDataContract.cs @@ -1305,7 +1305,7 @@ public int Compare(Member x, Member y) return x._baseTypeIndex - y._baseTypeIndex; } - internal static DataMemberConflictComparer Singleton = new DataMemberConflictComparer(); + internal static readonly DataMemberConflictComparer Singleton = new DataMemberConflictComparer(); } } @@ -1491,7 +1491,7 @@ public int Compare(DataMember? x, DataMember? y) return string.CompareOrdinal(x.Name, y.Name); } - internal static DataMemberComparer Singleton = new DataMemberComparer(); + internal static readonly DataMemberComparer Singleton = new DataMemberComparer(); } /// diff --git a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs index ffa24e873bd9c8..2740e34ca3c329 100644 --- a/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs +++ b/src/libraries/System.Private.DataContractSerialization/src/System/Runtime/Serialization/XmlSerializableServices.cs @@ -62,7 +62,7 @@ public static void WriteNodes(XmlWriter xmlWriter, XmlNode?[]? nodes) nodes[i]!.WriteTo(xmlWriter); } - internal static string AddDefaultSchemaMethodName = "AddDefaultSchema"; + internal const string AddDefaultSchemaMethodName = "AddDefaultSchema"; public static void AddDefaultSchema(XmlSchemaSet schemas, XmlQualifiedName typeQName) { ArgumentNullException.ThrowIfNull(schemas); diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlDocument.cs b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlDocument.cs index 42f275027562a5..a7f9c855edfa00 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlDocument.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Dom/XmlDocument.cs @@ -125,10 +125,10 @@ private static readonly (string key, int hash)[] s_nameTableSeeds = new[] private XmlAttribute? _namespaceXml; - internal static EmptyEnumerator EmptyEnumerator = new EmptyEnumerator(); - internal static IXmlSchemaInfo NotKnownSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.NotKnown); - internal static IXmlSchemaInfo ValidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Valid); - internal static IXmlSchemaInfo InvalidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Invalid); + internal static readonly EmptyEnumerator EmptyEnumerator = new EmptyEnumerator(); + internal static readonly IXmlSchemaInfo NotKnownSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.NotKnown); + internal static readonly IXmlSchemaInfo ValidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Valid); + internal static readonly IXmlSchemaInfo InvalidSchemaInfo = new XmlSchemaInfo(XmlSchemaValidity.Invalid); // Initializes a new instance of the XmlDocument class. public XmlDocument() : this(new XmlImplementation()) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/DataTypeImplementation.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/DataTypeImplementation.cs index 05f8bdc0bcbbcf..072991c236d72c 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/DataTypeImplementation.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/DataTypeImplementation.cs @@ -114,19 +114,19 @@ internal abstract class DatatypeImplementation : XmlSchemaDatatype private const int anySimpleTypeIndex = 11; - internal static XmlQualifiedName QnAnySimpleType = new XmlQualifiedName("anySimpleType", XmlReservedNs.NsXs); - internal static XmlQualifiedName QnAnyType = new XmlQualifiedName("anyType", XmlReservedNs.NsXs); + internal static readonly XmlQualifiedName QnAnySimpleType = new XmlQualifiedName("anySimpleType", XmlReservedNs.NsXs); + internal static readonly XmlQualifiedName QnAnyType = new XmlQualifiedName("anyType", XmlReservedNs.NsXs); //Create facet checkers - internal static FacetsChecker stringFacetsChecker = new StringFacetsChecker(); - internal static FacetsChecker miscFacetsChecker = new MiscFacetsChecker(); - internal static FacetsChecker numeric2FacetsChecker = new Numeric2FacetsChecker(); - internal static FacetsChecker binaryFacetsChecker = new BinaryFacetsChecker(); - internal static FacetsChecker dateTimeFacetsChecker = new DateTimeFacetsChecker(); - internal static FacetsChecker durationFacetsChecker = new DurationFacetsChecker(); - internal static FacetsChecker listFacetsChecker = new ListFacetsChecker(); - internal static FacetsChecker qnameFacetsChecker = new QNameFacetsChecker(); - internal static FacetsChecker unionFacetsChecker = new UnionFacetsChecker(); + internal static readonly FacetsChecker stringFacetsChecker = new StringFacetsChecker(); + internal static readonly FacetsChecker miscFacetsChecker = new MiscFacetsChecker(); + internal static readonly FacetsChecker numeric2FacetsChecker = new Numeric2FacetsChecker(); + internal static readonly FacetsChecker binaryFacetsChecker = new BinaryFacetsChecker(); + internal static readonly FacetsChecker dateTimeFacetsChecker = new DateTimeFacetsChecker(); + internal static readonly FacetsChecker durationFacetsChecker = new DurationFacetsChecker(); + internal static readonly FacetsChecker listFacetsChecker = new ListFacetsChecker(); + internal static readonly FacetsChecker qnameFacetsChecker = new QNameFacetsChecker(); + internal static readonly FacetsChecker unionFacetsChecker = new UnionFacetsChecker(); static DatatypeImplementation() { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs index 9c7e3c6e4f87b9..dfc8b6fe880df8 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/Inference/Infer.cs @@ -15,26 +15,26 @@ namespace System.Xml.Schema /// public sealed class XmlSchemaInference { - internal static XmlQualifiedName ST_boolean = new XmlQualifiedName("boolean", XmlSchema.Namespace); - internal static XmlQualifiedName ST_byte = new XmlQualifiedName("byte", XmlSchema.Namespace); - internal static XmlQualifiedName ST_unsignedByte = new XmlQualifiedName("unsignedByte", XmlSchema.Namespace); - internal static XmlQualifiedName ST_short = new XmlQualifiedName("short", XmlSchema.Namespace); - internal static XmlQualifiedName ST_unsignedShort = new XmlQualifiedName("unsignedShort", XmlSchema.Namespace); - internal static XmlQualifiedName ST_int = new XmlQualifiedName("int", XmlSchema.Namespace); - internal static XmlQualifiedName ST_unsignedInt = new XmlQualifiedName("unsignedInt", XmlSchema.Namespace); - internal static XmlQualifiedName ST_long = new XmlQualifiedName("long", XmlSchema.Namespace); - internal static XmlQualifiedName ST_unsignedLong = new XmlQualifiedName("unsignedLong", XmlSchema.Namespace); - internal static XmlQualifiedName ST_integer = new XmlQualifiedName("integer", XmlSchema.Namespace); - internal static XmlQualifiedName ST_decimal = new XmlQualifiedName("decimal", XmlSchema.Namespace); - internal static XmlQualifiedName ST_float = new XmlQualifiedName("float", XmlSchema.Namespace); - internal static XmlQualifiedName ST_double = new XmlQualifiedName("double", XmlSchema.Namespace); - internal static XmlQualifiedName ST_duration = new XmlQualifiedName("duration", XmlSchema.Namespace); - internal static XmlQualifiedName ST_dateTime = new XmlQualifiedName("dateTime", XmlSchema.Namespace); - internal static XmlQualifiedName ST_time = new XmlQualifiedName("time", XmlSchema.Namespace); - internal static XmlQualifiedName ST_date = new XmlQualifiedName("date", XmlSchema.Namespace); - internal static XmlQualifiedName ST_gYearMonth = new XmlQualifiedName("gYearMonth", XmlSchema.Namespace); - internal static XmlQualifiedName ST_string = new XmlQualifiedName("string", XmlSchema.Namespace); - internal static XmlQualifiedName ST_anySimpleType = new XmlQualifiedName("anySimpleType", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_boolean = new XmlQualifiedName("boolean", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_byte = new XmlQualifiedName("byte", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_unsignedByte = new XmlQualifiedName("unsignedByte", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_short = new XmlQualifiedName("short", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_unsignedShort = new XmlQualifiedName("unsignedShort", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_int = new XmlQualifiedName("int", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_unsignedInt = new XmlQualifiedName("unsignedInt", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_long = new XmlQualifiedName("long", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_unsignedLong = new XmlQualifiedName("unsignedLong", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_integer = new XmlQualifiedName("integer", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_decimal = new XmlQualifiedName("decimal", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_float = new XmlQualifiedName("float", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_double = new XmlQualifiedName("double", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_duration = new XmlQualifiedName("duration", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_dateTime = new XmlQualifiedName("dateTime", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_time = new XmlQualifiedName("time", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_date = new XmlQualifiedName("date", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_gYearMonth = new XmlQualifiedName("gYearMonth", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_string = new XmlQualifiedName("string", XmlSchema.Namespace); + internal static readonly XmlQualifiedName ST_anySimpleType = new XmlQualifiedName("anySimpleType", XmlSchema.Namespace); internal static XmlQualifiedName[] SimpleTypes = { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs index 8747cc9a39d8f6..7b6846b1d5d1c9 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Serialization/XmlSerializationEventSource.cs @@ -9,7 +9,7 @@ namespace System.Xml.Serialization Name = "System.Xml.Serialzation.XmlSerialization")] internal sealed class XmlSerializationEventSource : EventSource { - internal static XmlSerializationEventSource Log = new XmlSerializationEventSource(); + internal static readonly XmlSerializationEventSource Log = new XmlSerializationEventSource(); [Event(EventIds.XmlSerializerExpired, Level = EventLevel.Informational)] internal void XmlSerializerExpired(string serializerName, string type) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathEmptyIterator.cs b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathEmptyIterator.cs index 6c9f61662249cd..e2fd6bb1de81f5 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathEmptyIterator.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XPath/Internal/XPathEmptyIterator.cs @@ -33,6 +33,6 @@ public override bool MoveNext() public override void Reset() { } // -- Instance - public static XPathEmptyIterator Instance = new XPathEmptyIterator(); + public static readonly XPathEmptyIterator Instance = new XPathEmptyIterator(); } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs index 793f75f324d43d..e6a7b8e5487c2f 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/SourceLineInfo.cs @@ -55,7 +55,7 @@ public SourceLineInfo(string? uriString, Location start, Location end) /// private const int NoSourceMagicNumber = 0xfeefee; - public static SourceLineInfo NoSource = new SourceLineInfo(string.Empty, NoSourceMagicNumber, 0, NoSourceMagicNumber, 0); + public static readonly SourceLineInfo NoSource = new SourceLineInfo(string.Empty, NoSourceMagicNumber, 0, NoSourceMagicNumber, 0); public bool IsNoSource { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs index d5f44fe82342d4..918dfa58a2cd7a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/Compiler.cs @@ -445,7 +445,7 @@ internal sealed class DecimalFormatDecl public readonly string NanSymbol; public readonly char[] Characters; - public static DecimalFormatDecl Default = new DecimalFormatDecl(new XmlQualifiedName(), "Infinity", "NaN", ".,%\u20300#;-"); + public static readonly DecimalFormatDecl Default = new DecimalFormatDecl(new XmlQualifiedName(), "Infinity", "NaN", ".,%\u20300#;-"); public DecimalFormatDecl(XmlQualifiedName name, string infinitySymbol, string nanSymbol, string characters) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltLoader.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltLoader.cs index 49c19730c53f3e..7148aacf2294df 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltLoader.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/Xslt/XsltLoader.cs @@ -30,13 +30,13 @@ internal sealed class XsltLoader : IErrorHelper private Stylesheet? _curStylesheet; // Current stylesheet private Template? _curTemplate; // Current template - internal static QilName nullMode = F.QName(string.Empty); + internal static readonly QilName nullMode = F.QName(string.Empty); // Flags which control attribute versioning - public static int V1Opt = 1; - public static int V1Req = 2; - public static int V2Opt = 4; - public static int V2Req = 8; + public const int V1Opt = 1; + public const int V1Req = 2; + public const int V2Opt = 4; + public const int V2Req = 8; public void Load(Compiler compiler, object stylesheet, XmlResolver? xmlResolver, XmlResolver? origResolver) { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs index d77aef50b0eb5f..20e82a4a9374e4 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/Compiler.cs @@ -91,7 +91,7 @@ internal sealed class Compiler private int _rtfCount; // Used to load Built In templates - public static XmlQualifiedName BuiltInMode = new XmlQualifiedName("*", string.Empty); + public static readonly XmlQualifiedName BuiltInMode = new XmlQualifiedName("*", string.Empty); internal KeywordsTable Atoms { diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs index e23f7c4498501d..7b40f06718a35a 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Xsl/XsltOld/VariableAction.cs @@ -17,7 +17,7 @@ internal enum VariableType internal class VariableAction : ContainerAction, IXsltContextVariable { - public static object BeingComputedMark = new object(); + public static readonly object BeingComputedMark = new object(); private const int ValueCalculated = 2; protected XmlQualifiedName? name; diff --git a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.Heaps.cs b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.Heaps.cs index 21e47c8b22c1c6..fe8b6af07ee138 100644 --- a/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.Heaps.cs +++ b/src/libraries/System.Reflection.Metadata/src/System/Reflection/Metadata/Ecma335/MetadataBuilder.Heaps.cs @@ -579,7 +579,7 @@ private static ImmutableArray SerializeStringHeap( /// private sealed class SuffixSort : IComparer> { - internal static SuffixSort Instance = new SuffixSort(); + internal static readonly SuffixSort Instance = new SuffixSort(); public int Compare(KeyValuePair xPair, KeyValuePair yPair) { 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 a78cf3a4ee560d..d9d592c7d578ec 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 @@ -22,11 +22,11 @@ public sealed class CmsSigner public X509Certificate2? Certificate { get; set; } public AsymmetricAlgorithm? PrivateKey { get; set; } - public X509Certificate2Collection Certificates { get; private set; } = new X509Certificate2Collection(); + public X509Certificate2Collection Certificates { get; } = new X509Certificate2Collection(); public Oid DigestAlgorithm { get; set; } public X509IncludeOption IncludeOption { get; set; } - public CryptographicAttributeObjectCollection SignedAttributes { get; private set; } = new CryptographicAttributeObjectCollection(); - public CryptographicAttributeObjectCollection UnsignedAttributes { get; private set; } = new CryptographicAttributeObjectCollection(); + public CryptographicAttributeObjectCollection SignedAttributes { get; } = new CryptographicAttributeObjectCollection(); + public CryptographicAttributeObjectCollection UnsignedAttributes { get; } = new CryptographicAttributeObjectCollection(); /// /// Gets or sets the RSA signature padding to use. diff --git a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXml.cs b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXml.cs index adc6af7f077e0e..98a5c73ea6e4e2 100644 --- a/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXml.cs +++ b/src/libraries/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/CanonicalXml.cs @@ -12,11 +12,6 @@ internal sealed class CanonicalXml private readonly CanonicalXmlDocument _c14nDoc; private readonly C14NAncestralNamespaceContextManager _ancMgr; - // private static string defaultXPathWithoutComments = "(//. | //@* | //namespace::*)[not(self::comment())]"; - // private static string defaultXPathWithoutComments = "(//. | //@* | //namespace::*)"; - // private static string defaultXPathWithComments = "(//. | //@* | //namespace::*)"; - // private static string defaultXPathWithComments = "(//. | //@* | //namespace::*)"; - internal CanonicalXml(Stream inputStream, bool includeComments, XmlResolver? resolver, string strBaseUri) { if (inputStream is null) diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/BasicSymmetricCipher.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/BasicSymmetricCipher.cs index 1fbcd1620c67a4..6f1c1e1b6317ea 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/BasicSymmetricCipher.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/BasicSymmetricCipher.cs @@ -31,8 +31,8 @@ protected BasicSymmetricCipher(byte[]? iv, int blockSizeInBytes, int paddingSize public abstract int TransformFinal(ReadOnlySpan input, Span output); - public int BlockSizeInBytes { get; private set; } - public int PaddingSizeInBytes { get; private set; } + public int BlockSizeInBytes { get; } + public int PaddingSizeInBytes { get; } public void Dispose() { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationParameters.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationParameters.cs index ad742335f7ae66..b8b8b3d198df94 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationParameters.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngKeyCreationParameters.cs @@ -36,7 +36,7 @@ public CngKeyCreationParameters() /// /// Extra parameter values to set before the key is finalized /// - public CngPropertyCollection Parameters { get; private set; } + public CngPropertyCollection Parameters { get; } /// /// Window handle to use as the parent for the dialog shown when the key is created diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngProperty.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngProperty.cs index 45fe97ab41e57c..179054ad97967e 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngProperty.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngProperty.cs @@ -52,7 +52,7 @@ internal CngProperty(string name, ReadOnlySpan value, CngPropertyOptions o /// /// Options used to set / get the property /// - public CngPropertyOptions Options { get; private set; } + public CngPropertyOptions Options { get; } public override bool Equals([NotNullWhen(true)] object? obj) { diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngUIPolicy.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngUIPolicy.cs index b784e4217dd8b2..c32b049a257f69 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngUIPolicy.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CngUIPolicy.cs @@ -43,27 +43,27 @@ public CngUIPolicy(CngUIProtectionLevels protectionLevel, string? friendlyName, /// /// Level of UI protection to apply to the key /// - public CngUIProtectionLevels ProtectionLevel { get; private set; } + public CngUIProtectionLevels ProtectionLevel { get; } /// /// Friendly name to describe the key with in the dialog box that appears when the key is accessed, /// null for default name /// - public string? FriendlyName { get; private set; } + public string? FriendlyName { get; } /// /// Description text displayed in the dialog box when the key is accessed, null for the default text /// - public string? Description { get; private set; } + public string? Description { get; } /// /// Description of how the key will be used /// - public string? UseContext { get; private set; } + public string? UseContext { get; } /// /// Title of the dialog box displayed when a newly created key is finalized, null for the default title /// - public string? CreationTitle { get; private set; } + public string? CreationTitle { get; } } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/KeySizes.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/KeySizes.cs index 167fbbc1853eb2..9189c896e2abb4 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/KeySizes.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/KeySizes.cs @@ -17,8 +17,8 @@ public KeySizes(int minSize, int maxSize, int skipSize) SkipSize = skipSize; } - public int MinSize { get; private set; } - public int MaxSize { get; private set; } - public int SkipSize { get; private set; } + public int MinSize { get; } + public int MaxSize { get; } + public int SkipSize { get; } } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/UniversalCryptoTransform.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/UniversalCryptoTransform.cs index 865b6a54e8617f..824636e4e9f6ef 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/UniversalCryptoTransform.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/UniversalCryptoTransform.cs @@ -121,7 +121,7 @@ protected int UncheckedTransformBlock(byte[] inputBuffer, int inputOffset, int i protected abstract byte[] UncheckedTransformFinalBlock(byte[] inputBuffer, int inputOffset, int inputCount); protected abstract int UncheckedTransformFinalBlock(ReadOnlySpan inputBuffer, Span outputBuffer); - protected PaddingMode PaddingMode { get; private set; } - protected BasicSymmetricCipher BasicSymmetricCipher { get; private set; } + protected PaddingMode PaddingMode { get; } + protected BasicSymmetricCipher BasicSymmetricCipher { get; } } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/AppleCertificatePal.Pkcs12.iOS.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/AppleCertificatePal.Pkcs12.iOS.cs index baa791d59f34ed..1de7e8ce9bee72 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/AppleCertificatePal.Pkcs12.iOS.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/AppleCertificatePal.Pkcs12.iOS.cs @@ -7,7 +7,7 @@ namespace System.Security.Cryptography.X509Certificates { internal sealed partial class AppleCertificatePal : ICertificatePal { - private static SafePasswordHandle s_passwordExportHandle = new SafePasswordHandle("DotnetExportPassphrase", passwordProvided: true); + private static readonly SafePasswordHandle s_passwordExportHandle = new SafePasswordHandle("DotnetExportPassphrase", passwordProvided: true); private static AppleCertificatePal ImportPkcs12( ReadOnlySpan rawData, diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/PublicKey.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/PublicKey.cs index d70378ef97b216..589e548fc85e02 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/PublicKey.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/PublicKey.cs @@ -68,9 +68,9 @@ public PublicKey(AsymmetricAlgorithm key) // will start returning non Rsa / Dsa types. } - public AsnEncodedData EncodedKeyValue { get; private set; } + public AsnEncodedData EncodedKeyValue { get; } - public AsnEncodedData EncodedParameters { get; private set; } + public AsnEncodedData EncodedParameters { get; } [Obsolete(Obsoletions.PublicKeyPropertyMessage, DiagnosticId = Obsoletions.PublicKeyPropertyDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] public AsymmetricAlgorithm Key diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElement.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElement.cs index ec247c9d98c5cd..9f926d75f2b04a 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElement.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509ChainElement.cs @@ -20,11 +20,11 @@ internal X509ChainElement(X509Certificate2 certificate, X509ChainStatus[] chainE Information = information; } - public X509Certificate2 Certificate { get; private set; } + public X509Certificate2 Certificate { get; } // For compat purposes, ChainElementStatus does *not* give each caller a private copy of the array. - public X509ChainStatus[] ChainElementStatus { get; private set; } + public X509ChainStatus[] ChainElementStatus { get; } - public string Information { get; private set; } + public string Information { get; } } } diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Store.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Store.cs index 07e68341d2c2e7..b68ea52a80ea84 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Store.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Store.cs @@ -97,9 +97,9 @@ public IntPtr StoreHandle } } - public StoreLocation Location { get; private set; } + public StoreLocation Location { get; } - public string? Name { get; private set; } + public string? Name { get; } public void Open(OpenFlags flags) diff --git a/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs b/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs index 84e13bd45dc9b2..e5b1f021d1c734 100644 --- a/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs +++ b/src/libraries/System.Security.Permissions/src/System/Xaml/Permissions/XamlLoadPermission.cs @@ -23,7 +23,7 @@ public XamlLoadPermission(IEnumerable allowedAccess) { } [ComVisible(false)] public override int GetHashCode() { return base.GetHashCode(); } [SupportedOSPlatform("windows")] - public IList AllowedAccess { get; private set; } = new ReadOnlyCollection(Array.Empty()); + public IList AllowedAccess { get; } = new ReadOnlyCollection(Array.Empty()); public override IPermission Copy() { return new XamlLoadPermission(PermissionState.Unrestricted); } public override void FromXml(SecurityElement elem) { } public bool Includes(XamlAccessLevel requestedAccess) { return true; } diff --git a/src/libraries/System.Speech/src/Internal/AlphabetConverter.cs b/src/libraries/System.Speech/src/Internal/AlphabetConverter.cs index 754b0f2e1e4152..ccba4dd0df9669 100644 --- a/src/libraries/System.Speech/src/Internal/AlphabetConverter.cs +++ b/src/libraries/System.Speech/src/Internal/AlphabetConverter.cs @@ -216,13 +216,13 @@ private PhoneMapData CreateMap(string resourceName) private int _currentLangId; private PhoneMapData _phoneMap; - private static int[] s_langIds = new int[] { 0x804, 0x404, 0x407, 0x409, 0x40A, 0x40C, 0x411 }; - private static string[] s_resourceNames = + private static readonly int[] s_langIds = new int[] { 0x804, 0x404, 0x407, 0x409, 0x40A, 0x40C, 0x411 }; + private static readonly string[] s_resourceNames = new string[] { "upstable_chs.upsmap", "upstable_cht.upsmap", "upstable_deu.upsmap", "upstable_enu.upsmap", "upstable_esp.upsmap", "upstable_fra.upsmap", "upstable_jpn.upsmap", }; - private static PhoneMapData[] s_phoneMaps = new PhoneMapData[7]; - private static object s_staticLock = new(); + private static readonly PhoneMapData[] s_phoneMaps = new PhoneMapData[7]; + private static readonly object s_staticLock = new(); #endregion diff --git a/src/libraries/System.Speech/src/Internal/SrgsCompiler/CFGGrammar.cs b/src/libraries/System.Speech/src/Internal/SrgsCompiler/CFGGrammar.cs index 1430c159527010..6fece55f676b62 100644 --- a/src/libraries/System.Speech/src/Internal/SrgsCompiler/CFGGrammar.cs +++ b/src/libraries/System.Speech/src/Internal/SrgsCompiler/CFGGrammar.cs @@ -530,7 +530,7 @@ internal static uint NextHandle #region Internal Fields - internal static Guid _SPGDF_ContextFree = new(0x4ddc926d, 0x6ce7, 0x4dc0, 0x99, 0xa7, 0xaf, 0x9e, 0x6b, 0x6a, 0x4e, 0x91); + internal static readonly Guid _SPGDF_ContextFree = new(0x4ddc926d, 0x6ce7, 0x4dc0, 0x99, 0xa7, 0xaf, 0x9e, 0x6b, 0x6a, 0x4e, 0x91); // internal const int INFINITE = unchecked((int)0xffffffff); diff --git a/src/libraries/System.Speech/src/Recognition/DictationGrammar.cs b/src/libraries/System.Speech/src/Recognition/DictationGrammar.cs index 758da033e35356..e14510e5bc1d38 100644 --- a/src/libraries/System.Speech/src/Recognition/DictationGrammar.cs +++ b/src/libraries/System.Speech/src/Recognition/DictationGrammar.cs @@ -50,7 +50,7 @@ public void SetDictationContext(string precedingText, string subsequentText) #region Private Fields - private static Uri s_defaultDictationUri = new("grammar:dictation"); + private static readonly Uri s_defaultDictationUri = new("grammar:dictation"); #endregion } diff --git a/src/libraries/System.Speech/src/Recognition/Grammar.cs b/src/libraries/System.Speech/src/Recognition/Grammar.cs index 95d8a33be3ff3b..b4737ed283a411 100644 --- a/src/libraries/System.Speech/src/Recognition/Grammar.cs +++ b/src/libraries/System.Speech/src/Recognition/Grammar.cs @@ -1121,7 +1121,7 @@ private static string CheckRuleName(Stream stream, string rulename, bool isImpor private InternalGrammarData _internalData; private string _grammarName = string.Empty; private Collection _ruleRefs; - private static ResourceLoader s_resourceLoader = new(); + private static readonly ResourceLoader s_resourceLoader = new(); #if DEBUG private bool _loaded; diff --git a/src/libraries/System.Speech/src/SR.cs b/src/libraries/System.Speech/src/SR.cs index 540a8d57c29291..b41f29dbe670a7 100644 --- a/src/libraries/System.Speech/src/SR.cs +++ b/src/libraries/System.Speech/src/SR.cs @@ -8,7 +8,7 @@ namespace System.Speech { internal static class SR { - private static ResourceManager s_resourceManager = new("ExceptionStringTable", typeof(SR).Assembly); + private static readonly ResourceManager s_resourceManager = new("ExceptionStringTable", typeof(SR).Assembly); internal static string Get(SRID id, params object[] args) { diff --git a/src/libraries/System.Speech/src/Synthesis/Prompt.cs b/src/libraries/System.Speech/src/Synthesis/Prompt.cs index e771fca8d9b724..4c281cb8dbbe0a 100644 --- a/src/libraries/System.Speech/src/Synthesis/Prompt.cs +++ b/src/libraries/System.Speech/src/Synthesis/Prompt.cs @@ -148,7 +148,7 @@ internal object Synthesizer /// private object _synthesizer; - private static ResourceLoader s_resourceLoader = new(); + private static readonly ResourceLoader s_resourceLoader = new(); #endregion } diff --git a/src/libraries/System.Speech/src/Synthesis/PromptBuilder.cs b/src/libraries/System.Speech/src/Synthesis/PromptBuilder.cs index 2b4c4341405514..5cabd2f19490f9 100644 --- a/src/libraries/System.Speech/src/Synthesis/PromptBuilder.cs +++ b/src/libraries/System.Speech/src/Synthesis/PromptBuilder.cs @@ -991,7 +991,7 @@ private void AppendSsmlInternal(XmlReader ssmlFile) private List _elements = new(); // Resource loader for the prompt builder - private static ResourceLoader s_resourceLoader = new(); + private static readonly ResourceLoader s_resourceLoader = new(); private const string _xmlnsDefault = @"http://www.w3.org/2001/10/synthesis"; diff --git a/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRange.cs b/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRange.cs index 2c199790d2b9ac..71bc46690bf860 100644 --- a/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRange.cs +++ b/src/libraries/System.Text.Encodings.Web/src/System/Text/Unicode/UnicodeRange.cs @@ -38,12 +38,12 @@ public UnicodeRange(int firstCodePoint, int length) /// /// The first code point in this range. /// - public int FirstCodePoint { get; private set; } + public int FirstCodePoint { get; } /// /// The number of code points in this range. /// - public int Length { get; private set; } + public int Length { get; } /// /// Creates a new from a span of characters. diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonConverterAttribute.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonConverterAttribute.cs index e456a009178d92..6a3ead5847d583 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonConverterAttribute.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Attributes/JsonConverterAttribute.cs @@ -36,7 +36,7 @@ protected JsonConverterAttribute() { } /// The type of the converter to create, or null if should be used to obtain the converter. /// [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] - public Type? ConverterType { get; private set; } + public Type? ConverterType { get; } /// /// If overridden and is null, allows a custom attribute to create the converter in order to pass additional state. diff --git a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs index 408fe376752c9a..64f46a74635bc4 100644 --- a/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs +++ b/src/libraries/System.Threading/src/System/Threading/CDSsyncETWBCLProvider.cs @@ -31,7 +31,7 @@ internal sealed class CdsSyncEtwBCLProvider : EventSource /// Defines the singleton instance for the CDS Sync ETW provider. /// The CDS Sync Event provider GUID is {EC631D38-466B-4290-9306-834971BA0217}. /// - public static CdsSyncEtwBCLProvider Log = new CdsSyncEtwBCLProvider(); + public static readonly CdsSyncEtwBCLProvider Log = new CdsSyncEtwBCLProvider(); /// Prevent external instantiation. All logging should go through the Log instance. private CdsSyncEtwBCLProvider() { } diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/DtcProxyShim/OletxHelper.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/DtcProxyShim/OletxHelper.cs index ce0bb80e059971..d62e679228989b 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/DtcProxyShim/OletxHelper.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/DtcProxyShim/OletxHelper.cs @@ -11,24 +11,24 @@ internal static class OletxHelper private const int RetryInterval = 50; // in milliseconds private const int MaxRetryCount = 100; - internal static int S_OK = 0; - internal static int E_FAIL = -2147467259; // 0x80004005, -2147467259 - internal static int XACT_S_READONLY = 315394; // 0x0004D002, 315394 - internal static int XACT_S_SINGLEPHASE = 315401; // 0x0004D009, 315401 - internal static int XACT_E_ABORTED = -2147168231; // 0x8004D019, -2147168231 - internal static int XACT_E_NOTRANSACTION = -2147168242; // 0x8004D00E, -2147168242 - internal static int XACT_E_CONNECTION_DOWN = -2147168228; // 0x8004D01C, -2147168228 - internal static int XACT_E_REENLISTTIMEOUT = -2147168226; // 0x8004D01E, -2147168226 - internal static int XACT_E_RECOVERYALREADYDONE = -2147167996; // 0x8004D104, -2147167996 - internal static int XACT_E_TMNOTAVAILABLE = -2147168229; // 0x8004d01b, -2147168229 - internal static int XACT_E_INDOUBT = -2147168234; // 0x8004d016, - internal static int XACT_E_ALREADYINPROGRESS = -2147168232; // x08004d018, - internal static int XACT_E_TOOMANY_ENLISTMENTS = -2147167999; // 0x8004d101 - internal static int XACT_E_PROTOCOL = -2147167995; // 8004d105 - internal static int XACT_E_FIRST = -2147168256; // 0x8004D000 - internal static int XACT_E_LAST = -2147168215; // 0x8004D029 - internal static int XACT_E_NOTSUPPORTED = -2147168241; // 0x8004D00F - internal static int XACT_E_NETWORK_TX_DISABLED = -2147168220; // 0x8004D024 + internal const int S_OK = 0; + internal const int E_FAIL = -2147467259; // 0x80004005, -2147467259 + internal const int XACT_S_READONLY = 315394; // 0x0004D002, 315394 + internal const int XACT_S_SINGLEPHASE = 315401; // 0x0004D009, 315401 + internal const int XACT_E_ABORTED = -2147168231; // 0x8004D019, -2147168231 + internal const int XACT_E_NOTRANSACTION = -2147168242; // 0x8004D00E, -2147168242 + internal const int XACT_E_CONNECTION_DOWN = -2147168228; // 0x8004D01C, -2147168228 + internal const int XACT_E_REENLISTTIMEOUT = -2147168226; // 0x8004D01E, -2147168226 + internal const int XACT_E_RECOVERYALREADYDONE = -2147167996; // 0x8004D104, -2147167996 + internal const int XACT_E_TMNOTAVAILABLE = -2147168229; // 0x8004d01b, -2147168229 + internal const int XACT_E_INDOUBT = -2147168234; // 0x8004d016, + internal const int XACT_E_ALREADYINPROGRESS = -2147168232; // x08004d018, + internal const int XACT_E_TOOMANY_ENLISTMENTS = -2147167999; // 0x8004d101 + internal const int XACT_E_PROTOCOL = -2147167995; // 8004d105 + internal const int XACT_E_FIRST = -2147168256; // 0x8004D000 + internal const int XACT_E_LAST = -2147168215; // 0x8004D029 + internal const int XACT_E_NOTSUPPORTED = -2147168241; // 0x8004D00F + internal const int XACT_E_NETWORK_TX_DISABLED = -2147168220; // 0x8004D024 internal static void Retry(Action action) { diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxEnlistment.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxEnlistment.cs index 23e72382d2dca2..75cc0607be9eef 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxEnlistment.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxEnlistment.cs @@ -846,7 +846,6 @@ public EnlistmentTraceIdentifier EnlistmentTraceId public void Prepared() { - int hrResult = OletxHelper.S_OK; EnlistmentShim? localEnlistmentShim = null; Phase0EnlistmentShim? localPhase0Shim = null; bool localFabricateRollback = false; diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxResourceManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxResourceManager.cs index c2cb9bf5049815..c38d9751a2224d 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxResourceManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxResourceManager.cs @@ -15,7 +15,7 @@ internal sealed class OletxResourceManager internal ResourceManagerShim? resourceManagerShim; internal Hashtable EnlistmentHashtable; - internal static Hashtable VolatileEnlistmentHashtable = new Hashtable(); + internal static readonly Hashtable VolatileEnlistmentHashtable = new Hashtable(); internal OletxTransactionManager OletxTransactionManager; // reenlistList is a simple ArrayList of OletxEnlistment objects that are either in the diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxTransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxTransactionManager.cs index e32c991e4e13b9..a68c0608e0c94a 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxTransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/Oletx/OletxTransactionManager.cs @@ -30,7 +30,7 @@ internal sealed class OletxTransactionManager private readonly DtcTransactionManager _dtcTransactionManager; internal OletxInternalResourceManager InternalResourceManager; - internal static DtcProxyShimFactory ProxyShimFactory = null!; // Late initialization + internal static DtcProxyShimFactory ProxyShimFactory = null!; // Lazy initialization // Double-checked locking pattern requires volatile for read/write synchronization internal static volatile EventWaitHandle? _shimWaitHandle; diff --git a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs index 8fed4d70cb8f97..e88772583be0f2 100644 --- a/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs +++ b/src/libraries/System.Transactions.Local/src/System/Transactions/TransactionManager.cs @@ -432,7 +432,7 @@ public static bool ImplicitDistributedTransactions } internal static bool? s_implicitDistributedTransactions; - internal static object s_implicitDistributedTransactionsLock = new(); + internal static readonly object s_implicitDistributedTransactionsLock = new(); #else public static bool ImplicitDistributedTransactions { diff --git a/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs b/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs index 3c4d510fd3a17b..8d4e171f68f2ab 100644 --- a/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs +++ b/src/libraries/System.Windows.Extensions/src/System/Xaml/Permissions/XamlAccessLevel.cs @@ -43,8 +43,8 @@ public AssemblyName AssemblyAccessToAssemblyName get { return new AssemblyName(AssemblyNameString); } } - public string? PrivateAccessToTypeName { get; private set; } + public string? PrivateAccessToTypeName { get; } - internal string AssemblyNameString { get; private set; } + internal string AssemblyNameString { get; } } } diff --git a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs index a6c80c89ac8d82..dfd0f368561bdc 100644 --- a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs @@ -358,7 +358,7 @@ internal sealed class MethodInfo public int KickOffMethod { get; } internal bool IsCompilerGenerated { get; } private AsyncScopeDebugInformation[] _asyncScopes { get; set; } - private static SignatureTypeProvider _signatureTypeProvider = new(); + private static readonly SignatureTypeProvider _signatureTypeProvider = new(); public MethodInfo(AssemblyInfo assembly, string methodName, int methodToken, TypeInfo type, MethodAttributes attrs) {