Skip to content

Commit 96d7bbc

Browse files
authored
CA1823 Avoid unused private fields (#7180)
Relates to #7174
1 parent d1f5a8a commit 96d7bbc

File tree

14 files changed

+32
-94
lines changed

14 files changed

+32
-94
lines changed

eng/Common.globalconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ dotnet_diagnostic.CA1821.severity = warning
277277
dotnet_diagnostic.CA1822.severity = none
278278

279279
# Avoid unused private fields
280-
dotnet_diagnostic.CA1823.severity = suggestion
280+
dotnet_diagnostic.CA1823.severity = warning
281281

282282
# Mark assemblies with NeutralResourcesLanguageAttribute
283283
dotnet_diagnostic.CA1824.severity = warning

src/Build/Collections/RetrievableEntryHashSet/HashSet.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ internal class RetrievableEntryHashSet<T> : ICollection<T>,
9393
{
9494
// store lower 31 bits of hash code
9595
private const int Lower31BitMask = 0x7FFFFFFF;
96+
#if NEVER
9697
// cutoff point, above which we won't do stackallocs. This corresponds to 100 integers.
9798
private const int StackAllocThreshold = 100;
99+
#endif
98100
// when constructing a hashset from an existing collection, it may contain duplicates,
99101
// so this is used as the max acceptable excess ratio of capacity to count. Note that
100102
// this is only used on the ctor and not to automatically shrink if the hashset has, e.g,
@@ -121,7 +123,7 @@ internal class RetrievableEntryHashSet<T> : ICollection<T>,
121123
// temporary variable needed during deserialization
122124
private SerializationInfo _siInfo;
123125

124-
#region Constructors
126+
#region Constructors
125127

126128
public RetrievableEntryHashSet(IEqualityComparer<string> comparer)
127129
{
@@ -204,7 +206,7 @@ protected RetrievableEntryHashSet(SerializationInfo info, StreamingContext conte
204206
_siInfo = info;
205207
}
206208

207-
#endregion
209+
#endregion
208210

209211
// Convenience to minimise change to callers used to dictionaries
210212
public ICollection<string> Keys
@@ -230,7 +232,7 @@ public ICollection<T> Values
230232
get { return this; }
231233
}
232234

233-
#region ICollection<T> methods
235+
#region ICollection<T> methods
234236

235237
// Convenience to minimise change to callers used to dictionaries
236238
internal T this[string name]
@@ -481,9 +483,9 @@ internal void MakeReadOnly()
481483
_readOnly = true;
482484
}
483485

484-
#endregion
486+
#endregion
485487

486-
#region IEnumerable methods
488+
#region IEnumerable methods
487489

488490
public Enumerator GetEnumerator()
489491
{
@@ -508,9 +510,9 @@ IEnumerator IEnumerable.GetEnumerator()
508510
return new Enumerator(this);
509511
}
510512

511-
#endregion
513+
#endregion
512514

513-
#region ISerializable methods
515+
#region ISerializable methods
514516

515517
// [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
516518
[SecurityCritical]
@@ -533,9 +535,9 @@ public virtual void GetObjectData(SerializationInfo info, StreamingContext conte
533535
}
534536
}
535537

536-
#endregion
538+
#endregion
537539

538-
#region IDeserializationCallback methods
540+
#region IDeserializationCallback methods
539541

540542
public virtual void OnDeserialization(Object sender)
541543
{
@@ -580,9 +582,9 @@ public virtual void OnDeserialization(Object sender)
580582
_siInfo = null;
581583
}
582584

583-
#endregion
585+
#endregion
584586

585-
#region HashSet methods
587+
#region HashSet methods
586588

587589
/// <summary>
588590
/// Add item to this HashSet.
@@ -630,7 +632,7 @@ public void UnionWith(IEnumerable<T> other)
630632
}
631633
}
632634

633-
#if NEVER
635+
#if NEVER
634636
/// <summary>
635637
/// Takes the intersection of this set with other. Modifies this set.
636638
///
@@ -1152,9 +1154,9 @@ public static IEqualityComparer<RetrievableEntryHashSet<T>> CreateSetComparer()
11521154
#endif
11531155
#endif
11541156

1155-
#endregion
1157+
#endregion
11561158

1157-
#region Helper methods
1159+
#region Helper methods
11581160

11591161
/// <summary>
11601162
/// Initializes buckets and slots arrays. Uses suggested capacity by finding next prime
@@ -1723,7 +1725,7 @@ private int InternalGetHashCode(string item)
17231725
return _comparer.GetHashCode(item) & Lower31BitMask;
17241726
}
17251727

1726-
#endregion
1728+
#endregion
17271729

17281730
// used for set checking operations (using enumerables) that rely on counting
17291731
internal struct ElementCount

src/MSBuild.UnitTests/PerfLog_Tests.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ namespace Microsoft.Build.UnitTests
1414
{
1515
public class PerfLogTests
1616
{
17-
#if USE_MSBUILD_DLL_EXTN
18-
private const string MSBuildExeName = "MSBuild.dll";
19-
#else
20-
private const string MSBuildExeName = "MSBuild.exe";
21-
#endif
22-
2317
private readonly ITestOutputHelper _output;
2418

2519
public PerfLogTests(ITestOutputHelper output)

src/Shared/FileUtilities.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,27 +1089,6 @@ internal static string MakeRelative(string basePath, string path)
10891089
return StringBuilderCache.GetStringAndRelease(sb);
10901090
}
10911091

1092-
/// <summary>
1093-
/// Helper function to create an Uri object from path.
1094-
/// </summary>
1095-
/// <param name="path">path string</param>
1096-
/// <returns>uri object</returns>
1097-
private static Uri CreateUriFromPath(string path)
1098-
{
1099-
ErrorUtilities.VerifyThrowArgumentLength(path, nameof(path));
1100-
1101-
Uri pathUri;
1102-
1103-
// Try absolute first, then fall back on relative, otherwise it
1104-
// makes some absolute UNC paths like (\\foo\bar) relative ...
1105-
if (!Uri.TryCreate(path, UriKind.Absolute, out pathUri))
1106-
{
1107-
pathUri = new Uri(path, UriKind.Relative);
1108-
}
1109-
1110-
return pathUri;
1111-
}
1112-
11131092
/// <summary>
11141093
/// Normalizes the path if and only if it is longer than max path,
11151094
/// or would be if rooted by the current directory.

src/Shared/UnitTests/EngineTestEnvironment.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ namespace Microsoft.Build.UnitTests
2424
public partial class TestEnvironment
2525
{
2626
// reset the default build manager and the state it might have accumulated from other tests
27+
#pragma warning disable CA1823 // Avoid unused private fields
2728
private object _resetBuildManager = new ResetDefaultBuildManager();
29+
#pragma warning restore CA1823 // Avoid unused private fields
2830

2931
private class ResetDefaultBuildManager
3032
{

src/Tasks/GenerateResource.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -934,17 +934,7 @@ public override bool Execute()
934934
private static bool allowMOTW;
935935

936936
private const string CLSID_InternetSecurityManager = "7b8a2d94-0ac9-11d1-896c-00c04fb6bfc4";
937-
938-
private const uint ZoneLocalMachine = 0;
939-
940-
private const uint ZoneIntranet = 1;
941-
942-
private const uint ZoneTrusted = 2;
943-
944937
private const uint ZoneInternet = 3;
945-
946-
private const uint ZoneUntrusted = 4;
947-
948938
private static IInternetSecurityManager internetSecurityManager = null;
949939

950940
// Resources can have arbitrarily serialized objects in them which can execute arbitrary code

src/Tasks/LockCheck.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ internal struct RM_UNIQUE_PROCESS
8383
public FILETIME ProcessStartTime;
8484
}
8585

86-
const int RM_INVALID_SESSION = -1;
87-
const int RM_INVALID_PROCESS = -1;
8886
const int CCH_RM_MAX_APP_NAME = 255;
8987
const int CCH_RM_MAX_SVC_NAME = 63;
9088
const int ERROR_SEM_TIMEOUT = 121;

src/Tasks/ManifestUtil/SecurityUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public static class SecurityUtilities
5858
#if !RUNTIME_TYPE_NETCORE
5959
private const int Fx2MajorVersion = 2;
6060
private const int Fx3MajorVersion = 3;
61-
#endif
6261
private static readonly Version s_dotNet40Version = new Version("4.0");
62+
#endif
6363
private static readonly Version s_dotNet45Version = new Version("4.5");
6464

6565
#if !RUNTIME_TYPE_NETCORE

src/Tasks/ManifestUtil/Util.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ internal static class Util
2929
internal static readonly string logPath = GetLogPath();
3030
private static readonly char[] s_fileNameInvalidChars = { '\\', '/', ':', '*', '?', '"', '<', '>', '|' };
3131
private static StreamWriter s_logFileWriter;
32+
#if !RUNTIME_TYPE_NETCORE
3233
// Major, Minor, Build and Revision of CLR v2.0
3334
private static readonly int[] s_clrVersion2 = { 2, 0, 50727, 0 };
34-
#if RUNTIME_TYPE_NETCORE
35+
#else
3536
// Major, Minor, Build and Revision of CLR v4.0
3637
private static readonly int[] s_clrVersion4 = { 4, 0, 30319, 0 };
3738
#endif

src/Tasks/ManifestUtil/mansign2.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,6 @@ private void init()
281281
#endif
282282
}
283283

284-
private static XmlElement FindIdElement(XmlElement context, string idValue)
285-
{
286-
if (context == null)
287-
return null;
288-
289-
XmlElement idReference = context.SelectSingleNode("//*[@Id=\"" + idValue + "\"]") as XmlElement;
290-
if (idReference != null)
291-
return idReference;
292-
idReference = context.SelectSingleNode("//*[@id=\"" + idValue + "\"]") as XmlElement;
293-
if (idReference != null)
294-
return idReference;
295-
return context.SelectSingleNode("//*[@ID=\"" + idValue + "\"]") as XmlElement;
296-
}
297-
298284
public override XmlElement GetIdElement(XmlDocument document, string idValue)
299285
{
300286
// We only care about Id references inside of the KeyInfo section
@@ -320,9 +306,6 @@ internal class SignedCmiManifest2
320306
private const string Sha1SignatureMethodUri = @"http://www.w3.org/2000/09/xmldsig#rsa-sha1";
321307
private const string Sha1DigestMethod = @"http://www.w3.org/2000/09/xmldsig#sha1";
322308

323-
private const string wintrustPolicyFlagsRegPath = "Software\\Microsoft\\Windows\\CurrentVersion\\WinTrust\\Trust Providers\\Software Publishing";
324-
private const string wintrustPolicyFlagsRegName = "State";
325-
326309
private SignedCmiManifest2() { }
327310

328311
internal SignedCmiManifest2(XmlDocument manifestDom, bool useSha256)

0 commit comments

Comments
 (0)