From 1f673e992ce614f203a808495114997af83cc8a6 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 5 Aug 2024 19:40:34 -0700 Subject: [PATCH] Add some more missing 'readonly' modifiers --- src/WinRT.Runtime/ComWrappersSupport.net5.cs | 2 +- src/WinRT.Runtime/Marshalers.cs | 6 +++--- src/WinRT.Runtime/MonoSupport.cs | 4 ++-- src/WinRT.Runtime/Projections/Bindable.net5.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/WinRT.Runtime/ComWrappersSupport.net5.cs b/src/WinRT.Runtime/ComWrappersSupport.net5.cs index 42713d015..b45bfe67d 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -41,7 +41,7 @@ private static DefaultComWrappers DefaultComWrappersInstance internal static Type CreateRCWType; private static ComWrappers _comWrappers; - private static object _comWrappersLock = new object(); + private static readonly object _comWrappersLock = new object(); private static ComWrappers ComWrappers { get diff --git a/src/WinRT.Runtime/Marshalers.cs b/src/WinRT.Runtime/Marshalers.cs index f973d8501..c2e55f26e 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -79,8 +79,8 @@ internal struct HSTRING_HEADER public ref struct Pinnable { - private HSTRING_HEADER _header; - private string _value; + private readonly HSTRING_HEADER _header; + private readonly string _value; #if DEBUG private bool _pinned; #endif @@ -116,7 +116,7 @@ public unsafe IntPtr GetAbi() Marshal.ThrowExceptionForHR(Platform.WindowsCreateStringReference( (ushort*)Unsafe.AsPointer(ref Unsafe.AsRef(in GetPinnableReference())), _value.Length, - (IntPtr*)Unsafe.AsPointer(ref _header), + (IntPtr*)Unsafe.AsPointer(ref Unsafe.AsRef(in _header)), &hstring)); return hstring; } diff --git a/src/WinRT.Runtime/MonoSupport.cs b/src/WinRT.Runtime/MonoSupport.cs index 146a1fafb..412f8a4eb 100644 --- a/src/WinRT.Runtime/MonoSupport.cs +++ b/src/WinRT.Runtime/MonoSupport.cs @@ -13,7 +13,7 @@ namespace WinRT { internal static class Mono { - static unsafe Lazy _usingMono = new Lazy(() => + static readonly unsafe Lazy _usingMono = new Lazy(() => { IntPtr modulePtr = Platform.LoadLibraryExW("mono-2.0-bdwgc.dll", IntPtr.Zero, 0); if (modulePtr == IntPtr.Zero) return false; @@ -75,7 +75,7 @@ struct MonoInternalThread_x64 public sealed class ThreadContext : IDisposable { - static Lazy> _foreignThreads = new Lazy>(); + static readonly Lazy> _foreignThreads = new Lazy>(); readonly IntPtr _threadPtr = IntPtr.Zero; diff --git a/src/WinRT.Runtime/Projections/Bindable.net5.cs b/src/WinRT.Runtime/Projections/Bindable.net5.cs index 66388b2bc..d9f9372c9 100644 --- a/src/WinRT.Runtime/Projections/Bindable.net5.cs +++ b/src/WinRT.Runtime/Projections/Bindable.net5.cs @@ -873,7 +873,7 @@ public IEnumerator GetEnumerator() public sealed class ToAbiHelper : IBindableVector #pragma warning restore CA2257 { - private global::System.Collections.IList _list; + private readonly global::System.Collections.IList _list; public ToAbiHelper(global::System.Collections.IList list) => _list = list;