From c4638601c6779d9e8547be3af64218f1179904d8 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 25 Jul 2019 22:02:21 -0400 Subject: [PATCH] Re-enable CA1802 (use consts instead of readonly statics) (dotnet/corefx#39782) * Re-enable CA1802 (use consts instead of readonly statics) I enabled it only for privates and internals, as we've previously violated this in public surface area, and as everything goes through API review moving forward, didn't seem worthwhile fighting it and adding suppressions in various places. * Address PR feedback Commit migrated from https://github.com/dotnet/corefx/commit/318b5941ba4e713155d82c674c7f5bd0e68faf7b --- src/libraries/CodeAnalysis.ruleset | 1 - .../src/System/Data/ProviderBase/TimeoutTimer.cs | 2 +- .../Common/src/System/Net/Mail/MailBnfHelper.cs | 38 +++-- .../Common/src/System/Net/SocketAddress.cs | 2 + .../System/Configuration/ConfigurationElement.cs | 2 +- .../System/Configuration/ConfigurationProperty.cs | 4 +- .../ConfigurationPropertyAttribute.cs | 7 +- .../ConfigurationPropertyCollection.cs | 2 +- .../Configuration/PropertyInformationCollection.cs | 2 +- .../src/System/Data/Common/DecimalStorage.cs | 22 +-- .../src/System/Data/Common/UInt16Storage.cs | 16 +- .../src/System/Data/Common/UInt32Storage.cs | 16 +- .../src/System/Data/Common/UInt64Storage.cs | 16 +- .../src/System/Data/SQLTypes/SQLByte.cs | 2 +- .../src/System/Data/SQLTypes/SQLDateTime.cs | 18 +-- .../src/System/Data/SQLTypes/SQLDecimal.cs | 82 +++++----- .../src/System/Data/SQLTypes/SQLGuid.cs | 12 +- .../src/System/Data/SQLTypes/SQLInt16.cs | 6 +- .../src/System/Data/SQLTypes/SQLInt32.cs | 4 +- .../src/System/Data/SQLTypes/SQLInt64.cs | 4 +- .../src/System/Data/SQLTypes/SQLMoney.cs | 10 +- .../src/System/Data/SQLTypes/SQLString.cs | 10 +- .../Common/System/Data/Common/AdapterUtil.Odbc.cs | 3 - .../src/System/Data/Odbc/OdbcCommand.cs | 2 +- .../src/System/Data/Odbc/OdbcConnection.cs | 2 +- .../src/System/Data/Odbc/OdbcHandle.cs | 4 +- .../src/System/Data/Odbc/OdbcParameter.cs | 2 +- .../src/System/Data/Odbc/OdbcParameterHelper.cs | 2 +- .../System/Data/Common/AdapterUtil.SqlClient.cs | 3 - .../src/System/Data/SqlClient/SqlCommand.cs | 4 +- .../src/System/Data/SqlClient/SqlEnums.cs | 2 +- .../src/System/Data/SqlClient/SqlParameter.cs | 12 +- .../System/Data/SqlClient/SqlParameterHelper.cs | 2 +- .../src/System/Data/SqlClient/TdsParser.cs | 17 +-- .../IO/Packaging/InternalRelationshipCollection.cs | 64 ++++---- .../src/System/IO/Packaging/PackUriHelper.cs | 36 ++--- .../src/System/IO/Packaging/PackagingUtilities.cs | 2 +- .../src/System/IO/Packaging/ZipPackage.cs | 85 ++++++----- .../src/System/Management/ManagementQuery.cs | 168 ++++++++++----------- .../System/Net/Sockets/SocketAsyncEngine.Unix.cs | 11 +- .../Sockets/UnixDomainSocketEndPoint.Windows.cs | 2 + .../UnixDomainSocketTest.netcoreapp.cs | 6 +- .../src/System.Private.Xml.csproj | 2 +- .../src/System/Xml/Base64Decoder.cs | 6 +- .../src/System/Xml/BinaryXml/SqlUtils.cs | 20 +-- .../System.Private.Xml/src/System/Xml/Bits.cs | 20 +-- .../System/Xml/Schema/XmlUntypedStringConverter.cs | 4 +- .../src/System/Xml/XmlConvert.cs | 14 +- .../Runtime/Caching/PhysicalMemoryMonitor.cs | 8 +- .../src/System/Security/AccessControl/ACE.cs | 2 +- .../Security/AccessControl/ObjectSecurity.cs | 4 +- .../src/System/Security/Principal/SID.cs | 4 +- .../Text/RegularExpressions/RegexCharClass.cs | 58 ++++--- 53 files changed, 419 insertions(+), 430 deletions(-) diff --git a/src/libraries/CodeAnalysis.ruleset b/src/libraries/CodeAnalysis.ruleset index e2f8929..92aa3bc 100644 --- a/src/libraries/CodeAnalysis.ruleset +++ b/src/libraries/CodeAnalysis.ruleset @@ -43,7 +43,6 @@ - diff --git a/src/libraries/Common/src/System/Data/ProviderBase/TimeoutTimer.cs b/src/libraries/Common/src/System/Data/ProviderBase/TimeoutTimer.cs index 7b25865..acd7685 100644 --- a/src/libraries/Common/src/System/Data/ProviderBase/TimeoutTimer.cs +++ b/src/libraries/Common/src/System/Data/ProviderBase/TimeoutTimer.cs @@ -102,7 +102,7 @@ namespace System.Data.ProviderBase //------------------- // Indicator for infinite timeout when starting a timer - internal static readonly long InfiniteTimeout = 0; + internal const long InfiniteTimeout = 0; // Is this timer in an expired state? internal bool IsExpired diff --git a/src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs b/src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs index b9d62f7..ea9ca19 100644 --- a/src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs +++ b/src/libraries/Common/src/System/Net/Mail/MailBnfHelper.cs @@ -2,12 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; -using System.Text; -using System.Net.Mail; -using System.Globalization; -using System.Collections.Generic; using System.Diagnostics; +using System.Text; namespace System.Net.Mime { @@ -31,22 +27,22 @@ namespace System.Net.Mime // characters allowed inside of comments internal static readonly bool[] Ctext = CreateCharactersAllowedInComments(); - internal static readonly int Ascii7bitMaxValue = 127; - internal static readonly char Quote = '\"'; - internal static readonly char Space = ' '; - internal static readonly char Tab = '\t'; - internal static readonly char CR = '\r'; - internal static readonly char LF = '\n'; - internal static readonly char StartComment = '('; - internal static readonly char EndComment = ')'; - internal static readonly char Backslash = '\\'; - internal static readonly char At = '@'; - internal static readonly char EndAngleBracket = '>'; - internal static readonly char StartAngleBracket = '<'; - internal static readonly char StartSquareBracket = '['; - internal static readonly char EndSquareBracket = ']'; - internal static readonly char Comma = ','; - internal static readonly char Dot = '.'; + internal const int Ascii7bitMaxValue = 127; + internal const char Quote = '\"'; + internal const char Space = ' '; + internal const char Tab = '\t'; + internal const char CR = '\r'; + internal const char LF = '\n'; + internal const char StartComment = '('; + internal const char EndComment = ')'; + internal const char Backslash = '\\'; + internal const char At = '@'; + internal const char EndAngleBracket = '>'; + internal const char StartAngleBracket = '<'; + internal const char StartSquareBracket = '['; + internal const char EndSquareBracket = ']'; + internal const char Comma = ','; + internal const char Dot = '.'; private static readonly char[] s_colonSeparator = new char[] { ':' }; diff --git a/src/libraries/Common/src/System/Net/SocketAddress.cs b/src/libraries/Common/src/System/Net/SocketAddress.cs index e9f495e..310b8fc 100644 --- a/src/libraries/Common/src/System/Net/SocketAddress.cs +++ b/src/libraries/Common/src/System/Net/SocketAddress.cs @@ -22,8 +22,10 @@ namespace System.Net.Internals #endif class SocketAddress { +#pragma warning disable CA1802 // these could be const on Windows but need to be static readonly for Unix internal static readonly int IPv6AddressSize = SocketAddressPal.IPv6AddressSize; internal static readonly int IPv4AddressSize = SocketAddressPal.IPv4AddressSize; +#pragma warning restore CA1802 internal int InternalSize; internal byte[] Buffer; diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationElement.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationElement.cs index 102f903..59bcf78 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationElement.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationElement.cs @@ -1163,7 +1163,7 @@ namespace System.Configuration ConfigurationElement elem = (ConfigurationElement)value; - if (prop.Name != ConfigurationProperty.s_defaultCollectionPropertyName) + if (prop.Name != ConfigurationProperty.DefaultCollectionPropertyName) { dataToWrite |= elem.SerializeToXmlElement(writer, prop.Name); } diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs index 42e3c04..b809412 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationProperty.cs @@ -12,7 +12,7 @@ namespace System.Configuration { internal static readonly ConfigurationValidatorBase s_nonEmptyStringValidator = new StringValidator(1); private static readonly ConfigurationValidatorBase s_defaultValidatorInstance = new DefaultValidator(); - internal static readonly string s_defaultCollectionPropertyName = ""; + internal const string DefaultCollectionPropertyName = ""; private TypeConverter _converter; private volatile bool _isConfigurationElementType; private volatile bool _isTypeInited; @@ -229,7 +229,7 @@ namespace System.Configuration if (((options & ConfigurationPropertyOptions.IsDefaultCollection) != 0) && string.IsNullOrEmpty(name)) { - name = s_defaultCollectionPropertyName; + name = DefaultCollectionPropertyName; } else { diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyAttribute.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyAttribute.cs index 7bf8435..b232b9c 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyAttribute.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyAttribute.cs @@ -7,10 +7,7 @@ namespace System.Configuration [AttributeUsage(AttributeTargets.Property)] public sealed class ConfigurationPropertyAttribute : Attribute { - // disable csharp compiler warning #0414: field assigned unused value -#pragma warning disable 0414 - internal static readonly string s_defaultCollectionPropertyName = ""; -#pragma warning restore 0414 + internal const string DefaultCollectionPropertyName = ""; public ConfigurationPropertyAttribute(string name) { @@ -54,4 +51,4 @@ namespace System.Configuration } } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyCollection.cs index b4d4f52..e317cc9 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyCollection.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/ConfigurationPropertyCollection.cs @@ -11,7 +11,7 @@ namespace System.Configuration private readonly ArrayList _items = new ArrayList(); internal ConfigurationProperty DefaultCollectionProperty - => this[ConfigurationProperty.s_defaultCollectionPropertyName]; + => this[ConfigurationProperty.DefaultCollectionPropertyName]; public ConfigurationProperty this[string name] { diff --git a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/PropertyInformationCollection.cs b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/PropertyInformationCollection.cs index 067af4b..0cee1d0 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/PropertyInformationCollection.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/PropertyInformationCollection.cs @@ -29,7 +29,7 @@ namespace System.Configuration if (result == null) { PropertyInformation defaultColl = - (PropertyInformation)BaseGet(ConfigurationProperty.s_defaultCollectionPropertyName); + (PropertyInformation)BaseGet(ConfigurationProperty.DefaultCollectionPropertyName); if ((defaultColl != null) && (defaultColl.ProvidedName == propertyName)) result = defaultColl; } diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DecimalStorage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DecimalStorage.cs index 7a8d954..847dfb2 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DecimalStorage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DecimalStorage.cs @@ -9,12 +9,12 @@ namespace System.Data.Common { internal sealed class DecimalStorage : DataStorage { - private static readonly decimal s_defaultValue = decimal.Zero; + private const decimal DefaultValue = decimal.Zero; private decimal[] _values; internal DecimalStorage(DataColumn column) - : base(column, typeof(decimal), s_defaultValue, StorageType.Decimal) + : base(column, typeof(decimal), DefaultValue, StorageType.Decimal) { } @@ -26,7 +26,7 @@ namespace System.Data.Common switch (kind) { case AggregateType.Sum: - decimal sum = s_defaultValue; + decimal sum = DefaultValue; foreach (int record in records) { if (HasValue(record)) @@ -42,7 +42,7 @@ namespace System.Data.Common return _nullValue; case AggregateType.Mean: - decimal meanSum = s_defaultValue; + decimal meanSum = DefaultValue; int meanCount = 0; foreach (int record in records) { @@ -64,10 +64,10 @@ namespace System.Data.Common case AggregateType.Var: case AggregateType.StDev: int count = 0; - double var = (double)s_defaultValue; - double prec = (double)s_defaultValue; - double dsum = (double)s_defaultValue; - double sqrsum = (double)s_defaultValue; + double var = (double)DefaultValue; + double prec = (double)DefaultValue; + double dsum = (double)DefaultValue; + double sqrsum = (double)DefaultValue; foreach (int record in records) { @@ -158,7 +158,7 @@ namespace System.Data.Common decimal valueNo1 = _values[recordNo1]; decimal valueNo2 = _values[recordNo2]; - if (valueNo1 == s_defaultValue || valueNo2 == s_defaultValue) + if (valueNo1 == DefaultValue || valueNo2 == DefaultValue) { int bitCheck = CompareBits(recordNo1, recordNo2); if (0 != bitCheck) @@ -178,7 +178,7 @@ namespace System.Data.Common } decimal valueNo1 = _values[recordNo]; - if ((s_defaultValue == valueNo1) && !HasValue(recordNo)) + if ((DefaultValue == valueNo1) && !HasValue(recordNo)) { return -1; } @@ -217,7 +217,7 @@ namespace System.Data.Common System.Diagnostics.Debug.Assert(null != value, "null value"); if (_nullValue == value) { - _values[record] = s_defaultValue; + _values[record] = DefaultValue; SetNullBit(record, true); } else diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/UInt16Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/UInt16Storage.cs index 1979aa3..d0ed60a 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/UInt16Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/UInt16Storage.cs @@ -9,12 +9,12 @@ namespace System.Data.Common { internal sealed class UInt16Storage : DataStorage { - private static readonly ushort s_defaultValue = ushort.MinValue; + private const ushort DefaultValue = ushort.MinValue; private ushort[] _values; public UInt16Storage(DataColumn column) - : base(column, typeof(ushort), s_defaultValue, StorageType.UInt16) + : base(column, typeof(ushort), DefaultValue, StorageType.UInt16) { } @@ -26,7 +26,7 @@ namespace System.Data.Common switch (kind) { case AggregateType.Sum: - ulong sum = s_defaultValue; + ulong sum = DefaultValue; foreach (int record in records) { if (HasValue(record)) @@ -42,7 +42,7 @@ namespace System.Data.Common return _nullValue; case AggregateType.Mean: - long meanSum = s_defaultValue; + long meanSum = DefaultValue; int meanCount = 0; foreach (int record in records) { @@ -166,7 +166,7 @@ namespace System.Data.Common ushort valueNo1 = _values[recordNo1]; ushort valueNo2 = _values[recordNo2]; - if (valueNo1 == s_defaultValue || valueNo2 == s_defaultValue) + if (valueNo1 == DefaultValue || valueNo2 == DefaultValue) { int bitCheck = CompareBits(recordNo1, recordNo2); if (0 != bitCheck) @@ -189,7 +189,7 @@ namespace System.Data.Common } ushort valueNo1 = _values[recordNo]; - if ((s_defaultValue == valueNo1) && !HasValue(recordNo)) + if ((DefaultValue == valueNo1) && !HasValue(recordNo)) { return -1; } @@ -222,7 +222,7 @@ namespace System.Data.Common public override object Get(int record) { ushort value = _values[record]; - if (!value.Equals(s_defaultValue)) + if (!value.Equals(DefaultValue)) { return value; } @@ -234,7 +234,7 @@ namespace System.Data.Common System.Diagnostics.Debug.Assert(null != value, "null value"); if (_nullValue == value) { - _values[record] = s_defaultValue; + _values[record] = DefaultValue; SetNullBit(record, true); } else diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/UInt32Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/UInt32Storage.cs index c9781c0..330a185 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/UInt32Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/UInt32Storage.cs @@ -9,12 +9,12 @@ namespace System.Data.Common { internal sealed class UInt32Storage : DataStorage { - private static readonly uint s_defaultValue = uint.MinValue; + private const uint DefaultValue = uint.MinValue; private uint[] _values; public UInt32Storage(DataColumn column) - : base(column, typeof(uint), s_defaultValue, StorageType.UInt32) + : base(column, typeof(uint), DefaultValue, StorageType.UInt32) { } @@ -26,7 +26,7 @@ namespace System.Data.Common switch (kind) { case AggregateType.Sum: - ulong sum = s_defaultValue; + ulong sum = DefaultValue; foreach (int record in records) { if (HasValue(record)) @@ -42,7 +42,7 @@ namespace System.Data.Common return _nullValue; case AggregateType.Mean: - long meanSum = s_defaultValue; + long meanSum = DefaultValue; int meanCount = 0; foreach (int record in records) { @@ -165,7 +165,7 @@ namespace System.Data.Common uint valueNo1 = _values[recordNo1]; uint valueNo2 = _values[recordNo2]; - if (valueNo1 == s_defaultValue || valueNo2 == s_defaultValue) + if (valueNo1 == DefaultValue || valueNo2 == DefaultValue) { int bitCheck = CompareBits(recordNo1, recordNo2); if (0 != bitCheck) @@ -188,7 +188,7 @@ namespace System.Data.Common } uint valueNo1 = _values[recordNo]; - if ((s_defaultValue == valueNo1) && !HasValue(recordNo)) + if ((DefaultValue == valueNo1) && !HasValue(recordNo)) { return -1; } @@ -221,7 +221,7 @@ namespace System.Data.Common public override object Get(int record) { uint value = _values[record]; - if (!value.Equals(s_defaultValue)) + if (!value.Equals(DefaultValue)) { return value; } @@ -233,7 +233,7 @@ namespace System.Data.Common System.Diagnostics.Debug.Assert(null != value, "null value"); if (_nullValue == value) { - _values[record] = s_defaultValue; + _values[record] = DefaultValue; SetNullBit(record, true); } else diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/UInt64Storage.cs b/src/libraries/System.Data.Common/src/System/Data/Common/UInt64Storage.cs index 0bb59d6..155cc89 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/UInt64Storage.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/UInt64Storage.cs @@ -9,12 +9,12 @@ namespace System.Data.Common { internal sealed class UInt64Storage : DataStorage { - private static readonly ulong s_defaultValue = ulong.MinValue; + private const ulong DefaultValue = ulong.MinValue; private ulong[] _values; public UInt64Storage(DataColumn column) - : base(column, typeof(ulong), s_defaultValue, StorageType.UInt64) + : base(column, typeof(ulong), DefaultValue, StorageType.UInt64) { } @@ -26,7 +26,7 @@ namespace System.Data.Common switch (kind) { case AggregateType.Sum: - ulong sum = s_defaultValue; + ulong sum = DefaultValue; foreach (int record in records) { if (HasValue(record)) @@ -42,7 +42,7 @@ namespace System.Data.Common return _nullValue; case AggregateType.Mean: - decimal meanSum = s_defaultValue; + decimal meanSum = DefaultValue; int meanCount = 0; foreach (int record in records) { @@ -158,7 +158,7 @@ namespace System.Data.Common ulong valueNo1 = _values[recordNo1]; ulong valueNo2 = _values[recordNo2]; - if (valueNo1.Equals(s_defaultValue) || valueNo2.Equals(s_defaultValue)) + if (valueNo1.Equals(DefaultValue) || valueNo2.Equals(DefaultValue)) { int bitCheck = CompareBits(recordNo1, recordNo2); if (0 != bitCheck) @@ -179,7 +179,7 @@ namespace System.Data.Common } ulong valueNo1 = _values[recordNo]; - if ((s_defaultValue == valueNo1) && !HasValue(recordNo)) + if ((DefaultValue == valueNo1) && !HasValue(recordNo)) { return -1; } @@ -212,7 +212,7 @@ namespace System.Data.Common public override object Get(int record) { ulong value = _values[record]; - if (!value.Equals(s_defaultValue)) + if (!value.Equals(DefaultValue)) { return value; } @@ -224,7 +224,7 @@ namespace System.Data.Common System.Diagnostics.Debug.Assert(null != value, "null value"); if (_nullValue == value) { - _values[record] = s_defaultValue; + _values[record] = DefaultValue; SetNullBit(record, true); } else diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLByte.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLByte.cs index 9ea2001..6c69589 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLByte.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLByte.cs @@ -23,7 +23,7 @@ namespace System.Data.SqlTypes private bool m_fNotNull; // false if null. Do not rename (binary serialization) private byte m_value; // Do not rename (binary serialization) - private static readonly int s_iBitNotByteMax = ~0xff; + private const int s_iBitNotByteMax = ~0xff; // constructor // construct a Null diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDateTime.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDateTime.cs index 96060a6..56c0f7a 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDateTime.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDateTime.cs @@ -30,26 +30,26 @@ namespace System.Data.SqlTypes // Constants // Number of (100ns) ticks per time unit - private static readonly double s_SQLTicksPerMillisecond = 0.3; + private const double s_SQLTicksPerMillisecond = 0.3; public static readonly int SQLTicksPerSecond = 300; public static readonly int SQLTicksPerMinute = SQLTicksPerSecond * 60; public static readonly int SQLTicksPerHour = SQLTicksPerMinute * 60; private static readonly int s_SQLTicksPerDay = SQLTicksPerHour * 24; - private static readonly long s_ticksPerSecond = TimeSpan.TicksPerMillisecond * 1000; + private const long s_ticksPerSecond = TimeSpan.TicksPerMillisecond * 1000; private static readonly DateTime s_SQLBaseDate = new DateTime(1900, 1, 1); private static readonly long s_SQLBaseDateTicks = s_SQLBaseDate.Ticks; - private static readonly int s_minYear = 1753; // Jan 1 1753 - private static readonly int s_maxYear = 9999; // Dec 31 9999 + private const int s_minYear = 1753; // Jan 1 1753 + private const int s_maxYear = 9999; // Dec 31 9999 - private static readonly int s_minDay = -53690; // Jan 1 1753 - private static readonly int s_maxDay = 2958463; // Dec 31 9999 is this many days from Jan 1 1900 - private static readonly int s_minTime = 0; // 00:00:0:000PM + private const int s_minDay = -53690; // Jan 1 1753 + private const int s_maxDay = 2958463; // Dec 31 9999 is this many days from Jan 1 1900 + private const int s_minTime = 0; // 00:00:0:000PM private static readonly int s_maxTime = s_SQLTicksPerDay - 1; // = 25919999, 11:59:59:997PM - private static readonly int s_dayBase = 693595; // Jan 1 1900 is this many days from Jan 1 0001 + private const int s_dayBase = 693595; // Jan 1 1900 is this many days from Jan 1 0001 private static readonly int[] s_daysToMonth365 = new int[] { @@ -61,7 +61,7 @@ namespace System.Data.SqlTypes private static readonly DateTime s_maxDateTime = DateTime.MaxValue; private static readonly TimeSpan s_minTimeSpan = s_minDateTime.Subtract(s_SQLBaseDate); private static readonly TimeSpan s_maxTimeSpan = s_maxDateTime.Subtract(s_SQLBaseDate); - private static readonly string s_ISO8601_DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fff"; + private const string s_ISO8601_DateTimeFormat = "yyyy-MM-ddTHH:mm:ss.fff"; // These formats are valid styles in SQL Server (style 9, 12, 13, 14) // but couldn't be recognized by the default parse. Needs to call diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDecimal.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDecimal.cs index 9b8e08b..2de681f 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDecimal.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLDecimal.cs @@ -37,38 +37,38 @@ namespace System.Data.SqlTypes internal uint _data3; internal uint _data4; - private static readonly byte s_NUMERIC_MAX_PRECISION = 38; // Maximum precision of numeric + private const byte s_NUMERIC_MAX_PRECISION = 38; // Maximum precision of numeric public static readonly byte MaxPrecision = s_NUMERIC_MAX_PRECISION; // max SS precision public static readonly byte MaxScale = s_NUMERIC_MAX_PRECISION; // max SS scale - private static readonly byte s_bNullMask = 1; // bit mask for null bit in m_bStatus - private static readonly byte s_bIsNull = 0; // is null - private static readonly byte s_bNotNull = 1; // is not null - private static readonly byte s_bReverseNullMask = unchecked((byte)~s_bNullMask); + private const byte s_bNullMask = 1; // bit mask for null bit in m_bStatus + private const byte s_bIsNull = 0; // is null + private const byte s_bNotNull = 1; // is not null + private const byte s_bReverseNullMask = unchecked((byte)~s_bNullMask); - private static readonly byte s_bSignMask = 2; // bit mask for sign bit in m_bStatus - private static readonly byte s_bPositive = 0; // is positive - private static readonly byte s_bNegative = 2; // is negative - private static readonly byte s_bReverseSignMask = unchecked((byte)~s_bSignMask); + private const byte s_bSignMask = 2; // bit mask for sign bit in m_bStatus + private const byte s_bPositive = 0; // is positive + private const byte s_bNegative = 2; // is negative + private const byte s_bReverseSignMask = unchecked((byte)~s_bSignMask); - private static readonly uint s_uiZero = 0; + private const uint s_uiZero = 0; - private static readonly int s_cNumeMax = 4; - private static readonly long s_lInt32Base = ((long)1) << 32; // 2**32 - private static readonly ulong s_ulInt32Base = ((ulong)1) << 32; // 2**32 - private static readonly ulong s_ulInt32BaseForMod = s_ulInt32Base - 1; // 2**32 - 1 (0xFFF...FF) + private const int s_cNumeMax = 4; + private const long s_lInt32Base = ((long)1) << 32; // 2**32 + private const ulong s_ulInt32Base = ((ulong)1) << 32; // 2**32 + private const ulong s_ulInt32BaseForMod = s_ulInt32Base - 1; // 2**32 - 1 (0xFFF...FF) - internal static readonly ulong s_llMax = long.MaxValue; // Max of Int64 + internal const ulong s_llMax = long.MaxValue; // Max of Int64 - private static readonly uint s_ulBase10 = 10; + private const uint s_ulBase10 = 10; - private static readonly double s_DUINT_BASE = s_lInt32Base; // 2**32 - private static readonly double s_DUINT_BASE2 = s_DUINT_BASE * s_DUINT_BASE; // 2**64 - private static readonly double s_DUINT_BASE3 = s_DUINT_BASE2 * s_DUINT_BASE; // 2**96 - private static readonly double s_DMAX_NUME = 1.0e+38; // Max value of numeric - private static readonly uint s_DBL_DIG = 17; // Max decimal digits of double + private const double s_DUINT_BASE = s_lInt32Base; // 2**32 + private const double s_DUINT_BASE2 = s_DUINT_BASE * s_DUINT_BASE; // 2**64 + private const double s_DUINT_BASE3 = s_DUINT_BASE2 * s_DUINT_BASE; // 2**96 + private const double s_DMAX_NUME = 1.0e+38; // Max value of numeric + private const uint s_DBL_DIG = 17; // Max decimal digits of double - private static readonly byte s_cNumeDivScaleMin = 6; // Minimum result scale of numeric division + private const byte s_cNumeDivScaleMin = 6; // Minimum result scale of numeric division // Array of multipliers for lAdjust and Ceiling/Floor. private static readonly uint[] s_rgulShiftBase = new uint[9] { @@ -1912,25 +1912,25 @@ namespace System.Data.SqlTypes // Powers of ten (used by BGetPrecI4,BGetPrecI8) - private static readonly uint s_ulT1 = 10; - private static readonly uint s_ulT2 = 100; - private static readonly uint s_ulT3 = 1000; - private static readonly uint s_ulT4 = 10000; - private static readonly uint s_ulT5 = 100000; - private static readonly uint s_ulT6 = 1000000; - private static readonly uint s_ulT7 = 10000000; - private static readonly uint s_ulT8 = 100000000; - private static readonly uint s_ulT9 = 1000000000; - private static readonly ulong s_dwlT10 = 10000000000; - private static readonly ulong s_dwlT11 = 100000000000; - private static readonly ulong s_dwlT12 = 1000000000000; - private static readonly ulong s_dwlT13 = 10000000000000; - private static readonly ulong s_dwlT14 = 100000000000000; - private static readonly ulong s_dwlT15 = 1000000000000000; - private static readonly ulong s_dwlT16 = 10000000000000000; - private static readonly ulong s_dwlT17 = 100000000000000000; - private static readonly ulong s_dwlT18 = 1000000000000000000; - private static readonly ulong s_dwlT19 = 10000000000000000000; + private const uint s_ulT1 = 10; + private const uint s_ulT2 = 100; + private const uint s_ulT3 = 1000; + private const uint s_ulT4 = 10000; + private const uint s_ulT5 = 100000; + private const uint s_ulT6 = 1000000; + private const uint s_ulT7 = 10000000; + private const uint s_ulT8 = 100000000; + private const uint s_ulT9 = 1000000000; + private const ulong s_dwlT10 = 10000000000; + private const ulong s_dwlT11 = 100000000000; + private const ulong s_dwlT12 = 1000000000000; + private const ulong s_dwlT13 = 10000000000000; + private const ulong s_dwlT14 = 100000000000000; + private const ulong s_dwlT15 = 1000000000000000; + private const ulong s_dwlT16 = 10000000000000000; + private const ulong s_dwlT17 = 100000000000000000; + private const ulong s_dwlT18 = 1000000000000000000; + private const ulong s_dwlT19 = 10000000000000000000; //------------------------------------------------------------------ //BGetPrecI4 diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLGuid.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLGuid.cs index 5724384..c1eabec 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLGuid.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLGuid.cs @@ -18,7 +18,7 @@ namespace System.Data.SqlTypes [System.Runtime.CompilerServices.TypeForwardedFrom("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public struct SqlGuid : INullable, IComparable, IXmlSerializable { - private static readonly int s_sizeOfGuid = 16; + private const int SizeOfGuid = 16; // Comparison orders. private static readonly int[] s_rgiGuidOrder = new int[16] @@ -36,16 +36,16 @@ namespace System.Data.SqlTypes public SqlGuid(byte[] value) { - if (value == null || value.Length != s_sizeOfGuid) + if (value == null || value.Length != SizeOfGuid) throw new ArgumentException(SQLResource.InvalidArraySizeMessage); - m_value = new byte[s_sizeOfGuid]; + m_value = new byte[SizeOfGuid]; value.CopyTo(m_value, 0); } internal SqlGuid(byte[] value, bool ignored) { - if (value == null || value.Length != s_sizeOfGuid) + if (value == null || value.Length != SizeOfGuid) throw new ArgumentException(SQLResource.InvalidArraySizeMessage); m_value = value; @@ -99,7 +99,7 @@ namespace System.Data.SqlTypes public byte[] ToByteArray() { - byte[] ret = new byte[s_sizeOfGuid]; + byte[] ret = new byte[SizeOfGuid]; m_value.CopyTo(ret, 0); return ret; } @@ -126,7 +126,7 @@ namespace System.Data.SqlTypes private static EComparison Compare(SqlGuid x, SqlGuid y) { //Swap to the correct order to be compared - for (int i = 0; i < s_sizeOfGuid; i++) + for (int i = 0; i < SizeOfGuid; i++) { byte b1, b2; diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt16.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt16.cs index c19a8ea..6d2a5a0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt16.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt16.cs @@ -22,7 +22,7 @@ namespace System.Data.SqlTypes private bool m_fNotNull; // false if null. Do not rename (binary serialization) private short m_value; // Do not rename (binary serialization) - private static readonly int s_MASKI2 = ~0x00007fff; + private const int MaskI2 = ~0x00007fff; // constructor // construct a Null @@ -125,8 +125,8 @@ namespace System.Data.SqlTypes return Null; int iResult = x.m_value * y.m_value; - int iTemp = iResult & s_MASKI2; - if (iTemp != 0 && iTemp != s_MASKI2) + int iTemp = iResult & MaskI2; + if (iTemp != 0 && iTemp != MaskI2) throw new OverflowException(SQLResource.ArithOverflowMessage); else return new SqlInt16((short)iResult); diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt32.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt32.cs index 42e20cc..a7caabb 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt32.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt32.cs @@ -22,8 +22,8 @@ namespace System.Data.SqlTypes private bool m_fNotNull; // false if null, the default ctor (plain 0) will make it Null. Do not rename (binary serialization) private int m_value; // Do not rename (binary serialization) - private static readonly long s_iIntMin = int.MinValue; // minimum (signed) int value - private static readonly long s_lBitNotIntMax = ~int.MaxValue; + private const long s_iIntMin = int.MinValue; // minimum (signed) int value + private const long s_lBitNotIntMax = ~int.MaxValue; // constructor // construct a Null diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt64.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt64.cs index 06231f3..a86bea4 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt64.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLInt64.cs @@ -23,8 +23,8 @@ namespace System.Data.SqlTypes private bool m_fNotNull; // false if null. Do not rename (binary serialization) private long m_value; // Do not rename (binary serialization) - private static readonly long s_lLowIntMask = 0xffffffff; - private static readonly long s_lHighIntMask = unchecked((long)0xffffffff00000000); + private const long s_lLowIntMask = 0xffffffff; + private const long s_lHighIntMask = unchecked((long)0xffffffff00000000); // constructor // construct a Null diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLMoney.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLMoney.cs index fc85e1c..b3d7057 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLMoney.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLMoney.cs @@ -28,12 +28,12 @@ namespace System.Data.SqlTypes private long _value; // SQL Server stores money8 as ticks of 1/10000. - internal static readonly int s_iMoneyScale = 4; - private static readonly long s_lTickBase = 10000; - private static readonly double s_dTickBase = s_lTickBase; + internal const int s_iMoneyScale = 4; + private const long s_lTickBase = 10000; + private const double s_dTickBase = s_lTickBase; - private static readonly long s_minLong = unchecked((long)0x8000000000000000L) / s_lTickBase; - private static readonly long s_maxLong = 0x7FFFFFFFFFFFFFFFL / s_lTickBase; + private const long s_minLong = unchecked((long)0x8000000000000000L) / s_lTickBase; + private const long s_maxLong = 0x7FFFFFFFFFFFFFFFL / s_lTickBase; // constructor // construct a Null diff --git a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLString.cs b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLString.cs index ab8bd50..85047cf 100644 --- a/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLString.cs +++ b/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLString.cs @@ -69,20 +69,20 @@ namespace System.Data.SqlTypes /// public static readonly int BinarySort2 = 0x4000; - private static readonly SqlCompareOptions s_iDefaultFlag = + private const SqlCompareOptions s_iDefaultFlag = SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreKanaType | SqlCompareOptions.IgnoreWidth; - private static readonly CompareOptions s_iValidCompareOptionMask = + private const CompareOptions s_iValidCompareOptionMask = CompareOptions.IgnoreCase | CompareOptions.IgnoreWidth | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreKanaType; - internal static readonly SqlCompareOptions s_iValidSqlCompareOptionMask = + internal const SqlCompareOptions s_iValidSqlCompareOptionMask = SqlCompareOptions.IgnoreCase | SqlCompareOptions.IgnoreWidth | SqlCompareOptions.IgnoreNonSpace | SqlCompareOptions.IgnoreKanaType | SqlCompareOptions.BinarySort | SqlCompareOptions.BinarySort2; - internal static readonly int s_lcidUSEnglish = 0x00000409; - private static readonly int s_lcidBinary = 0x00008200; + internal const int s_lcidUSEnglish = 0x00000409; + private const int s_lcidBinary = 0x00008200; // constructor diff --git a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs index fc4917e..158020c 100644 --- a/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs +++ b/src/libraries/System.Data.Odbc/src/Common/System/Data/Common/AdapterUtil.Odbc.cs @@ -570,9 +570,6 @@ namespace System.Data.Common internal const int DecimalMaxPrecision28 = 28; // there are some cases in Odbc where we need that ... internal const int DefaultCommandTimeout = 30; - // security issue, don't rely upon static public readonly values - AS/URT 109635 - internal static readonly string StrEmpty = ""; // String.Empty - internal static readonly IntPtr PtrZero = new IntPtr(0); // IntPtr.Zero internal static readonly int PtrSize = IntPtr.Size; diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcCommand.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcCommand.cs index b02a6c1..2f3691c 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcCommand.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcCommand.cs @@ -159,7 +159,7 @@ namespace System.Data.Odbc get { string value = _commandText; - return ((null != value) ? value : ADP.StrEmpty); + return ((null != value) ? value : string.Empty); } set { diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnection.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnection.cs index 7afd825..6fa7875 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnection.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcConnection.cs @@ -206,7 +206,7 @@ namespace System.Data.Odbc } return ProviderInfo.DriverName; } - return ADP.StrEmpty; + return string.Empty; } } diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs index d642517..1ecd9b6 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs @@ -197,7 +197,7 @@ namespace System.Data.Odbc } else { - sqlState = ADP.StrEmpty; + sqlState = string.Empty; } return retcode; } @@ -215,7 +215,7 @@ namespace System.Data.Odbc } else { - sqlState = ADP.StrEmpty; + sqlState = string.Empty; } return retcode; } diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameter.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameter.cs index ec888aa..a401609 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameter.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameter.cs @@ -225,7 +225,7 @@ namespace System.Data.Odbc get { string parameterName = _parameterName; - return ((null != parameterName) ? parameterName : ADP.StrEmpty); + return ((null != parameterName) ? parameterName : string.Empty); } set { diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameterHelper.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameterHelper.cs index 9353178..72f7bc7 100644 --- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameterHelper.cs +++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcParameterHelper.cs @@ -139,7 +139,7 @@ namespace System.Data.Odbc get { string sourceColumn = _sourceColumn; - return ((null != sourceColumn) ? sourceColumn : ADP.StrEmpty); + return ((null != sourceColumn) ? sourceColumn : string.Empty); } set { diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/Common/AdapterUtil.SqlClient.cs b/src/libraries/System.Data.SqlClient/src/System/Data/Common/AdapterUtil.SqlClient.cs index e37e22c..9cf4208e 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/Common/AdapterUtil.SqlClient.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/Common/AdapterUtil.SqlClient.cs @@ -581,9 +581,6 @@ namespace System.Data.Common internal const int DefaultCommandTimeout = 30; internal const float FailoverTimeoutStep = 0.08F; // fraction of timeout to use for fast failover connections - // security issue, don't rely upon public static readonly values - internal static readonly string StrEmpty = ""; // String.Empty - internal const int CharSize = sizeof(char); internal static Delegate FindBuilder(MulticastDelegate mcd) diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs index 9f5fa08..25977a3 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlCommand.cs @@ -394,7 +394,7 @@ namespace System.Data.SqlClient get { string value = _commandText; - return ((null != value) ? value : ADP.StrEmpty); + return ((null != value) ? value : string.Empty); } set { @@ -2168,7 +2168,7 @@ namespace System.Data.SqlClient { p.SqlDbType = MetaType.GetSqlDbTypeFromOleDbType((short)r[colNames[(int)ProcParamsColIndex.DataType]], ADP.IsNull(r[colNames[(int)ProcParamsColIndex.TypeName]]) ? - ADP.StrEmpty : + string.Empty : (string)r[colNames[(int)ProcParamsColIndex.TypeName]]); } diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs index 2c57b26..f6f6104 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlEnums.cs @@ -700,7 +700,7 @@ namespace System.Data.SqlClient // store on TdsEnums instead of SqlDbType because we do not want to expose // this type to the user. private static readonly MetaType s_metaSmallVarBinary = new MetaType - (255, 255, -1, false, false, false, TdsEnums.SQLVARBINARY, TdsEnums.SQLBIGBINARY, ADP.StrEmpty, typeof(byte[]), typeof(SqlBinary), TdsEnums.SmallVarBinary, DbType.Binary, 2); + (255, 255, -1, false, false, false, TdsEnums.SQLVARBINARY, TdsEnums.SQLBIGBINARY, string.Empty, typeof(byte[]), typeof(SqlBinary), TdsEnums.SmallVarBinary, DbType.Binary, 2); internal static readonly MetaType MetaImage = new MetaType (255, 255, -1, false, true, false, TdsEnums.SQLIMAGE, TdsEnums.SQLIMAGE, MetaTypeName.IMAGE, typeof(byte[]), typeof(SqlBinary), SqlDbType.Image, DbType.Binary, 0); diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameter.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameter.cs index d2d8fa5..5683348 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameter.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameter.cs @@ -257,7 +257,7 @@ namespace System.Data.SqlClient { get { - return (_xmlSchemaCollection?.Database ?? ADP.StrEmpty); + return (_xmlSchemaCollection?.Database ?? string.Empty); } set { @@ -277,7 +277,7 @@ namespace System.Data.SqlClient { get { - return (_xmlSchemaCollection?.OwningSchema ?? ADP.StrEmpty); + return (_xmlSchemaCollection?.OwningSchema ?? string.Empty); } set { @@ -297,7 +297,7 @@ namespace System.Data.SqlClient { get { - return (_xmlSchemaCollection?.Name ?? ADP.StrEmpty); + return (_xmlSchemaCollection?.Name ?? string.Empty); } set { @@ -556,7 +556,7 @@ namespace System.Data.SqlClient get { string parameterName = _parameterName; - return (parameterName ?? ADP.StrEmpty); + return (parameterName ?? string.Empty); } set { @@ -765,7 +765,7 @@ namespace System.Data.SqlClient get { string typeName = _udtTypeName; - return (typeName ?? ADP.StrEmpty); + return (typeName ?? string.Empty); } set { @@ -775,7 +775,7 @@ namespace System.Data.SqlClient public string TypeName { - get => (_typeName ?? ADP.StrEmpty); + get => (_typeName ?? string.Empty); set { _typeName = value; diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameterHelper.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameterHelper.cs index e239d4c..7698581 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameterHelper.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlParameterHelper.cs @@ -107,7 +107,7 @@ namespace System.Data.SqlClient public override string SourceColumn { - get => (_sourceColumn ?? ADP.StrEmpty); + get => (_sourceColumn ?? string.Empty); set => _sourceColumn = value; } diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs index b22c8fc..37f27d8 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/TdsParser.cs @@ -19,7 +19,6 @@ using MSS = Microsoft.SqlServer.Server; namespace System.Data.SqlClient { - internal struct SNIErrorDetails { public string errorMessage; @@ -4466,7 +4465,7 @@ namespace System.Data.SqlClient } else { - s = ADP.StrEmpty; + s = string.Empty; } } else @@ -5742,7 +5741,7 @@ namespace System.Data.SqlClient internal int GetEncodingCharLength(string value, int numChars, int charOffset, Encoding encoding) { - if (value == null || value == ADP.StrEmpty) + if (value == null || value == string.Empty) { return 0; } @@ -7602,13 +7601,13 @@ namespace System.Data.SqlClient if (_isYukon && (mt.SqlDbType == SqlDbType.Xml)) { - if (((param.XmlSchemaCollectionDatabase != null) && (param.XmlSchemaCollectionDatabase != ADP.StrEmpty)) || - ((param.XmlSchemaCollectionOwningSchema != null) && (param.XmlSchemaCollectionOwningSchema != ADP.StrEmpty)) || - ((param.XmlSchemaCollectionName != null) && (param.XmlSchemaCollectionName != ADP.StrEmpty))) + if (((param.XmlSchemaCollectionDatabase != null) && (param.XmlSchemaCollectionDatabase != string.Empty)) || + ((param.XmlSchemaCollectionOwningSchema != null) && (param.XmlSchemaCollectionOwningSchema != string.Empty)) || + ((param.XmlSchemaCollectionName != null) && (param.XmlSchemaCollectionName != string.Empty))) { stateObj.WriteByte(1); //Schema present flag - if ((param.XmlSchemaCollectionDatabase != null) && (param.XmlSchemaCollectionDatabase != ADP.StrEmpty)) + if ((param.XmlSchemaCollectionDatabase != null) && (param.XmlSchemaCollectionDatabase != string.Empty)) { tempLen = (param.XmlSchemaCollectionDatabase).Length; stateObj.WriteByte((byte)(tempLen)); @@ -7619,7 +7618,7 @@ namespace System.Data.SqlClient stateObj.WriteByte(0); // No dbname } - if ((param.XmlSchemaCollectionOwningSchema != null) && (param.XmlSchemaCollectionOwningSchema != ADP.StrEmpty)) + if ((param.XmlSchemaCollectionOwningSchema != null) && (param.XmlSchemaCollectionOwningSchema != string.Empty)) { tempLen = (param.XmlSchemaCollectionOwningSchema).Length; stateObj.WriteByte((byte)(tempLen)); @@ -7630,7 +7629,7 @@ namespace System.Data.SqlClient stateObj.WriteByte(0); // no xml schema name } - if ((param.XmlSchemaCollectionName != null) && (param.XmlSchemaCollectionName != ADP.StrEmpty)) + if ((param.XmlSchemaCollectionName != null) && (param.XmlSchemaCollectionName != string.Empty)) { tempLen = (param.XmlSchemaCollectionName).Length; WriteShort((short)(tempLen), stateObj); diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs index 49e777a..29e886e 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/InternalRelationshipCollection.cs @@ -263,7 +263,7 @@ namespace System.IO.Packaging // Make sure that the current node read is an Element if (reader.NodeType == XmlNodeType.Element && (reader.Depth == 0) - && (string.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0) + && (string.CompareOrdinal(RelationshipsTagName, reader.LocalName) == 0) && (string.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0)) { ThrowIfXmlBaseAttributeIsPresent(reader); @@ -287,14 +287,14 @@ namespace System.IO.Packaging if (reader.NodeType == XmlNodeType.Element && (reader.Depth == 1) - && (string.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0) + && (string.CompareOrdinal(RelationshipTagName, reader.LocalName) == 0) && (string.CompareOrdinal(PackagingUtilities.RelationshipNamespaceUri, reader.NamespaceURI) == 0)) { ThrowIfXmlBaseAttributeIsPresent(reader); int expectedAttributesCount = 3; - string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName); + string targetModeAttributeValue = reader.GetAttribute(TargetModeAttributeName); if (targetModeAttributeValue != null) expectedAttributesCount++; @@ -314,7 +314,7 @@ namespace System.IO.Packaging } } else - if (!(string.CompareOrdinal(s_relationshipsTagName, reader.LocalName) == 0 && (reader.NodeType == XmlNodeType.EndElement))) + if (!(string.CompareOrdinal(RelationshipsTagName, reader.LocalName) == 0 && (reader.NodeType == XmlNodeType.EndElement))) throw new XmlException(SR.UnknownTagEncountered, null, reader.LineNumber, reader.LinePosition); } } @@ -330,7 +330,7 @@ namespace System.IO.Packaging { // Attribute : TargetMode - string targetModeAttributeValue = reader.GetAttribute(s_targetModeAttributeName); + string targetModeAttributeValue = reader.GetAttribute(TargetModeAttributeName); //If the TargetMode attribute is missing in the underlying markup then we assume it to be internal TargetMode relationshipTargetMode = TargetMode.Internal; @@ -343,33 +343,33 @@ namespace System.IO.Packaging } catch (ArgumentNullException argNullEx) { - ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argNullEx); + ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argNullEx); } catch (ArgumentException argEx) { //if the targetModeAttributeValue is not Internal|External then Argument Exception will be thrown. - ThrowForInvalidAttributeValue(reader, s_targetModeAttributeName, argEx); + ThrowForInvalidAttributeValue(reader, TargetModeAttributeName, argEx); } } // Attribute : Target // create a new PackageRelationship - string targetAttributeValue = reader.GetAttribute(s_targetAttributeName); + string targetAttributeValue = reader.GetAttribute(TargetAttributeName); if (string.IsNullOrEmpty(targetAttributeValue)) - throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_targetAttributeName), null, reader.LineNumber, reader.LinePosition); + throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TargetAttributeName), null, reader.LineNumber, reader.LinePosition); Uri targetUri = new Uri(targetAttributeValue, DotNetRelativeOrAbsolute); // Attribute : Type - string typeAttributeValue = reader.GetAttribute(s_typeAttributeName); + string typeAttributeValue = reader.GetAttribute(TypeAttributeName); if (string.IsNullOrEmpty(typeAttributeValue)) - throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_typeAttributeName), null, reader.LineNumber, reader.LinePosition); + throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, TypeAttributeName), null, reader.LineNumber, reader.LinePosition); // Attribute : Id // Get the Id attribute (required attribute). - string idAttributeValue = reader.GetAttribute(s_idAttributeName); + string idAttributeValue = reader.GetAttribute(IdAttributeName); if (string.IsNullOrEmpty(idAttributeValue)) - throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, s_idAttributeName), null, reader.LineNumber, reader.LinePosition); + throw new XmlException(SR.Format(SR.RequiredRelationshipAttributeMissing, IdAttributeName), null, reader.LineNumber, reader.LinePosition); // Add the relationship to the collection Add(targetUri, relationshipTargetMode, typeAttributeValue, idAttributeValue, parsing: true); @@ -385,10 +385,10 @@ namespace System.IO.Packaging //Skips over the following - ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace reader.MoveToContent(); - if (reader.NodeType == XmlNodeType.EndElement && string.CompareOrdinal(s_relationshipTagName, reader.LocalName) == 0) + if (reader.NodeType == XmlNodeType.EndElement && string.CompareOrdinal(RelationshipTagName, reader.LocalName) == 0) return; else - throw new XmlException(SR.Format(SR.ElementIsNotEmptyElement, s_relationshipTagName), null, reader.LineNumber, reader.LinePosition); + throw new XmlException(SR.Format(SR.ElementIsNotEmptyElement, RelationshipTagName), null, reader.LineNumber, reader.LinePosition); } @@ -477,7 +477,7 @@ namespace System.IO.Packaging writer.WriteStartDocument(); // start outer Relationships tag - writer.WriteStartElement(s_relationshipsTagName, PackagingUtilities.RelationshipNamespaceUri); + writer.WriteStartElement(RelationshipsTagName, PackagingUtilities.RelationshipNamespaceUri); // Write Relationship elements. WriteRelationshipsAsXml( @@ -503,10 +503,10 @@ namespace System.IO.Packaging { foreach (PackageRelationship relationship in relationships) { - writer.WriteStartElement(s_relationshipTagName); + writer.WriteStartElement(RelationshipTagName); // Write RelationshipType attribute. - writer.WriteAttributeString(s_typeAttributeName, relationship.RelationshipType); + writer.WriteAttributeString(TypeAttributeName, relationship.RelationshipType); // Write Target attribute. // We would like to persist the uri as passed in by the user and so we use the @@ -516,14 +516,14 @@ namespace System.IO.Packaging // the string can be converted to a valid Uri. // Also, we are just using it here to persist the information and we are not // resolving or fetching a resource based on this Uri. - writer.WriteAttributeString(s_targetAttributeName, relationship.TargetUri.OriginalString); + writer.WriteAttributeString(TargetAttributeName, relationship.TargetUri.OriginalString); // TargetMode is optional attribute in the markup and its default value is TargetMode="Internal" if (alwaysWriteTargetModeAttribute || relationship.TargetMode == TargetMode.External) - writer.WriteAttributeString(s_targetModeAttributeName, relationship.TargetMode.ToString()); + writer.WriteAttributeString(TargetModeAttributeName, relationship.TargetMode.ToString()); // Write Id attribute. - writer.WriteAttributeString(s_idAttributeName, relationship.Id); + writer.WriteAttributeString(IdAttributeName, relationship.Id); writer.WriteEndElement(); } @@ -581,10 +581,10 @@ namespace System.IO.Packaging //Throws an exception if the xml:base attribute is present in the Relationships XML private void ThrowIfXmlBaseAttributeIsPresent(XmlCompatibilityReader reader) { - string xmlBaseAttributeValue = reader.GetAttribute(s_xmlBaseAttributeName); + string xmlBaseAttributeValue = reader.GetAttribute(XmlBaseAttributeName); if (xmlBaseAttributeValue != null) - throw new XmlException(SR.Format(SR.InvalidXmlBaseAttributePresent, s_xmlBaseAttributeName), null, reader.LineNumber, reader.LinePosition); + throw new XmlException(SR.Format(SR.InvalidXmlBaseAttributePresent, XmlBaseAttributeName), null, reader.LineNumber, reader.LinePosition); } //Throws an XML exception if the attribute value is invalid @@ -609,7 +609,7 @@ namespace System.IO.Packaging private string GenerateRelationshipId() { // The timestamp consists of the first 8 hex octets of the GUID. - return string.Concat("R", Guid.NewGuid().ToString("N").Substring(0, s_timestampLength)); + return string.Concat("R", Guid.NewGuid().ToString("N").Substring(0, TimestampLength)); } // If 'id' is not of the xsd type ID or is not unique for this collection, throw an exception. @@ -656,15 +656,15 @@ namespace System.IO.Packaging //------------------------------------------------------ // segment that indicates a relationship part - private static readonly int s_timestampLength = 16; + private const int TimestampLength = 16; - private static readonly string s_relationshipsTagName = "Relationships"; - private static readonly string s_relationshipTagName = "Relationship"; - private static readonly string s_targetAttributeName = "Target"; - private static readonly string s_typeAttributeName = "Type"; - private static readonly string s_idAttributeName = "Id"; - private static readonly string s_xmlBaseAttributeName = "xml:base"; - private static readonly string s_targetModeAttributeName = "TargetMode"; + private const string RelationshipsTagName = "Relationships"; + private const string RelationshipTagName = "Relationship"; + private const string TargetAttributeName = "Target"; + private const string TypeAttributeName = "Type"; + private const string IdAttributeName = "Id"; + private const string XmlBaseAttributeName = "xml:base"; + private const string TargetModeAttributeName = "TargetMode"; private static readonly string[] s_relationshipKnownNamespaces = new string[] { PackagingUtilities.RelationshipNamespaceUri }; diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs index 2a1f8f1..ca788a4 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackUriHelper.cs @@ -225,9 +225,9 @@ namespace System.IO.Packaging // Get the partname without the last segment partName = partName.Substring(0, partName.Length - file.Length); - partName = Path.Combine(partName, s_relationshipPartSegmentName, file); // Adding the "_rels" segment and the last segment back + partName = Path.Combine(partName, RelationshipPartSegmentName, file); // Adding the "_rels" segment and the last segment back partName = partName.Replace(BackwardSlashChar, ForwardSlashChar); - partName += s_relationshipPartExtensionName; // Adding the ".rels" extension + partName += RelationshipPartExtensionName; // Adding the ".rels" extension // convert to Uri - We could use PackUriHelper.Create, but since we know that this is a //valid Part Uri we can just call the Uri constructor. @@ -276,16 +276,16 @@ namespace System.IO.Packaging string partNameWithoutExtension = Path.GetFileNameWithoutExtension(path); - Debug.Assert((path.Length - partNameWithoutExtension.Length - s_relationshipPartExtensionName.Length - 1) > 0, + Debug.Assert((path.Length - partNameWithoutExtension.Length - RelationshipPartExtensionName.Length - 1) > 0, "The partname may not be well-formed"); //Get the part name without the last segment - path = path.Substring(0, path.Length - partNameWithoutExtension.Length - s_relationshipPartExtensionName.Length - 1); + path = path.Substring(0, path.Length - partNameWithoutExtension.Length - RelationshipPartExtensionName.Length - 1); - Debug.Assert((path.Length - s_relationshipPartSegmentName.Length) > 0, + Debug.Assert((path.Length - RelationshipPartSegmentName.Length) > 0, "The partname may not be well-formed"); - path = path.Substring(0, path.Length - s_relationshipPartSegmentName.Length); // Removing rels segment + path = path.Substring(0, path.Length - RelationshipPartSegmentName.Length); // Removing rels segment path = Path.Combine(path, partNameWithoutExtension); // Adding the last segment without ".rels" extension path = path.Replace(BackwardSlashChar, ForwardSlashChar); @@ -595,15 +595,15 @@ namespace System.IO.Packaging private static readonly char[] s_specialCharacterChars = { '%', '@', ',', '?' }; //Rels segment and extension - private static readonly string s_relationshipPartSegmentName = "_rels"; - private static readonly string s_relationshipPartExtensionName = ".rels"; + private const string RelationshipPartSegmentName = "_rels"; + private const string RelationshipPartExtensionName = ".rels"; // Forward Slash internal const char ForwardSlashChar = '/'; internal static readonly char[] s_forwardSlashCharArray = { ForwardSlashChar }; // Backward Slash - internal static readonly char BackwardSlashChar = '\\'; + internal const char BackwardSlashChar = '\\'; /// /// pack scheme name @@ -795,7 +795,7 @@ namespace System.IO.Packaging bool result = false; //exit early if the partUri does not end with the relationship extension - if (!NormalizedPartUriString.EndsWith(s_relationshipPartUpperCaseExtension, StringComparison.Ordinal)) + if (!NormalizedPartUriString.EndsWith(RelationshipPartUpperCaseExtension, StringComparison.Ordinal)) return false; // if uri is /_rels/.rels then we return true @@ -819,25 +819,25 @@ namespace System.IO.Packaging Debug.Assert(segments.Length > 0 && segments[0] == string.Empty); //If the extension was not equal to .rels, we would have exited early. - Debug.Assert(string.CompareOrdinal((Path.GetExtension(segments[segments.Length - 1])), s_relationshipPartUpperCaseExtension) == 0); + Debug.Assert(string.CompareOrdinal((Path.GetExtension(segments[segments.Length - 1])), RelationshipPartUpperCaseExtension) == 0); // must be at least two segments and the last one must end with .RELs // and the length of the segment should be greater than just the extension. if ((segments.Length >= 3) && - (segments[segments.Length - 1].Length > s_relationshipPartExtensionName.Length)) + (segments[segments.Length - 1].Length > RelationshipPartExtensionName.Length)) { // look for "_RELS" segment which must be second last segment - result = (string.CompareOrdinal(segments[segments.Length - 2], s_relationshipPartUpperCaseSegmentName) == 0); + result = (string.CompareOrdinal(segments[segments.Length - 2], RelationshipPartUpperCaseSegmentName) == 0); } // In addition we need to make sure that the relationship is not created by taking another relationship // as the source of this uri. So XXX/_rels/_rels/YYY.rels.rels would be invalid. if (segments.Length > 3 && result == true) { - if ((segments[segments.Length - 1]).EndsWith(s_relsrelsUpperCaseExtension, StringComparison.Ordinal)) + if ((segments[segments.Length - 1]).EndsWith(RelsrelsUpperCaseExtension, StringComparison.Ordinal)) { // look for "_rels" segment in the third last segment - if (string.CompareOrdinal(segments[segments.Length - 3], s_relationshipPartUpperCaseSegmentName) == 0) + if (string.CompareOrdinal(segments[segments.Length - 3], RelationshipPartUpperCaseSegmentName) == 0) throw new ArgumentException(SR.NotAValidRelationshipPartUri); } } @@ -895,9 +895,9 @@ namespace System.IO.Packaging //String Uppercase variants - private static readonly string s_relationshipPartUpperCaseExtension = ".RELS"; - private static readonly string s_relationshipPartUpperCaseSegmentName = "_RELS"; - private static readonly string s_relsrelsUpperCaseExtension = string.Concat(s_relationshipPartUpperCaseExtension, s_relationshipPartUpperCaseExtension); + private const string RelationshipPartUpperCaseExtension = ".RELS"; + private const string RelationshipPartUpperCaseSegmentName = "_RELS"; + private const string RelsrelsUpperCaseExtension = RelationshipPartUpperCaseExtension + RelationshipPartUpperCaseExtension; //need to use the private constructor to initialize this particular partUri as we need this in the //IsRelationshipPartUri, that is called from the constructor. diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs index 28808ad..8826e07 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/PackagingUtilities.cs @@ -12,7 +12,7 @@ namespace System.IO.Packaging { internal static class PackagingUtilities { - internal static readonly string RelationshipNamespaceUri = "http://schemas.openxmlformats.org/package/2006/relationships"; + internal const string RelationshipNamespaceUri = "http://schemas.openxmlformats.org/package/2006/relationships"; internal static readonly ContentType RelationshipPartContentType = new ContentType("application/vnd.openxmlformats-package.relationships+xml"); diff --git a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs index 05ba78f..d9a2d3e 100644 --- a/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs +++ b/src/libraries/System.IO.Packaging/src/System/IO/Packaging/ZipPackage.cs @@ -560,7 +560,7 @@ namespace System.IO.Packaging _zipStreamManager = zipStreamManager; //initialized in the ZipPackage constructor // The extensions are stored in the default Dictionary in their original form , but they are compared // in a normalized manner using the ExtensionComparer. - _defaultDictionary = new Dictionary(s_defaultDictionaryInitialSize, s_extensionEqualityComparer); + _defaultDictionary = new Dictionary(DefaultDictionaryInitialSize, s_extensionEqualityComparer); // Identify the content type file or files before identifying parts and piece sequences. // This is necessary because the name of the content type stream is not a part name and @@ -582,7 +582,7 @@ namespace System.IO.Packaging { get { - return s_contentTypesFile; + return ContentTypesFile; } } @@ -666,7 +666,7 @@ namespace System.IO.Packaging //Lazy init: Initialize when the first part is added. if (!_contentTypeStreamExists) { - _contentTypeZipArchiveEntry = _zipArchive.CreateEntry(s_contentTypesFile, _cachedCompressionLevel); + _contentTypeZipArchiveEntry = _zipArchive.CreateEntry(ContentTypesFile, _cachedCompressionLevel); _contentTypeStreamExists = true; } else @@ -688,7 +688,7 @@ namespace System.IO.Packaging writer.WriteStartDocument(); // write root element tag - Types - writer.WriteStartElement(s_typesTagName, s_typesNamespaceUri); + writer.WriteStartElement(TypesTagName, TypesNamespaceUri); // for each default entry foreach (string key in _defaultDictionary.Keys) @@ -722,7 +722,7 @@ namespace System.IO.Packaging // The part Uris are stored in the Override Dictionary in their original form , but they are compared // in a normalized manner using the PartUriComparer if (_overrideDictionary == null) - _overrideDictionary = new Dictionary(s_overrideDictionaryInitialSize); + _overrideDictionary = new Dictionary(OverrideDictionaryInitialSize); } private void ParseContentTypesFile(System.Collections.ObjectModel.ReadOnlyCollection zipFiles) @@ -754,8 +754,8 @@ namespace System.IO.Packaging // Make sure that the current node read is an Element if ((reader.NodeType == XmlNodeType.Element) && (reader.Depth == 0) - && (string.CompareOrdinal(reader.NamespaceURI, s_typesNamespaceUri) == 0) - && (string.CompareOrdinal(reader.Name, s_typesTagName) == 0)) + && (string.CompareOrdinal(reader.NamespaceURI, TypesNamespaceUri) == 0) + && (string.CompareOrdinal(reader.Name, TypesTagName) == 0)) { //There should be a namespace Attribute present at this level. //Also any other attribute on the tag is an error including xml: and xsi: attributes @@ -780,21 +780,21 @@ namespace System.IO.Packaging // Currently we expect the Default and Override Tag at Depth 1 if (reader.NodeType == XmlNodeType.Element && reader.Depth == 1 - && (string.CompareOrdinal(reader.NamespaceURI, s_typesNamespaceUri) == 0) - && (string.CompareOrdinal(reader.Name, s_defaultTagName) == 0)) + && (string.CompareOrdinal(reader.NamespaceURI, TypesNamespaceUri) == 0) + && (string.CompareOrdinal(reader.Name, DefaultTagName) == 0)) { ProcessDefaultTagAttributes(reader); } else if (reader.NodeType == XmlNodeType.Element && reader.Depth == 1 - && (string.CompareOrdinal(reader.NamespaceURI, s_typesNamespaceUri) == 0) - && (string.CompareOrdinal(reader.Name, s_overrideTagName) == 0)) + && (string.CompareOrdinal(reader.NamespaceURI, TypesNamespaceUri) == 0) + && (string.CompareOrdinal(reader.Name, OverrideTagName) == 0)) { ProcessOverrideTagAttributes(reader); } else - if (reader.NodeType == XmlNodeType.EndElement && reader.Depth == 0 && string.CompareOrdinal(reader.Name, s_typesTagName) == 0) + if (reader.NodeType == XmlNodeType.EndElement && reader.Depth == 0 && string.CompareOrdinal(reader.Name, TypesTagName) == 0) continue; else { @@ -821,7 +821,7 @@ namespace System.IO.Packaging { foreach (ZipArchiveEntry zipFileInfo in zipFiles) { - if (zipFileInfo.Name.ToUpperInvariant().StartsWith(s_contentTypesFileUpperInvariant, StringComparison.Ordinal)) + if (zipFileInfo.Name.ToUpperInvariant().StartsWith(ContentTypesFileUpperInvariant, StringComparison.Ordinal)) { // Atomic name. if (zipFileInfo.Name.Length == ContentTypeFileName.Length) @@ -854,21 +854,21 @@ namespace System.IO.Packaging // get the required Extension and ContentType attributes - string extensionAttributeValue = reader.GetAttribute(s_extensionAttributeName); - ValidateXmlAttribute(s_extensionAttributeName, extensionAttributeValue, s_defaultTagName, reader); + string extensionAttributeValue = reader.GetAttribute(ExtensionAttributeName); + ValidateXmlAttribute(ExtensionAttributeName, extensionAttributeValue, DefaultTagName, reader); - string contentTypeAttributeValue = reader.GetAttribute(s_contentTypeAttributeName); - ThrowIfXmlAttributeMissing(s_contentTypeAttributeName, contentTypeAttributeValue, s_defaultTagName, reader); + string contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); + ThrowIfXmlAttributeMissing(ContentTypeAttributeName, contentTypeAttributeValue, DefaultTagName, reader); // The extensions are stored in the Default Dictionary in their original form , but they are compared // in a normalized manner using the ExtensionComparer. PackUriHelper.ValidatedPartUri temporaryUri = PackUriHelper.ValidatePartUri( - new Uri(s_temporaryPartNameWithoutExtension + extensionAttributeValue, UriKind.Relative)); + new Uri(TemporaryPartNameWithoutExtension + extensionAttributeValue, UriKind.Relative)); _defaultDictionary.Add(temporaryUri.PartUriExtension, new ContentType(contentTypeAttributeValue)); //Skip the EndElement for Default Tag if (!reader.IsEmptyElement) - ProcessEndElement(reader, s_defaultTagName); + ProcessEndElement(reader, DefaultTagName); } // Process the attributes for the Default tag @@ -881,11 +881,11 @@ namespace System.IO.Packaging // get the required Extension and ContentType attributes - string partNameAttributeValue = reader.GetAttribute(s_partNameAttributeName); - ValidateXmlAttribute(s_partNameAttributeName, partNameAttributeValue, s_overrideTagName, reader); + string partNameAttributeValue = reader.GetAttribute(PartNameAttributeName); + ValidateXmlAttribute(PartNameAttributeName, partNameAttributeValue, OverrideTagName, reader); - string contentTypeAttributeValue = reader.GetAttribute(s_contentTypeAttributeName); - ThrowIfXmlAttributeMissing(s_contentTypeAttributeName, contentTypeAttributeValue, s_overrideTagName, reader); + string contentTypeAttributeValue = reader.GetAttribute(ContentTypeAttributeName); + ThrowIfXmlAttributeMissing(ContentTypeAttributeName, contentTypeAttributeValue, OverrideTagName, reader); PackUriHelper.ValidatedPartUri partUri = PackUriHelper.ValidatePartUri(new Uri(partNameAttributeValue, UriKind.Relative)); @@ -898,7 +898,7 @@ namespace System.IO.Packaging //Skip the EndElement for Override Tag if (!reader.IsEmptyElement) - ProcessEndElement(reader, s_overrideTagName); + ProcessEndElement(reader, OverrideTagName); } //If End element is present for Relationship then we process it @@ -944,18 +944,18 @@ namespace System.IO.Packaging private void WriteOverrideElement(XmlWriter xmlWriter, PackUriHelper.ValidatedPartUri partUri, ContentType contentType) { - xmlWriter.WriteStartElement(s_overrideTagName); - xmlWriter.WriteAttributeString(s_partNameAttributeName, + xmlWriter.WriteStartElement(OverrideTagName); + xmlWriter.WriteAttributeString(PartNameAttributeName, partUri.PartUriString); - xmlWriter.WriteAttributeString(s_contentTypeAttributeName, contentType.ToString()); + xmlWriter.WriteAttributeString(ContentTypeAttributeName, contentType.ToString()); xmlWriter.WriteEndElement(); } private void WriteDefaultElement(XmlWriter xmlWriter, string extension, ContentType contentType) { - xmlWriter.WriteStartElement(s_defaultTagName); - xmlWriter.WriteAttributeString(s_extensionAttributeName, extension); - xmlWriter.WriteAttributeString(s_contentTypeAttributeName, contentType.ToString()); + xmlWriter.WriteStartElement(DefaultTagName); + xmlWriter.WriteAttributeString(ExtensionAttributeName, extension); + xmlWriter.WriteAttributeString(ContentTypeAttributeName, contentType.ToString()); xmlWriter.WriteEndElement(); } @@ -988,21 +988,20 @@ namespace System.IO.Packaging private bool _contentTypeStreamExists; private bool _dirty; private CompressionLevel _cachedCompressionLevel; - private static readonly string s_contentTypesFile = "[Content_Types].xml"; - private static readonly string s_contentTypesFileUpperInvariant = "[CONTENT_TYPES].XML"; - private static readonly int s_defaultDictionaryInitialSize = 16; - private static readonly int s_overrideDictionaryInitialSize = 8; - + private const string ContentTypesFile = "[Content_Types].xml"; + private const string ContentTypesFileUpperInvariant = "[CONTENT_TYPES].XML"; + private const int DefaultDictionaryInitialSize = 16; + private const int OverrideDictionaryInitialSize = 8; //Xml tag specific strings for the Content Type file - private static readonly string s_typesNamespaceUri = "http://schemas.openxmlformats.org/package/2006/content-types"; - private static readonly string s_typesTagName = "Types"; - private static readonly string s_defaultTagName = "Default"; - private static readonly string s_extensionAttributeName = "Extension"; - private static readonly string s_contentTypeAttributeName = "ContentType"; - private static readonly string s_overrideTagName = "Override"; - private static readonly string s_partNameAttributeName = "PartName"; - private static readonly string s_temporaryPartNameWithoutExtension = "/tempfiles/sample."; + private const string TypesNamespaceUri = "http://schemas.openxmlformats.org/package/2006/content-types"; + private const string TypesTagName = "Types"; + private const string DefaultTagName = "Default"; + private const string ExtensionAttributeName = "Extension"; + private const string ContentTypeAttributeName = "ContentType"; + private const string OverrideTagName = "Override"; + private const string PartNameAttributeName = "PartName"; + private const string TemporaryPartNameWithoutExtension = "/tempfiles/sample."; } } } diff --git a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs index 77b9396..3a3486a 100644 --- a/src/libraries/System.Management/src/System/Management/ManagementQuery.cs +++ b/src/libraries/System.Management/src/System/Management/ManagementQuery.cs @@ -23,7 +23,7 @@ namespace System.Management public abstract class ManagementQuery : ICloneable { internal const string DEFAULTQUERYLANGUAGE = "WQL"; - internal static readonly string tokenSelect = "select "; // Keep trailing space char. + internal const string TokenSelect = "select "; // Keep trailing space char. //Used when any public property on this object is changed, to signal //to the containing object that it needs to be refreshed. @@ -657,7 +657,7 @@ namespace System.Management { // Minimally determine if the string is a query or class name. // - if (queryOrClassName.TrimStart().StartsWith(tokenSelect, StringComparison.OrdinalIgnoreCase)) + if (queryOrClassName.TrimStart().StartsWith(TokenSelect, StringComparison.OrdinalIgnoreCase)) { // Looks to be a query - do further checking. // @@ -915,7 +915,7 @@ namespace System.Management return; //Select clause - s = tokenSelect; + s = TokenSelect; //If properties are specified list them if ((null != selectedProperties) && (0 < selectedProperties.Count)) @@ -968,7 +968,7 @@ namespace System.Management if (isSchemaQuery == false) //instances query { //Find "select" clause and get the property list if exists - string keyword = tokenSelect; + string keyword = TokenSelect; if ((q.Length >= keyword.Length) && (string.Compare(q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase) == 0)) //select clause found { ParseToken (ref q, keyword, ref bFound); @@ -1175,17 +1175,17 @@ namespace System.Management //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC// public class RelatedObjectQuery : WqlObjectQuery { - private static readonly string tokenAssociators = "associators"; - private static readonly string tokenOf = "of"; - private static readonly string tokenWhere = "where"; - private static readonly string tokenResultClass = "resultclass"; - private static readonly string tokenAssocClass = "assocclass"; - private static readonly string tokenResultRole = "resultrole"; - private static readonly string tokenRole = "role"; - private static readonly string tokenRequiredQualifier = "requiredqualifier"; - private static readonly string tokenRequiredAssocQualifier = "requiredassocqualifier"; - private static readonly string tokenClassDefsOnly = "classdefsonly"; - private static readonly string tokenSchemaOnly = "schemaonly"; + private const string TokenAssociators = "associators"; + private const string TokenOf = "of"; + private const string TokenWhere = "where"; + private const string TokenResultClass = "resultclass"; + private const string TokenAssocClass = "assocclass"; + private const string TokenResultRole = "resultrole"; + private const string TokenRole = "role"; + private const string TokenRequiredQualifier = "requiredqualifier"; + private const string TokenRequiredAssocQualifier = "requiredassocqualifier"; + private const string TokenClassDefsOnly = "classdefsonly"; + private const string TokenSchemaOnly = "schemaonly"; private bool isSchemaQuery; private string sourceObject; @@ -1250,7 +1250,7 @@ namespace System.Management { // Minimally determine if the string is a query or instance name. // - if (queryOrSourceObject.TrimStart().StartsWith(tokenAssociators, StringComparison.OrdinalIgnoreCase)) + if (queryOrSourceObject.TrimStart().StartsWith(TokenAssociators, StringComparison.OrdinalIgnoreCase)) { // Looks to be a query - do further checking. // @@ -1562,7 +1562,7 @@ namespace System.Management return; //"associators" clause - string s = tokenAssociators + " " + tokenOf + " {" + sourceObject + "}"; + string s = TokenAssociators + " " + TokenOf + " {" + sourceObject + "}"; //If any of the other parameters are set we need a "where" clause if (!(RelatedClass.Length==0) || @@ -1574,40 +1574,40 @@ namespace System.Management classDefinitionsOnly || isSchemaQuery) { - s = s + " " + tokenWhere; + s = s + " " + TokenWhere; //"ResultClass" if (!(RelatedClass.Length==0)) - s = s + " " + tokenResultClass + " = " + relatedClass; + s = s + " " + TokenResultClass + " = " + relatedClass; //"AssocClass" if (!(RelationshipClass.Length==0)) - s = s + " " + tokenAssocClass + " = " + relationshipClass; + s = s + " " + TokenAssocClass + " = " + relationshipClass; //"ResultRole" if (!(RelatedRole.Length==0)) - s = s + " " + tokenResultRole + " = " + relatedRole; + s = s + " " + TokenResultRole + " = " + relatedRole; //"Role" if (!(ThisRole.Length==0)) - s = s + " " + tokenRole + " = " + thisRole; + s = s + " " + TokenRole + " = " + thisRole; //"RequiredQualifier" if (!(RelatedQualifier.Length==0)) - s = s + " " + tokenRequiredQualifier + " = " + relatedQualifier; + s = s + " " + TokenRequiredQualifier + " = " + relatedQualifier; //"RequiredAssocQualifier" if (!(RelationshipQualifier.Length==0)) - s = s + " " + tokenRequiredAssocQualifier + " = " + relationshipQualifier; + s = s + " " + TokenRequiredAssocQualifier + " = " + relationshipQualifier; //"SchemaOnly" and "ClassDefsOnly" if (!isSchemaQuery) //this is an instance query - classDefs allowed { if (classDefinitionsOnly) - s = s + " " + tokenClassDefsOnly; + s = s + " " + TokenClassDefsOnly; } else //this is a schema query, schemaonly required - s = s + " " + tokenSchemaOnly; + s = s + " " + TokenSchemaOnly; } //Set the queryString member to the built query (NB: note we set @@ -1640,11 +1640,11 @@ namespace System.Management int i; //Find "associators" clause - if (0 != string.Compare(q, 0, tokenAssociators, 0, tokenAssociators.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare(q, 0, TokenAssociators, 0, TokenAssociators.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"associators"); // Invalid query // Strip off the clause - q = q.Remove(0, tokenAssociators.Length); + q = q.Remove(0, TokenAssociators.Length); // Must be some white space next if ((0 == q.Length) || !char.IsWhiteSpace (q[0])) @@ -1653,11 +1653,11 @@ namespace System.Management q = q.TrimStart(null); // Remove the leading whitespace // Next token should be "of" - if (0 != string.Compare(q, 0, tokenOf, 0, tokenOf.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare(q, 0, TokenOf, 0, TokenOf.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"of"); // Invalid query // Strip off the clause and leading WS - q = q.Remove(0, tokenOf.Length).TrimStart (null); + q = q.Remove(0, TokenOf.Length).TrimStart (null); // Next character should be "{" if (0 != q.IndexOf('{')) @@ -1677,10 +1677,10 @@ namespace System.Management if (0 < q.Length) { // Next should be the "where" clause - if (0 != string.Compare (q, 0, tokenWhere, 0, tokenWhere.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare (q, 0, TokenWhere, 0, TokenWhere.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"where"); // Invalid query - q = q.Remove (0, tokenWhere.Length); + q = q.Remove (0, TokenWhere.Length); // Must be some white space next if ((0 == q.Length) || !char.IsWhiteSpace (q[0])) @@ -1701,26 +1701,26 @@ namespace System.Management // Keep looking for tokens until we are done while (true) { - if ((q.Length >= tokenResultClass.Length) && (0 == string.Compare (q, 0, tokenResultClass, 0, tokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenResultClass, "=", ref bResultClassFound, ref tempRelatedClass); - else if ((q.Length >= tokenAssocClass.Length) && (0 == string.Compare (q, 0, tokenAssocClass, 0, tokenAssocClass.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenAssocClass, "=", ref bAssocClassFound, ref tempRelationshipClass); - else if ((q.Length >= tokenResultRole.Length) && (0 == string.Compare (q, 0, tokenResultRole, 0, tokenResultRole.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenResultRole, "=", ref bResultRoleFound, ref tempRelatedRole); - else if ((q.Length >= tokenRole.Length) && (0 == string.Compare (q, 0, tokenRole, 0, tokenRole.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenRole, "=", ref bRoleFound, ref tempThisRole); - else if ((q.Length >= tokenRequiredQualifier.Length) && (0 == string.Compare (q, 0, tokenRequiredQualifier, 0, tokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelatedQualifier); - else if ((q.Length >= tokenRequiredAssocQualifier.Length) && (0 == string.Compare (q, 0, tokenRequiredAssocQualifier, 0, tokenRequiredAssocQualifier.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenRequiredAssocQualifier, "=", ref bRequiredAssocQualifierFound, ref tempRelationshipQualifier); - else if ((q.Length >= tokenSchemaOnly.Length) && (0 == string.Compare (q, 0, tokenSchemaOnly, 0, tokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) + if ((q.Length >= TokenResultClass.Length) && (0 == string.Compare (q, 0, TokenResultClass, 0, TokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenResultClass, "=", ref bResultClassFound, ref tempRelatedClass); + else if ((q.Length >= TokenAssocClass.Length) && (0 == string.Compare (q, 0, TokenAssocClass, 0, TokenAssocClass.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenAssocClass, "=", ref bAssocClassFound, ref tempRelationshipClass); + else if ((q.Length >= TokenResultRole.Length) && (0 == string.Compare (q, 0, TokenResultRole, 0, TokenResultRole.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenResultRole, "=", ref bResultRoleFound, ref tempRelatedRole); + else if ((q.Length >= TokenRole.Length) && (0 == string.Compare (q, 0, TokenRole, 0, TokenRole.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenRole, "=", ref bRoleFound, ref tempThisRole); + else if ((q.Length >= TokenRequiredQualifier.Length) && (0 == string.Compare (q, 0, TokenRequiredQualifier, 0, TokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelatedQualifier); + else if ((q.Length >= TokenRequiredAssocQualifier.Length) && (0 == string.Compare (q, 0, TokenRequiredAssocQualifier, 0, TokenRequiredAssocQualifier.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenRequiredAssocQualifier, "=", ref bRequiredAssocQualifierFound, ref tempRelationshipQualifier); + else if ((q.Length >= TokenSchemaOnly.Length) && (0 == string.Compare (q, 0, TokenSchemaOnly, 0, TokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) { - ParseToken (ref q, tokenSchemaOnly, ref bSchemaOnlyFound); + ParseToken (ref q, TokenSchemaOnly, ref bSchemaOnlyFound); tempIsSchemaQuery = true; } - else if ((q.Length >= tokenClassDefsOnly.Length) && (0 == string.Compare (q, 0, tokenClassDefsOnly, 0, tokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if ((q.Length >= TokenClassDefsOnly.Length) && (0 == string.Compare (q, 0, TokenClassDefsOnly, 0, TokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) { - ParseToken (ref q, tokenClassDefsOnly, ref bClassDefsOnlyFound); + ParseToken (ref q, TokenClassDefsOnly, ref bClassDefsOnlyFound); tempClassDefsOnly = true; } else if (0 == q.Length) @@ -1819,14 +1819,14 @@ namespace System.Management //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC// public class RelationshipQuery : WqlObjectQuery { - private static readonly string tokenReferences = "references"; - private static readonly string tokenOf = "of"; - private static readonly string tokenWhere = "where"; - private static readonly string tokenResultClass = "resultclass"; - private static readonly string tokenRole = "role"; - private static readonly string tokenRequiredQualifier = "requiredqualifier"; - private static readonly string tokenClassDefsOnly = "classdefsonly"; - private static readonly string tokenSchemaOnly = "schemaonly"; + private const string TokenReferences = "references"; + private const string TokenOf = "of"; + private const string TokenWhere = "where"; + private const string TokenResultClass = "resultclass"; + private const string TokenRole = "role"; + private const string TokenRequiredQualifier = "requiredqualifier"; + private const string TokenClassDefsOnly = "classdefsonly"; + private const string TokenSchemaOnly = "schemaonly"; private string sourceObject; private string relationshipClass; @@ -1877,7 +1877,7 @@ namespace System.Management { // Minimally determine if the string is a query or instance name. // - if (queryOrSourceObject.TrimStart().StartsWith(tokenReferences, StringComparison.OrdinalIgnoreCase)) + if (queryOrSourceObject.TrimStart().StartsWith(TokenReferences, StringComparison.OrdinalIgnoreCase)) { // Looks to be a query - do further checking. // @@ -2095,7 +2095,7 @@ namespace System.Management return; //"references" clause - string s = tokenReferences + " " + tokenOf + " {" + sourceObject + "}"; + string s = TokenReferences + " " + TokenOf + " {" + sourceObject + "}"; //If any of the other parameters are set we need a "where" clause if (!(RelationshipClass.Length==0) || @@ -2104,28 +2104,28 @@ namespace System.Management classDefinitionsOnly || isSchemaQuery) { - s = s + " " + tokenWhere; + s = s + " " + TokenWhere; //"ResultClass" if (!(RelationshipClass.Length==0)) - s = s + " " + tokenResultClass + " = " + relationshipClass; + s = s + " " + TokenResultClass + " = " + relationshipClass; //"Role" if (!(ThisRole.Length==0)) - s = s + " " + tokenRole + " = " + thisRole; + s = s + " " + TokenRole + " = " + thisRole; //"RequiredQualifier" if (!(RelationshipQualifier.Length==0)) - s = s + " " + tokenRequiredQualifier + " = " + relationshipQualifier; + s = s + " " + TokenRequiredQualifier + " = " + relationshipQualifier; //"SchemaOnly" and "ClassDefsOnly" if (!isSchemaQuery) //this is an instance query - classDefs allowed { if (classDefinitionsOnly) - s = s + " " + tokenClassDefsOnly; + s = s + " " + TokenClassDefsOnly; } else //this is a schema query, schemaonly required - s = s + " " + tokenSchemaOnly; + s = s + " " + TokenSchemaOnly; } @@ -2155,11 +2155,11 @@ namespace System.Management int i; //Find "references" clause - if (0 != string.Compare(q, 0, tokenReferences, 0, tokenReferences.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare(q, 0, TokenReferences, 0, TokenReferences.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"references"); // Invalid query // Strip off the clause - q = q.Remove(0, tokenReferences.Length); + q = q.Remove(0, TokenReferences.Length); // Must be some white space next if ((0 == q.Length) || !char.IsWhiteSpace (q[0])) @@ -2168,11 +2168,11 @@ namespace System.Management q = q.TrimStart(null); // Remove the leading whitespace // Next token should be "of" - if (0 != string.Compare(q, 0, tokenOf, 0, tokenOf.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare(q, 0, TokenOf, 0, TokenOf.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"of"); // Invalid query // Strip off the clause and leading WS - q = q.Remove(0, tokenOf.Length).TrimStart (null); + q = q.Remove(0, TokenOf.Length).TrimStart (null); // Next character should be "{" if (0 != q.IndexOf('{')) @@ -2192,10 +2192,10 @@ namespace System.Management if (0 < q.Length) { // Next should be the "where" clause - if (0 != string.Compare (q, 0, tokenWhere, 0, tokenWhere.Length, StringComparison.OrdinalIgnoreCase)) + if (0 != string.Compare (q, 0, TokenWhere, 0, TokenWhere.Length, StringComparison.OrdinalIgnoreCase)) throw new ArgumentException(SR.InvalidQuery,"where"); // Invalid query - q = q.Remove (0, tokenWhere.Length); + q = q.Remove (0, TokenWhere.Length); // Must be some white space next if ((0 == q.Length) || !char.IsWhiteSpace (q[0])) @@ -2213,20 +2213,20 @@ namespace System.Management // Keep looking for tokens until we are done while (true) { - if ((q.Length >= tokenResultClass.Length) && (0 == string.Compare (q, 0, tokenResultClass, 0, tokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenResultClass, "=", ref bResultClassFound, ref tempRelationshipClass); - else if ((q.Length >= tokenRole.Length) && (0 == string.Compare (q, 0, tokenRole, 0, tokenRole.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenRole, "=", ref bRoleFound, ref tempThisRole); - else if ((q.Length >= tokenRequiredQualifier.Length) && (0 == string.Compare (q, 0, tokenRequiredQualifier, 0, tokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) - ParseToken (ref q, tokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelationshipQualifier); - else if ((q.Length >= tokenClassDefsOnly.Length) && (0 == string.Compare (q, 0, tokenClassDefsOnly, 0, tokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) + if ((q.Length >= TokenResultClass.Length) && (0 == string.Compare (q, 0, TokenResultClass, 0, TokenResultClass.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenResultClass, "=", ref bResultClassFound, ref tempRelationshipClass); + else if ((q.Length >= TokenRole.Length) && (0 == string.Compare (q, 0, TokenRole, 0, TokenRole.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenRole, "=", ref bRoleFound, ref tempThisRole); + else if ((q.Length >= TokenRequiredQualifier.Length) && (0 == string.Compare (q, 0, TokenRequiredQualifier, 0, TokenRequiredQualifier.Length, StringComparison.OrdinalIgnoreCase))) + ParseToken (ref q, TokenRequiredQualifier, "=", ref bRequiredQualifierFound, ref tempRelationshipQualifier); + else if ((q.Length >= TokenClassDefsOnly.Length) && (0 == string.Compare (q, 0, TokenClassDefsOnly, 0, TokenClassDefsOnly.Length, StringComparison.OrdinalIgnoreCase))) { - ParseToken (ref q, tokenClassDefsOnly, ref bClassDefsOnlyFound); + ParseToken (ref q, TokenClassDefsOnly, ref bClassDefsOnlyFound); tempClassDefsOnly = true; } - else if ((q.Length >= tokenSchemaOnly.Length) && (0 == string.Compare (q, 0, tokenSchemaOnly, 0, tokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) + else if ((q.Length >= TokenSchemaOnly.Length) && (0 == string.Compare (q, 0, TokenSchemaOnly, 0, TokenSchemaOnly.Length, StringComparison.OrdinalIgnoreCase))) { - ParseToken (ref q, tokenSchemaOnly, ref bSchemaOnlyFound); + ParseToken (ref q, TokenSchemaOnly, ref bSchemaOnlyFound); tempSchemaOnly = true; } else if (0 == q.Length) @@ -2414,7 +2414,7 @@ namespace System.Management //CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC// public class WqlEventQuery : EventQuery { - private static readonly string tokenSelectAll = "select * "; + private const string TokenSelectAll = "select * "; private string eventClassName; private TimeSpan withinInterval; @@ -2468,7 +2468,7 @@ namespace System.Management { // Minimally determine if the string is a query or event class name. // - if (queryOrEventClassName.TrimStart().StartsWith(tokenSelectAll, StringComparison.OrdinalIgnoreCase)) + if (queryOrEventClassName.TrimStart().StartsWith(TokenSelectAll, StringComparison.OrdinalIgnoreCase)) { QueryString = queryOrEventClassName; // Parse/validate; may throw. } @@ -2957,7 +2957,7 @@ namespace System.Management } //Select clause - string s = tokenSelectAll; //no property list allowed here... + string s = TokenSelectAll; //no property list allowed here... //From clause s = s + "from " + eventClassName; @@ -3021,7 +3021,7 @@ namespace System.Management bool bFound = false; //Find "select" clause and make sure it's a select * - string keyword = tokenSelect; + string keyword = TokenSelect; if ((q.Length < keyword.Length) || (0 != string.Compare (q, 0, keyword, 0, keyword.Length, StringComparison.OrdinalIgnoreCase))) throw new ArgumentException(SR.InvalidQuery); q = q.Remove(0, keyword.Length).TrimStart(null); diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs index a67682f..bab42f7 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs @@ -57,17 +57,20 @@ namespace System.Net.Sockets // In debug builds, force there to be 2 engines. In release builds, use half the number of processors when // there are at least 6. The lower bound is to avoid using multiple engines on systems which aren't servers. - private static readonly int EngineCount = +#pragma warning disable CA1802 // const works for debug, but needs to be static readonly for release + private static readonly int s_engineCount = #if DEBUG 2; #else Environment.ProcessorCount >= 6 ? Environment.ProcessorCount / 2 : 1; #endif +#pragma warning restore CA1802 + // // The current engines. We replace an engine when it runs out of "handle" values. // Must be accessed under s_lock. // - private static readonly SocketAsyncEngine[] s_currentEngines = new SocketAsyncEngine[EngineCount]; + private static readonly SocketAsyncEngine[] s_currentEngines = new SocketAsyncEngine[s_engineCount]; private static int s_allocateFromEngine = 0; private readonly IntPtr _port; @@ -102,7 +105,7 @@ namespace System.Net.Sockets // private static readonly IntPtr MaxHandles = IntPtr.Size == 4 ? (IntPtr)int.MaxValue : (IntPtr)long.MaxValue; #endif - private static readonly IntPtr MinHandlesForAdditionalEngine = EngineCount == 1 ? MaxHandles : (IntPtr)32; + private static readonly IntPtr MinHandlesForAdditionalEngine = s_engineCount == 1 ? MaxHandles : (IntPtr)32; // // Sentinel handle value to identify events from the "shutdown pipe," used to signal an event loop to stop @@ -181,7 +184,7 @@ namespace System.Net.Sockets // Round-robin to the next engine once we have sufficient sockets on this one. if (!engine.HasLowNumberOfSockets) { - s_allocateFromEngine = (s_allocateFromEngine + 1) % EngineCount; + s_allocateFromEngine = (s_allocateFromEngine + 1) % s_engineCount; } } } diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Windows.cs index c778247..0d041b9 100644 --- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Windows.cs +++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/UnixDomainSocketEndPoint.Windows.cs @@ -7,9 +7,11 @@ namespace System.Net.Sockets /// Represents a Unix Domain Socket endpoint as a path. public sealed partial class UnixDomainSocketEndPoint : EndPoint { +#pragma warning disable CA1802 // on Unix these need to be static readonly rather than const, so we do the same on Windows for consistency private static readonly int s_nativePathOffset = 2; // sizeof(sun_family) private static readonly int s_nativePathLength = 108; // sizeof(sun_path) private static readonly int s_nativeAddressSize = s_nativePathOffset + s_nativePathLength; // sizeof(sockaddr_un) +#pragma warning restore CA1802 private SocketAddress CreateSocketAddressForSerialize() => new SocketAddress(AddressFamily.Unix, s_nativeAddressSize); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.netcoreapp.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.netcoreapp.cs index db2e5b3..465d07c 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.netcoreapp.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.netcoreapp.cs @@ -330,10 +330,10 @@ namespace System.Net.Sockets.Tests Assert.Throws(() => new UnixDomainSocketEndPoint(null)); Assert.Throws(() => new UnixDomainSocketEndPoint(string.Empty)); - int maxNativeSize = (int)typeof(UnixDomainSocketEndPoint) - .GetField("s_nativePathLength", BindingFlags.Static | BindingFlags.NonPublic) - .GetValue(null); + FieldInfo fi = typeof(UnixDomainSocketEndPoint).GetField("s_nativePathLength", BindingFlags.Static | BindingFlags.NonPublic); + Assert.NotNull(fi); + int maxNativeSize = (int)fi.GetValue(null); string invalidLengthString = new string('a', maxNativeSize + 1); Assert.Throws(() => new UnixDomainSocketEndPoint(invalidLengthString)); } diff --git a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj index e465894..510c32d 100644 --- a/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj +++ b/src/libraries/System.Private.Xml/src/System.Private.Xml.csproj @@ -1,4 +1,4 @@ - + {C427CE0D-0740-41F3-9C3A-552BEA3DDB0D} System.Private.Xml diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs b/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs index 2edf11b..580ff0e 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Base64Decoder.cs @@ -20,7 +20,7 @@ namespace System.Xml private int _bits; private int _bitsFilled; - private static readonly string s_charsBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + private const string CharsBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; private static readonly byte[] s_mapBase64 = ConstructMapBase64(); private const int MaxValidChar = (int)'z'; private const byte Invalid = unchecked((byte)-1); @@ -144,9 +144,9 @@ namespace System.Xml { mapBase64[i] = Invalid; } - for (int i = 0; i < s_charsBase64.Length; i++) + for (int i = 0; i < CharsBase64.Length; i++) { - mapBase64[(int)s_charsBase64[i]] = (byte)i; + mapBase64[(int)CharsBase64[i]] = (byte)i; } return mapBase64; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs index feec7e4..5a30696 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/BinaryXml/SqlUtils.cs @@ -31,13 +31,13 @@ namespace System.Xml } } - private static readonly byte s_NUMERIC_MAX_PRECISION = 38; // Maximum precision of numeric - private static readonly byte s_maxPrecision = s_NUMERIC_MAX_PRECISION; // max SS precision + private const byte s_NUMERIC_MAX_PRECISION = 38; // Maximum precision of numeric + private const byte s_maxPrecision = s_NUMERIC_MAX_PRECISION; // max SS precision - private static readonly int s_cNumeMax = 4; - private static readonly long s_lInt32Base = ((long)1) << 32; // 2**32 - internal static readonly ulong x_llMax = long.MaxValue; // Max of Int64 - private static readonly double s_DUINT_BASE = (double)s_lInt32Base; // 2**32 + private const int s_cNumeMax = 4; + private const long s_lInt32Base = ((long)1) << 32; // 2**32 + internal const ulong x_llMax = long.MaxValue; // Max of Int64 + private const double s_DUINT_BASE = (double)s_lInt32Base; // 2**32 public BinXmlSqlDecimal(byte[] data, int offset, bool trim) { @@ -606,10 +606,10 @@ Error: } // Number of (100ns) ticks per time unit - private static readonly double s_SQLTicksPerMillisecond = 0.3; - public static readonly int SQLTicksPerSecond = 300; - public static readonly int SQLTicksPerMinute = SQLTicksPerSecond * 60; - public static readonly int SQLTicksPerHour = SQLTicksPerMinute * 60; + private const double s_SQLTicksPerMillisecond = 0.3; + internal const int SQLTicksPerSecond = 300; + internal const int SQLTicksPerMinute = SQLTicksPerSecond * 60; + internal const int SQLTicksPerHour = SQLTicksPerMinute * 60; public static string SqlSmallDateTimeToString(short dateticks, ushort timeticks) diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs b/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs index 853ac3e..a2c4738 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Bits.cs @@ -12,11 +12,11 @@ namespace System.Xml /// internal static class Bits { - private static readonly uint s_MASK_0101010101010101 = 0x55555555; - private static readonly uint s_MASK_0011001100110011 = 0x33333333; - private static readonly uint s_MASK_0000111100001111 = 0x0f0f0f0f; - private static readonly uint s_MASK_0000000011111111 = 0x00ff00ff; - private static readonly uint s_MASK_1111111111111111 = 0x0000ffff; + private const uint MASK_0101010101010101 = 0x55555555; + private const uint MASK_0011001100110011 = 0x33333333; + private const uint MASK_0000111100001111 = 0x0f0f0f0f; + private const uint MASK_0000000011111111 = 0x00ff00ff; + private const uint MASK_1111111111111111 = 0x0000ffff; /// /// Returns the number of 1 bits in an unsigned integer. Counts bits by divide-and-conquer method, @@ -25,11 +25,11 @@ namespace System.Xml /// public static int Count(uint num) { - num = (num & s_MASK_0101010101010101) + ((num >> 1) & s_MASK_0101010101010101); - num = (num & s_MASK_0011001100110011) + ((num >> 2) & s_MASK_0011001100110011); - num = (num & s_MASK_0000111100001111) + ((num >> 4) & s_MASK_0000111100001111); - num = (num & s_MASK_0000000011111111) + ((num >> 8) & s_MASK_0000000011111111); - num = (num & s_MASK_1111111111111111) + (num >> 16); + num = (num & MASK_0101010101010101) + ((num >> 1) & MASK_0101010101010101); + num = (num & MASK_0011001100110011) + ((num >> 2) & MASK_0011001100110011); + num = (num & MASK_0000111100001111) + ((num >> 4) & MASK_0000111100001111); + num = (num & MASK_0000000011111111) + ((num >> 8) & MASK_0000000011111111); + num = (num & MASK_1111111111111111) + (num >> 16); return (int)num; } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlUntypedStringConverter.cs b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlUntypedStringConverter.cs index 80e15c1..3366d37 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlUntypedStringConverter.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/Schema/XmlUntypedStringConverter.cs @@ -42,7 +42,7 @@ namespace System.Xml.Schema private static readonly Type s_uriType = typeof(Uri); private static readonly Type s_timeSpanType = typeof(TimeSpan); - private static readonly string s_untypedStringTypeName = "xdt:untypedAtomic"; + private const string UntypedStringTypeName = "xdt:untypedAtomic"; // Static convertor instance internal static XmlUntypedStringConverter Instance = new XmlUntypedStringConverter(true); @@ -240,7 +240,7 @@ namespace System.Xml.Schema private Exception CreateInvalidClrMappingException(Type sourceType, Type destinationType) { - return new InvalidCastException(SR.Format(SR.XmlConvert_TypeListBadMapping2, s_untypedStringTypeName, sourceType.Name, destinationType.Name)); + return new InvalidCastException(SR.Format(SR.XmlConvert_TypeListBadMapping2, UntypedStringTypeName, sourceType.Name, destinationType.Name)); } } } diff --git a/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs b/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs index 9e1a7d3..41a4340 100644 --- a/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs +++ b/src/libraries/System.Private.Xml/src/System/Xml/XmlConvert.cs @@ -109,7 +109,7 @@ namespace System.Xml matchPos = m.Index; } - for (int position = 0; position < length - s_encodedCharLength + 1; position++) + for (int position = 0; position < length - EncodedCharLength + 1; position++) { if (position == matchPos) { @@ -142,7 +142,7 @@ namespace System.Xml { if (u <= 0x0010ffff) { //convert to two chars - copyPosition = position + s_encodedCharLength + 4; + copyPosition = position + EncodedCharLength + 4; char lowChar, highChar; XmlCharType.SplitSurrogateChar(u, out lowChar, out highChar); bufBld.Append(highChar); @@ -152,20 +152,20 @@ namespace System.Xml } else { //convert to single char - copyPosition = position + s_encodedCharLength + 4; + copyPosition = position + EncodedCharLength + 4; bufBld.Append((char)u); } - position += s_encodedCharLength - 1 + 4; //just skip + position += EncodedCharLength - 1 + 4; //just skip } else { - copyPosition = position + s_encodedCharLength; + copyPosition = position + EncodedCharLength; bufBld.Append((char)( FromHex(name[position + 2]) * 0x1000 + FromHex(name[position + 3]) * 0x100 + FromHex(name[position + 4]) * 0x10 + FromHex(name[position + 5]))); - position += s_encodedCharLength - 1; + position += EncodedCharLength - 1; } } } @@ -300,7 +300,7 @@ namespace System.Xml } } - private static readonly int s_encodedCharLength = 7; // ("_xFFFF_".Length); + private const int EncodedCharLength = 7; // ("_xFFFF_".Length); private static volatile Regex s_encodeCharPattern; private static volatile Regex s_decodeCharPattern; private static int FromHex(char digit) diff --git a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.cs b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.cs index b990c41..2d6fde3 100644 --- a/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.cs +++ b/src/libraries/System.Runtime.Caching/src/System/Runtime/Caching/PhysicalMemoryMonitor.cs @@ -15,8 +15,8 @@ namespace System.Runtime.Caching // The limit is configurable (see ConfigUtil.cs). internal sealed partial class PhysicalMemoryMonitor : MemoryMonitor { - private const int MIN_TOTAL_MEMORY_TRIM_PERCENT = 10; - private static readonly long s_TARGET_TOTAL_MEMORY_TRIM_INTERVAL_TICKS = 5 * TimeSpan.TicksPerMinute; + private const int MinTotalMemoryTrimPercent = 10; + private const long TargetTotalMemoryTrimIntervalTicks = 5 * TimeSpan.TicksPerMinute; // Returns the percentage of physical machine memory that can be consumed by an // application before the cache starts forcibly removing items. @@ -87,8 +87,8 @@ namespace System.Runtime.Caching long ticksSinceTrim = utcNow.Subtract(lastTrimTime).Ticks; if (ticksSinceTrim > 0) { - percent = Math.Min(50, (int)((lastTrimPercent * s_TARGET_TOTAL_MEMORY_TRIM_INTERVAL_TICKS) / ticksSinceTrim)); - percent = Math.Max(MIN_TOTAL_MEMORY_TRIM_PERCENT, percent); + percent = Math.Min(50, (int)((lastTrimPercent * TargetTotalMemoryTrimIntervalTicks) / ticksSinceTrim)); + percent = Math.Max(MinTotalMemoryTrimPercent, percent); } #if PERF diff --git a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs index ffeea0c..2ff7cfb 100644 --- a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs +++ b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ACE.cs @@ -1789,7 +1789,7 @@ nameof(qualifier), // ADS_RIGHT_DS_WRITE_PROP = 0x20, // ADS_RIGHT_DS_CONTROL_ACCESS = 0x100 // - internal static readonly int AccessMaskWithObjectType = 0x1 | 0x2 | 0x8 | 0x10 | 0x20 | 0x100; + internal const int AccessMaskWithObjectType = 0x1 | 0x2 | 0x8 | 0x10 | 0x20 | 0x100; private static AceType TypeFromQualifier(bool isCallback, AceQualifier qualifier) { diff --git a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs index d2a01db..f1daf6e 100644 --- a/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs +++ b/src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs @@ -44,14 +44,14 @@ namespace System.Security.AccessControl // only these SACL control flags will be automatically carry forward // when update with new security descriptor. - private static readonly ControlFlags SACL_CONTROL_FLAGS = + private const ControlFlags SACL_CONTROL_FLAGS = ControlFlags.SystemAclPresent | ControlFlags.SystemAclAutoInherited | ControlFlags.SystemAclProtected; // only these DACL control flags will be automatically carry forward // when update with new security descriptor - private static readonly ControlFlags DACL_CONTROL_FLAGS = + private const ControlFlags DACL_CONTROL_FLAGS = ControlFlags.DiscretionaryAclPresent | ControlFlags.DiscretionaryAclAutoInherited | ControlFlags.DiscretionaryAclProtected; diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs index e739f40..9194916 100644 --- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs +++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/SID.cs @@ -259,13 +259,13 @@ namespace System.Security.Principal // Identifier authority must be at most six bytes long // - internal static readonly long MaxIdentifierAuthority = 0xFFFFFFFFFFFF; + internal const long MaxIdentifierAuthority = 0xFFFFFFFFFFFF; // // Maximum number of subauthorities in a SID // - internal static readonly byte MaxSubAuthorities = 15; + internal const byte MaxSubAuthorities = 15; // // Minimum length of a binary representation of a SID diff --git a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCharClass.cs b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCharClass.cs index a572814..f149b24 100644 --- a/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCharClass.cs +++ b/src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexCharClass.cs @@ -23,8 +23,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Globalization; -using System.IO; -using System.Text; namespace System.Text.RegularExpressions { @@ -47,18 +45,18 @@ namespace System.Text.RegularExpressions private const char ZeroWidthJoiner = '\u200D'; private const char ZeroWidthNonJoiner = '\u200C'; - private static readonly string s_internalRegexIgnoreCase = "__InternalRegexIgnoreCase__"; - private static readonly string s_space = "\x64"; - private static readonly string s_notSpace = "\uFF9C"; - private static readonly string s_word = "\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; - private static readonly string s_notWord = "\u0000\uFFFE\uFFFC\uFFFB\uFFFD\uFFFF\uFFFA\uFFF7\uFFED\u0000"; + private const string InternalRegexIgnoreCase = "__InternalRegexIgnoreCase__"; + private const string Space = "\x64"; + private const string NotSpace = "\uFF9C"; + private const string Word = "\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; + private const string NotWord = "\u0000\uFFFE\uFFFC\uFFFB\uFFFD\uFFFF\uFFFA\uFFF7\uFFED\u0000"; - public static readonly string SpaceClass = "\u0000\u0000\u0001\u0064"; - public static readonly string NotSpaceClass = "\u0001\u0000\u0001\u0064"; - public static readonly string WordClass = "\u0000\u0000\u000A\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; - public static readonly string NotWordClass = "\u0001\u0000\u000A\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; - public static readonly string DigitClass = "\u0000\u0000\u0001\u0009"; - public static readonly string NotDigitClass = "\u0000\u0000\u0001\uFFF7"; + internal const string SpaceClass = "\u0000\u0000\u0001\u0064"; + internal const string NotSpaceClass = "\u0001\u0000\u0001\u0064"; + internal const string WordClass = "\u0000\u0000\u000A\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; + internal const string NotWordClass = "\u0001\u0000\u000A\u0000\u0002\u0004\u0005\u0003\u0001\u0006\u0009\u0013\u0000"; + internal const string DigitClass = "\u0000\u0000\u0001\u0009"; + internal const string NotDigitClass = "\u0000\u0000\u0001\uFFF7"; private const string ECMASpaceSet = "\u0009\u000E\u0020\u0021"; private const string NotECMASpaceSet = "\0\u0009\u000E\u0020\u0021"; @@ -67,15 +65,15 @@ namespace System.Text.RegularExpressions private const string ECMADigitSet = "\u0030\u003A"; private const string NotECMADigitSet = "\0\u0030\u003A"; - public const string ECMASpaceClass = "\x00\x04\x00" + ECMASpaceSet; - public const string NotECMASpaceClass = "\x01\x04\x00" + ECMASpaceSet; - public const string ECMAWordClass = "\x00\x0A\x00" + ECMAWordSet; - public const string NotECMAWordClass = "\x01\x0A\x00" + ECMAWordSet; - public const string ECMADigitClass = "\x00\x02\x00" + ECMADigitSet; - public const string NotECMADigitClass = "\x01\x02\x00" + ECMADigitSet; + internal const string ECMASpaceClass = "\x00\x04\x00" + ECMASpaceSet; + internal const string NotECMASpaceClass = "\x01\x04\x00" + ECMASpaceSet; + internal const string ECMAWordClass = "\x00\x0A\x00" + ECMAWordSet; + internal const string NotECMAWordClass = "\x01\x0A\x00" + ECMAWordSet; + internal const string ECMADigitClass = "\x00\x02\x00" + ECMADigitSet; + internal const string NotECMADigitClass = "\x01\x02\x00" + ECMADigitSet; - public const string AnyClass = "\x00\x01\x00\x00"; - public const string EmptyClass = "\x00\x00\x00"; + internal const string AnyClass = "\x00\x01\x00\x00"; + internal const string EmptyClass = "\x00\x00\x00"; // UnicodeCategory is zero based, so we add one to each value and subtract it off later private const int DefinedCategoriesCapacity = 38; @@ -529,13 +527,13 @@ namespace System.Text.RegularExpressions public void AddCategoryFromName(string categoryName, bool invert, bool caseInsensitive, string pattern, int currentPos) { - if (s_definedCategories.TryGetValue(categoryName, out string category) && !categoryName.Equals(s_internalRegexIgnoreCase)) + if (s_definedCategories.TryGetValue(categoryName, out string category) && !categoryName.Equals(InternalRegexIgnoreCase)) { if (caseInsensitive) { if (categoryName.Equals("Ll") || categoryName.Equals("Lu") || categoryName.Equals("Lt")) // when RegexOptions.IgnoreCase is specified then {Ll}, {Lu}, and {Lt} cases should all match - category = s_definedCategories[s_internalRegexIgnoreCase]; + category = s_definedCategories[InternalRegexIgnoreCase]; } if (invert) @@ -641,14 +639,14 @@ namespace System.Text.RegularExpressions if (ecma) AddSet(NotECMAWordSet); else - AddCategory(s_notWord); + AddCategory(NotWord); } else { if (ecma) AddSet(ECMAWordSet); else - AddCategory(s_word); + AddCategory(Word); } } @@ -659,14 +657,14 @@ namespace System.Text.RegularExpressions if (ecma) AddSet(NotECMASpaceSet); else - AddCategory(s_notSpace); + AddCategory(NotSpace); } else { if (ecma) AddSet(ECMASpaceSet); else - AddCategory(s_space); + AddCategory(Space); } } @@ -1166,7 +1164,7 @@ namespace System.Text.RegularExpressions #if DEBUG public static readonly char[] Hex = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - public static readonly string[] Categories = new string[] {"Lu", "Ll", "Lt", "Lm", "Lo", s_internalRegexIgnoreCase, + public static readonly string[] Categories = new string[] {"Lu", "Ll", "Lt", "Lm", "Lo", InternalRegexIgnoreCase, "Mn", "Mc", "Me", "Nd", "Nl", "No", "Zs", "Zl", "Zp", @@ -1243,9 +1241,9 @@ namespace System.Text.RegularExpressions if (!found) { - if (group.Equals(s_word)) + if (group.Equals(Word)) desc.Append("\\w"); - else if (group.Equals(s_notWord)) + else if (group.Equals(NotWord)) desc.Append("\\W"); else Debug.Fail("Couldn't find a group to match '" + group + "'"); -- 2.7.4