Skip to content

[StyleCleanUp] Add readonly modifiers in WindowsBase #10731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
Expand Down Expand Up @@ -184,7 +184,7 @@ protected void DoCopyOnWriteCheck()
}
}

private object _syncRoot;
private readonly object _syncRoot;
private ArrayList _LiveList = new ArrayList();
private ArrayList _readonlyWrapper;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -257,11 +257,11 @@ public void Dispose()

#region Private Fields

private ExecutionContext _context;
private readonly ExecutionContext _context;
private CultureAndContextManager _cultureAndContext;

// static delegate to prevent repeated implicit allocations during Run
private static ContextCallback CallbackWrapperDelegate;
private static readonly ContextCallback CallbackWrapperDelegate;

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ private void CheckDisposed()
/// Synchronize access to IsolatedStorage methods that can step on each-other
/// </summary>
/// <remarks>See PS 1468964 for details.</remarks>
private static Object _isoStoreSyncObject = new Object();
private static Object _isolatedStorageFileLock = new Object();
private static readonly Object _isoStoreSyncObject = new Object();
private static readonly Object _isolatedStorageFileLock = new Object();
private static ReliableIsolatedStorageFileFolder _defaultFile;
private const string XmlNamespace = "xmlns";
private const string _encodingAttribute = "encoding";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Description:
Expand Down Expand Up @@ -184,7 +184,7 @@ private void CallWithNonPumpingWait(Action callback)

#region Private Fields

private ReaderWriterLockSlim _rwLock;
private readonly ReaderWriterLockSlim _rwLock;
private AutoReaderRelease _arr;
private AutoWriterRelease _awr;
private AutoReaderReleaseClass _arrc;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void Dispose()
_wrapper.ReleaseWriterLock();
}

private ReaderWriterLockWrapper _wrapper;
private readonly ReaderWriterLockWrapper _wrapper;
}

private struct AutoReaderRelease : IDisposable
Expand All @@ -232,7 +232,7 @@ public void Dispose()
_wrapper.ReleaseReaderLock();
}

private ReaderWriterLockWrapper _wrapper;
private readonly ReaderWriterLockWrapper _wrapper;
}

private class AutoWriterReleaseClass : IDisposable
Expand All @@ -247,7 +247,7 @@ public void Dispose()
_wrapper.ReleaseWriterLock2();
}

private ReaderWriterLockWrapper _wrapper;
private readonly ReaderWriterLockWrapper _wrapper;
}

private class AutoReaderReleaseClass : IDisposable
Expand All @@ -262,7 +262,7 @@ public void Dispose()
_wrapper.ReleaseReaderLock2();
}

private ReaderWriterLockWrapper _wrapper;
private readonly ReaderWriterLockWrapper _wrapper;
}

// This SynchronizationContext waits without pumping messages, like
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ internal static Point ClientToScreen(UIElement relativeTo, Point point)
// We use a callback on GC to purge out collected assemblies, so we don't grow indefinitely.
//
private static Dictionary<object, AssemblyName> _assemblies; // get key via GetKeyForAssembly
private static object syncObject = new object();
private static readonly object syncObject = new object();
private static bool _isGCCallbackPending;

// PERF: Cache delegate for CleanupCollectedAssemblies to avoid allocating it each time.
Expand Down Expand Up @@ -312,8 +312,8 @@ public override bool Equals(object o)
// will kick off a thread-pool job that you can use to purge a weakref cache.
internal class GCNotificationToken
{
private WaitCallback callback;
private object state;
private readonly WaitCallback callback;
private readonly object state;

private GCNotificationToken(WaitCallback callback, object state)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//
Expand Down Expand Up @@ -359,7 +359,7 @@ private enum InstallState
// Writes are not thread safe, but we don't mind the neglible perf hit
// of potentially writing it twice.
private static InstallState s_servicesInstalled = InstallState.Unknown;
private static object s_servicesInstalledLock = new object();
private static readonly object s_servicesInstalledLock = new object();

#endregion Private Fields
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void Reset()
}

private int _i;
private ArrayList _List;
private readonly ArrayList _List;
private object _StrongReference;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.DotNet.Wpf/src/Shared/MS/Utility/FrugalList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public virtual FrugalListBase<T> Finish()
protected FrugalListBase<T> _store;
protected int _validItemCount;
protected int _previousEnd;
private int _newCount;
private readonly int _newCount;
}

#endregion Compacter
Expand Down Expand Up @@ -1612,9 +1612,9 @@ public override FrugalListBase<T> Finish()
return _targetStore;
}

private ArrayItemList<T> _targetStore;
private T[] _sourceArray;
private T[] _targetArray;
private readonly ArrayItemList<T> _targetStore;
private readonly T[] _sourceArray;
private readonly T[] _targetArray;
}

#endregion Compacter
Expand Down Expand Up @@ -1951,8 +1951,8 @@ public void Finish()
}
}

private FrugalObjectList<T> _list;
private FrugalListBase<T>.Compacter _storeCompacter;
private readonly FrugalObjectList<T> _list;
private readonly FrugalListBase<T>.Compacter _storeCompacter;
}
#endregion Compacter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ public override int Count
// Hashtable will return null from its indexer if the key is not
// found OR if the value is null. To distinguish between these
// two cases we insert NullValue instead of null.
private static object NullValue = new object();
private static readonly object NullValue = new object();

internal Dictionary<int, object> _entries;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
Expand All @@ -11,7 +11,7 @@ internal static class HandleCollector
private static HandleType[] handleTypes;
private static int handleTypeCount = 0;

private static Object handleMutex = new Object();
private static readonly Object handleMutex = new Object();

/// <devdoc>
/// Adds the given handle to the handle collector. This keeps the
Expand Down Expand Up @@ -78,7 +78,7 @@ private class HandleType
{
internal readonly string name;

private int initialThreshHold;
private readonly int initialThreshHold;
private int threshHold;
private int handleCount;
private readonly int deltaPercent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;
Expand Down Expand Up @@ -590,9 +590,9 @@ private enum Bond
/// By instantiating this delegate as a static variable we ensure that
/// it will remain alive long enough to process messages.
/// </summary>
private static NativeMethods.WndProc DefWndProcStub = new NativeMethods.WndProc(DefWndProcWrapper);
private static readonly NativeMethods.WndProc DefWndProcStub = new NativeMethods.WndProc(DefWndProcWrapper);

private static IntPtr DefWndProc;
private static readonly IntPtr DefWndProc;

private IntPtr _hwndAttached;
private HandleRef _hwndHandleRef;
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/HwndWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,15 +358,15 @@ public DestroyWindowArgs(IntPtr handle, ushort classAtom)
private IntPtr _handle;
private UInt16 _classAtom;
private WeakReferenceList _hooks;
private int _ownerThreadID;
private readonly int _ownerThreadID;

private HwndWrapperHook _wndProc;
private readonly HwndWrapperHook _wndProc;
private bool _isDisposed;

private bool _isInCreateWindow = false; // debugging variable (temporary)
private readonly bool _isInCreateWindow = false; // debugging variable (temporary)

// Message to cause a dispose. We need this to ensure we destroy the window on the right thread.
private static WindowMessage s_msgGCMemory;
private static readonly WindowMessage s_msgGCMemory;
} // class RawWindow
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

//#define LOGGING
Expand Down Expand Up @@ -238,7 +238,7 @@ private static void Log(string msg)
private static IntPtr _cachedDefWindowProcA = IntPtr.Zero;
private static IntPtr _cachedDefWindowProcW = IntPtr.Zero;

private static Hashtable _hwndList = new Hashtable(10);
private static readonly Hashtable _hwndList = new Hashtable(10);
private static bool _exiting = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ internal class ICONINFO

internal abstract class WpfSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
private int _collectorId;
private readonly int _collectorId;

protected WpfSafeHandle(bool ownsHandle, int collectorId) : base(ownsHandle)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -476,7 +476,7 @@ private static Assembly LoadAssemblyHelper(string assemblyGivenName, string asse
return retassem;
}

private static Hashtable _loadedAssembliesHash = new Hashtable(8);
private static readonly Hashtable _loadedAssembliesHash = new Hashtable(8);
#else
// returns true is sourceAssembly declares LocalAssemblyName as a friend
internal static bool IsFriendAssembly(Assembly sourceAssembly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace System.Windows.Markup
/// </summary>
internal static class TypeConverterHelper
{
private static CultureInfo invariantEnglishUS = CultureInfo.InvariantCulture;
private static readonly CultureInfo invariantEnglishUS = CultureInfo.InvariantCulture;

internal static CultureInfo InvariantEnglishUS
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable
Expand Down Expand Up @@ -1642,14 +1642,14 @@ public NamespaceElementPair(string namespaceName, string itemName)
/// </summary>
private class CompatibilityScope
{
private CompatibilityScope _previous;
private int _depth;
private readonly CompatibilityScope _previous;
private readonly int _depth;
private bool _fallbackSeen;
private bool _inAlternateContent;
private bool _inProcessContent;
private bool _choiceTaken;
private bool _choiceSeen;
private XmlCompatibilityReader _reader;
private readonly XmlCompatibilityReader _reader;
private Dictionary<string, object> _ignorables;
private Dictionary<string, ProcessContentSet> _processContents;
private Dictionary<string, PreserveItemSet> _preserveElements;
Expand Down Expand Up @@ -1948,8 +1948,8 @@ public void Verify()
private class ProcessContentSet
{
private bool _all;
private string _namespaceName;
private XmlCompatibilityReader _reader;
private readonly string _namespaceName;
private readonly XmlCompatibilityReader _reader;
private HashSet<string> _names;

public ProcessContentSet(string namespaceName, XmlCompatibilityReader reader)
Expand Down Expand Up @@ -2003,8 +2003,8 @@ public void Add(string elementName)
private class PreserveItemSet
{
private bool _all;
private string _namespaceName;
private XmlCompatibilityReader _reader;
private readonly string _namespaceName;
private readonly XmlCompatibilityReader _reader;
private Dictionary<string, string> _names;

public PreserveItemSet(string namespaceName, XmlCompatibilityReader reader)
Expand Down Expand Up @@ -2059,12 +2059,12 @@ public void Add(string itemName)
#region Private Fields
private bool _inAttribute; // for Save/Restore ReaderPosition
private string _currentName; // for Save/Restore ReaderPosition
private IsXmlNamespaceSupportedCallback _namespaceCallback;
private readonly IsXmlNamespaceSupportedCallback _namespaceCallback;
private Dictionary<string, object> _knownNamespaces;
private Dictionary<string, string> _namespaceMap = new Dictionary<string, string>();
private Dictionary<string, object> _subsumingNamespaces;
private Dictionary<string, HandleElementCallback> _elementHandler = new Dictionary<string, HandleElementCallback>();
private Dictionary<string, HandleAttributeCallback> _attributeHandler = new Dictionary<string, HandleAttributeCallback>();
private readonly Dictionary<string, string> _namespaceMap = new Dictionary<string, string>();
private readonly Dictionary<string, HandleElementCallback> _elementHandler = new Dictionary<string, HandleElementCallback>();
private readonly Dictionary<string, HandleAttributeCallback> _attributeHandler = new Dictionary<string, HandleAttributeCallback>();
private int _depthOffset; // offset for Depth method, to account for elements that should be ignored by client
private int _ignoredAttributeCount;
private int _attributePosition; // used for ScanForCompatibility / HandleIgnorable
Expand All @@ -2086,7 +2086,7 @@ public void Add(string itemName)
private const string XmlnsDeclaration = "xmlns";
private const string MarkupCompatibilityURI = "http://schemas.openxmlformats.org/markup-compatibility/2006";

private static string[] _predefinedNamespaces = new string[4]
private static readonly string[] _predefinedNamespaces = new string[4]
{
"http://www.w3.org/2000/xmlns/",
"http://www.w3.org/XML/1998/namespace",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ public static Type GetTypeHelper(object value)
private static bool _hasBeenRefreshed = false;

// Delegates to create and remove the TraceSource instance
private GetTraceSourceDelegate _getTraceSourceDelegate;
private ClearTraceSourceDelegate _clearTraceSourceDelegate;
private readonly GetTraceSourceDelegate _getTraceSourceDelegate;
private readonly ClearTraceSourceDelegate _clearTraceSourceDelegate;

// Cache of TraceSource instance; real value resides in PresentationTraceSources.
private TraceSource _traceSource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace MS.Internal
Expand Down Expand Up @@ -41,8 +41,8 @@ public string[] Labels
}
}

private int _id;
private string[] _labels;
private readonly int _id;
private readonly string[] _labels;
}
}

Loading