Skip to content

[StyleCleanUp] Use literals where appropriate (CA1802) #10725

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 0 additions & 3 deletions src/Microsoft.DotNet.Wpf/src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ dotnet_diagnostic.CA5394.severity = suggestion
# CA1725: Parameter names should match base declaration
dotnet_diagnostic.CA1725.severity = suggestion

# CA1802: Use literals where appropriate
dotnet_diagnostic.CA1802.severity = suggestion

# CA1805: Do not initialize unnecessarily
dotnet_diagnostic.CA1805.severity = suggestion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class MatrixStack
#if DEBUG
private const int s_initialSize = 4;
#else
private static readonly int s_initialSize = 40; // sizeof(Matrix) * 40 = 2240 bytes. Must be > 4
private const int s_initialSize = 40; // sizeof(Matrix) * 40 = 2240 bytes. Must be > 4
#endif
private const int s_growFactor = 2;
private const int s_shrinkFactor = s_growFactor + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public override XmlQualifiedName[] GetLocatorPartTypes()
/// is done by the framework and does not need to be repeated. Use this
/// string in markup as a value for SubTreeProcessorIdProperty.
/// </summary>
public static readonly String Id = "FixedPage";
public const String Id = "FixedPage";

#endregion Public Properties

Expand Down Expand Up @@ -334,7 +334,7 @@ internal static ContentLocatorPart CreateLocatorPart(int page)
#region Private Fields

// Name of the value attribute containing the hash
private static readonly String ValueAttributeName = "Value";
private const String ValueAttributeName = "Value";

// Name of the locator part produced by this processor.
private static readonly XmlQualifiedName PageNumberElementName = new XmlQualifiedName("PageNumber", AnnotationXmlConstants.Namespaces.BaseSchemaNamespace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ private static ResourceManagerWrapper GetResourceManagerWrapper(Uri uri, out str

private static readonly Dictionary<string, ResourceManagerWrapper> s_registeredResourceManagers = new(StringComparer.Ordinal);
private static readonly Dictionary<string, ResourceManagerWrapper>.AlternateLookup<ReadOnlySpan<char>> s_registeredResourceManagersLookup = s_registeredResourceManagers.GetAlternateLookup<ReadOnlySpan<char>>();
private static readonly FileShare s_fileShare = FileShare.Read;
private const FileShare s_fileShare = FileShare.Read;

private static ResourceManagerWrapper s_applicationResourceManagerWrapper = null;
private static bool s_assemblyLoadHandlerAttached = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ void LogAllocationRelay(Type type, int count, int bytes)

#endregion Private Methods

private static readonly string AllListenersKey = "<All Listeners>"; // not a legal property name
private static readonly string StaticPropertyChanged = "StaticPropertyChanged";
private const string AllListenersKey = "<All Listeners>"; // not a legal property name
private const string StaticPropertyChanged = "StaticPropertyChanged";

#region TypeRecord

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ internal string BaseName
private string _baseName;
private string _xmlNamespace;

public static readonly string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
public static readonly string FixedMarkupNamespace = "http://schemas.microsoft.com/xps/2005/06";
public const string XamlNamespace = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
public const string FixedMarkupNamespace = "http://schemas.microsoft.com/xps/2005/06";
}

///<summary>Content-location information for an element.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ internal double Start
// ------------------------------------------------------------------
internal TextLineBreak TextLineBreak { get { return _textLineBreak; } }
private TextLineBreak _textLineBreak;
private static readonly uint HasBeenUpdatedMask = 0x40000000;
private static readonly uint LengthMask = 0x3FFFFFFF;
private static readonly uint HasInlineObjectsMask = 0x80000000;

private const uint HasBeenUpdatedMask = 0x40000000;
private const uint LengthMask = 0x3FFFFFFF;
private const uint HasInlineObjectsMask = 0x80000000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,23 +376,23 @@ internal class ErrorStrings
{
internal static string Format(string format, params object[] args) => String.Format(format, args);

internal static readonly string Arg_IndexOutOfRangeException = "Index was outside the bounds of the array.";
internal static readonly string Arg_KeyNotFound = "The given key was not present in the dictionary.";
internal static readonly string Arg_KeyNotFoundWithKey = "The given key '{0}' was not present in the dictionary.";
internal static readonly string Arg_RankMultiDimNotSupported = "Only single dimensional arrays are supported for the requested action.";
internal static readonly string Argument_AddingDuplicate = "An item with the same key has already been added.";
internal static readonly string Argument_AddingDuplicateWithKey = "An item with the same key has already been added. Key: {0}";
internal static readonly string Argument_IndexOutOfArrayBounds = "The specified index is out of bounds of the specified array.";
internal static readonly string Argument_InsufficientSpaceToCopyCollection = "The specified space is not sufficient to copy the elements from this Collection.";
internal static readonly string ArgumentOutOfRange_Index = "Index was out of range. Must be non-negative and less than the size of the collection.";
internal static readonly string ArgumentOutOfRange_IndexLargerThanMaxValue = "This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1).";
internal static readonly string InvalidOperation_CannotRemoveLastFromEmptyCollection = "Cannot remove the last element from an empty collection.";
internal static readonly string InvalidOperation_CollectionBackingDictionaryTooLarge = "The collection backing this Dictionary contains too many elements.";
internal static readonly string InvalidOperation_CollectionBackingListTooLarge = "The collection backing this List contains too many elements.";
internal static readonly string InvalidOperation_EnumEnded = "Enumeration already finished.";
internal static readonly string InvalidOperation_EnumFailedVersion = "Collection was modified; enumeration operation may not execute.";
internal static readonly string InvalidOperation_EnumNotStarted = "Enumeration has not started. Call MoveNext.";
internal static readonly string NotSupported_KeyCollectionSet = "Mutating a key collection derived from a dictionary is not allowed.";
internal static readonly string NotSupported_ValueCollectionSet = "Mutating a value collection derived from a dictionary is not allowed.";
internal const string Arg_IndexOutOfRangeException = "Index was outside the bounds of the array.";
internal const string Arg_KeyNotFound = "The given key was not present in the dictionary.";
internal const string Arg_KeyNotFoundWithKey = "The given key '{0}' was not present in the dictionary.";
internal const string Arg_RankMultiDimNotSupported = "Only single dimensional arrays are supported for the requested action.";
internal const string Argument_AddingDuplicate = "An item with the same key has already been added.";
internal const string Argument_AddingDuplicateWithKey = "An item with the same key has already been added. Key: {0}";
internal const string Argument_IndexOutOfArrayBounds = "The specified index is out of bounds of the specified array.";
internal const string Argument_InsufficientSpaceToCopyCollection = "The specified space is not sufficient to copy the elements from this Collection.";
internal const string ArgumentOutOfRange_Index = "Index was out of range. Must be non-negative and less than the size of the collection.";
internal const string ArgumentOutOfRange_IndexLargerThanMaxValue = "This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1).";
internal const string InvalidOperation_CannotRemoveLastFromEmptyCollection = "Cannot remove the last element from an empty collection.";
internal const string InvalidOperation_CollectionBackingDictionaryTooLarge = "The collection backing this Dictionary contains too many elements.";
internal const string InvalidOperation_CollectionBackingListTooLarge = "The collection backing this List contains too many elements.";
internal const string InvalidOperation_EnumEnded = "Enumeration already finished.";
internal const string InvalidOperation_EnumFailedVersion = "Collection was modified; enumeration operation may not execute.";
internal const string InvalidOperation_EnumNotStarted = "Enumeration has not started. Call MoveNext.";
internal const string NotSupported_KeyCollectionSet = "Mutating a key collection derived from a dictionary is not allowed.";
internal const string NotSupported_ValueCollectionSet = "Mutating a value collection derived from a dictionary is not allowed.";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static bool ShouldUseDedicatedSegmenter(string languageTag)
};


public static readonly string Undetermined = "und";
public const string Undetermined = "und";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal partial class Speller
/// </remarks>
private partial class TextMapOffsetErrorLogger
{
private static readonly string TextMapOffsetError = "TextMapOffsetError";
private const string TextMapOffsetError = "TextMapOffsetError";

private DebugInfo _debugInfo;
public enum CalculationModes : int
Expand All @@ -52,7 +52,7 @@ public enum CalculationModes : int
/// expected for various indices and offsets is -1. Therefore -2 can act as a handy way to
/// represent an "unset" or "uninitialized" value;
/// </summary>
private static readonly int UnsetValue = -2;
private const int UnsetValue = -2;

public TextMapOffsetErrorLogger(LogicalDirection direction, TextMap textMap, ArrayList segments, int positionInSegmentList, int leftWordBreak, int rightWordBreak, int contentOffset)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal class SpellerCOMActionTraceLogger : IDisposable
/// <summary>
/// The name of the event that will be logged by this class
/// </summary>
private static readonly string SpellerCOMLatencyMeasurement = nameof(SpellerCOMLatencyMeasurement);
private const string SpellerCOMLatencyMeasurement = nameof(SpellerCOMLatencyMeasurement);

/// <summary>
/// Various actions that we track in this logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public bool IsKeyTypeExtension
private bool _isStatic;
private bool _isType;

private static readonly byte TypeExtensionValueMask = 0x01;
private static readonly byte StaticExtensionValueMask = 0x02;
private const byte TypeExtensionValueMask = 0x01;
private const byte StaticExtensionValueMask = 0x02;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2448,9 +2448,9 @@ public override string ToString()
private short _extensionTypeId = 0;
private short _valueId = 0;

private static readonly short ExtensionIdMask = 0x0FFF;
private static readonly short TypeExtensionValueMask = 0x4000;
private static readonly short StaticExtensionValueMask = 0x2000;
private const short ExtensionIdMask = 0x0FFF;
private const short TypeExtensionValueMask = 0x4000;
private const short StaticExtensionValueMask = 0x2000;
#endregion Data
}

Expand Down Expand Up @@ -2888,11 +2888,11 @@ private static BitVector32.Section _isRawEnumValueSetSection
}
#endif

#endregion Properties
#endregion Properties

#region Data
#region Data

internal static readonly short TypeIdValueMask = 0x4000;
internal const short TypeIdValueMask = 0x4000;

private short _attributeId = 0;
private short _serializerTypeId = 0;
Expand Down Expand Up @@ -3658,8 +3658,8 @@ public bool IsValueStaticExtension

private short _valueId = 0;

private static readonly byte TypeExtensionValueMask = 0x01;
private static readonly byte StaticExtensionValueMask = 0x02;
private const byte TypeExtensionValueMask = 0x01;
private const byte StaticExtensionValueMask = 0x02;

// Allocate space in _flags.
private static BitVector32.Section _isValueTypeExtensionSection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ internal static MethodInfo XmlSpaceSetter
}

// These are special attributes that aren't mapped like other properties
internal static readonly string XmlSpaceString = "xml:space";
internal static readonly string XmlLangString = "xml:lang";
internal static readonly string XmlnsDefinitionString = "xmlns";
internal const string XmlSpaceString = "xml:space";
internal const string XmlLangString = "xml:lang";
internal const string XmlnsDefinitionString = "xmlns";
private static MethodInfo _xmlSpaceSetter = null;
#endregion Internal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public CornerRadius CornerRadius
(d, e) => ((WindowChrome)d)._OnPropertyChangedThatRequiresRepaint()),
_NonClientFrameEdgesAreValid);

private static readonly NonClientFrameEdges NonClientFrameEdges_All = NonClientFrameEdges.Left | NonClientFrameEdges.Top | NonClientFrameEdges.Right | NonClientFrameEdges.Bottom;
private const NonClientFrameEdges NonClientFrameEdges_All = NonClientFrameEdges.Left | NonClientFrameEdges.Top | NonClientFrameEdges.Right | NonClientFrameEdges.Bottom;

private static bool _NonClientFrameEdgesAreValid(object value)
{
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: NativeDirectoryServicesQueryAPIs contains managed wrappers
Expand Down Expand Up @@ -166,20 +166,20 @@ internal struct DsObjectNames

// CommonQuery parameters (from cmnquery.h) used in OpenQueryWindowParams to define the
// state of the People Picker when invoked.
internal static readonly uint OQWF_OKCANCEL = 0x00000001; // = 1 => Provide OK/Cancel buttons
internal static readonly uint OQWF_DEFAULTFORM = 0x00000002; // = 1 => clsidDefaultQueryForm is valid
internal static readonly uint OQWF_SINGLESELECT = 0x00000004; // = 1 => allow single selection only
internal static readonly uint OQWF_REMOVEFORMS = 0x00000020; // = 1 => remove form picker from dialog
internal static readonly uint OQWF_SHOWOPTIONAL = 0x00000080; // = 1 => list optional forms by default
internal static readonly uint OQWF_HIDEMENUS = 0x00000400; // = 1 => no menu bar displayed
internal const uint OQWF_OKCANCEL = 0x00000001; // = 1 => Provide OK/Cancel buttons
internal const uint OQWF_DEFAULTFORM = 0x00000002; // = 1 => clsidDefaultQueryForm is valid
internal const uint OQWF_SINGLESELECT = 0x00000004; // = 1 => allow single selection only
internal const uint OQWF_REMOVEFORMS = 0x00000020; // = 1 => remove form picker from dialog
internal const uint OQWF_SHOWOPTIONAL = 0x00000080; // = 1 => list optional forms by default
internal const uint OQWF_HIDEMENUS = 0x00000400; // = 1 => no menu bar displayed

// Clipboard formats (from winuser.h)
internal static readonly String CFSTR_DSOBJECTNAMES = "DsObjectNames";
internal const String CFSTR_DSOBJECTNAMES = "DsObjectNames";

// Success/Failure codes
internal static readonly uint S_OK = 0x00000000;
internal static readonly uint S_FALSE = 0x00000001;
internal static readonly uint E_FAIL = 0x80000008;
internal const uint S_OK = 0x00000000;
internal const uint S_FALSE = 0x00000001;
internal const uint E_FAIL = 0x80000008;

}
}
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 All @@ -16,32 +16,32 @@ internal static class DevModeDitherTypes
/// <summary>
/// No dithering
/// </summary>
public static readonly uint DMDITHER_NONE = 0x00000001;
public const uint DMDITHER_NONE = 0x00000001;

/// <summary>
/// Dithering with a coarse brush.
/// </summary>
public static readonly uint DMDITHER_COARSE = 0x00000002;
public const uint DMDITHER_COARSE = 0x00000002;

/// <summary>
/// Dithering with a fine brush.
/// </summary>
public static readonly uint DMDITHER_FINE = 0x00000003;
public const uint DMDITHER_FINE = 0x00000003;

/// <summary>
/// Line art dithering.
/// </summary>
public static readonly uint DMDITHER_LINEART = 0x00000004;
public const uint DMDITHER_LINEART = 0x00000004;

/// <summary>
/// Windows 95/98/Me: Dithering in which an algorithm is used to spread, or diffuse, the error of approximating a specified color over adjacent pixels.
/// In contrast, DMDITHER_COARSE, DMDITHER_FINE, and DMDITHER_LINEART use patterned halftoning to approximate a color.
/// </summary>
public static readonly uint DMDITHER_ERRORDIFFUSION = 0x00000005;
public const uint DMDITHER_ERRORDIFFUSION = 0x00000005;

/// <summary>
/// Device does gray scaling.
/// </summary>
public static readonly uint DMDITHER_GRAYSCALE = 0x0000000A;
public const uint DMDITHER_GRAYSCALE = 0x0000000A;
}
}
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 All @@ -16,21 +16,21 @@ internal static class DevModeICMIntents
/// <summary>
/// Color matching should optimize for color saturation. This value is the most appropriate choice for business graphs when dithering is not desired.
/// </summary>
public static readonly uint DMICM_SATURATE = 1;
public const uint DMICM_SATURATE = 1;

/// <summary>
/// Color matching should optimize for color contrast. This value is the most appropriate choice for scanned or photographic images when dithering is desired.
/// </summary>
public static readonly uint DMICM_CONTRAST = 2;
public const uint DMICM_CONTRAST = 2;

/// <summary>
/// Color matching should optimize to match the exact color requested. This value is most appropriate for use with business logos or other images when an exact color match is desired.
/// </summary>
public static readonly uint DMICM_COLORIMETRIC = 3;
public const uint DMICM_COLORIMETRIC = 3;

/// <summary>
/// Color matching should optimize to match the exact color requested without white point mapping. This value is most appropriate for use with proofing.
/// </summary>
public static readonly uint DMICM_ABS_COLORIMETRIC = 4;
public const uint DMICM_ABS_COLORIMETRIC = 4;
}
}
Loading