From b9fb45deeee994a94d433e3ea83fbddcbf242a04 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 5 Aug 2024 23:09:29 -0700 Subject: [PATCH] Add some more missing 'readonly' modifiers (#1707) --- 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 42713d01..b45bfe67 100644 --- a/src/WinRT.Runtime/ComWrappersSupport.net5.cs +++ b/src/WinRT.Runtime/ComWrappersSupport.net5.cs @@ -41,7 +41,7 @@ namespace WinRT 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 f973d850..c2e55f26 100644 --- a/src/WinRT.Runtime/Marshalers.cs +++ b/src/WinRT.Runtime/Marshalers.cs @@ -79,8 +79,8 @@ namespace WinRT 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 @@ namespace WinRT 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 146a1faf..412f8a4e 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 @@ namespace WinRT 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 66388b2b..d9f9372c 100644 --- a/src/WinRT.Runtime/Projections/Bindable.net5.cs +++ b/src/WinRT.Runtime/Projections/Bindable.net5.cs @@ -873,7 +873,7 @@ namespace ABI.System.Collections 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;