Skip to content

Commit c686e7d

Browse files
authored
remove some redundant assignments (#4522)
1 parent 0b8a683 commit c686e7d

File tree

13 files changed

+24
-28
lines changed

13 files changed

+24
-28
lines changed

src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginCache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public List<string> GetExtensionPaths(string endsWithPattern, bool skipDefaultEx
128128
return TestExtensions.GetTestExtensionCache<TPluginInfo>();
129129
}
130130

131-
Dictionary<string, TPluginInfo>? pluginInfos = null;
131+
Dictionary<string, TPluginInfo>? pluginInfos;
132132
SetupAssemblyResolver(null);
133133

134134
// Some times TestPlatform.core.dll assembly fails to load in the current appdomain (from devenv.exe).
@@ -177,6 +177,7 @@ public List<string> GetExtensionPaths(string endsWithPattern, bool skipDefaultEx
177177
// Nothing to do here, we just do not want to do an EqtTrace.Fail for this thread
178178
// being aborted as it is a legitimate exception to receive.
179179
EqtTrace.Verbose("TestPluginCache.DiscoverTestExtensions: Data extension discovery is being aborted due to a thread abort.");
180+
return null;
180181
}
181182
#endif
182183
catch (Exception e)

src/Microsoft.TestPlatform.Common/ExtensionFramework/TestPluginDiscoverer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ private static void GetTestExtensionsFromFiles<TPluginInfo, TExtension>(
9191
}
9292
try
9393
{
94-
Assembly? assembly = null;
9594
var assemblyName = Path.GetFileNameWithoutExtension(file);
96-
assembly = Assembly.Load(new AssemblyName(assemblyName));
95+
var assembly = Assembly.Load(new AssemblyName(assemblyName));
9796
if (assembly != null)
9897
{
9998
GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(assembly, pluginInfos, file);

src/Microsoft.TestPlatform.Common/Filtering/FilterExpression.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ private static void ProcessOperator(Stack<FilterExpression> filterStack, Operato
130130
// Only the leaves have a condition value.
131131
if (current._condition != null)
132132
{
133-
bool valid = false;
134-
valid = current._condition.ValidForProperties(properties, propertyProvider);
133+
var valid = current._condition.ValidForProperties(properties, propertyProvider);
135134
// If it's not valid will add it to the function's return array.
136135
return !valid ? new string[1] { current._condition.Name } : null;
137136
}

src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/ProxyTestSessionManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public virtual bool StartSession(ITestSessionEventsHandler eventsHandler, IReque
209209
/// <inheritdoc/>
210210
public virtual bool StopSession(IRequestData requestData)
211211
{
212-
var testSessionId = string.Empty;
212+
string testSessionId;
213213
lock (_lockObject)
214214
{
215215
if (_testSessionInfo == null)
@@ -251,7 +251,7 @@ public virtual bool StopSession(IRequestData requestData)
251251
/// <returns>The dequeued proxy.</returns>
252252
public virtual ProxyOperationManager DequeueProxy(string source, string? runSettings)
253253
{
254-
ProxyOperationManagerContainer? proxyContainer = null;
254+
ProxyOperationManagerContainer? proxyContainer;
255255

256256
lock (_proxyOperationLockObject)
257257
{

src/Microsoft.TestPlatform.CrossPlatEngine/TestSession/TestSessionPool.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re
9696
{
9797
// TODO (copoiena): What happens if some request is running for the current session ?
9898
// Should we stop the request as well ? Probably yes.
99-
IProxyTestSessionManager? proxyManager = null;
99+
IProxyTestSessionManager? proxyManager;
100100

101101
lock (_lockObject)
102102
{
@@ -133,7 +133,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re
133133
{
134134
ValidateArg.NotNull(requestData, nameof(requestData));
135135

136-
ProxyTestSessionManager? sessionManager = null;
136+
ProxyTestSessionManager? sessionManager;
137137
lock (_lockObject)
138138
{
139139
if (!_sessionPool.ContainsKey(testSessionInfo))
@@ -181,7 +181,7 @@ public virtual bool KillSession(TestSessionInfo testSessionInfo, IRequestData re
181181
/// <returns>True if the operation succeeded, false otherwise.</returns>
182182
public virtual bool ReturnProxy(TestSessionInfo testSessionInfo, int proxyId)
183183
{
184-
ProxyTestSessionManager? sessionManager = null;
184+
ProxyTestSessionManager? sessionManager;
185185
lock (_lockObject)
186186
{
187187
if (!_sessionPool.ContainsKey(testSessionInfo))

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/MiniDumpWriteDump.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public static void CollectDumpUsingMiniDumpWriteDump(Process process, string out
2828
using var stream = new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
2929
NativeMethods.MinidumpExceptionInformation exceptionInfo = default;
3030

31-
NativeMethods.MinidumpType dumpType = NativeMethods.MinidumpType.MiniDumpNormal;
32-
dumpType = type switch
31+
var dumpType = type switch
3332
{
3433
MiniDumpTypeOption.Full => NativeMethods.MinidumpType.MiniDumpWithFullMemory |
3534
NativeMethods.MinidumpType.MiniDumpWithDataSegs |
@@ -39,12 +38,12 @@ public static void CollectDumpUsingMiniDumpWriteDump(Process process, string out
3938
NativeMethods.MinidumpType.MiniDumpWithThreadInfo |
4039
NativeMethods.MinidumpType.MiniDumpWithTokenInformation,
4140
MiniDumpTypeOption.WithHeap => NativeMethods.MinidumpType.MiniDumpWithPrivateReadWriteMemory |
42-
NativeMethods.MinidumpType.MiniDumpWithDataSegs |
43-
NativeMethods.MinidumpType.MiniDumpWithHandleData |
44-
NativeMethods.MinidumpType.MiniDumpWithUnloadedModules |
45-
NativeMethods.MinidumpType.MiniDumpWithFullMemoryInfo |
46-
NativeMethods.MinidumpType.MiniDumpWithThreadInfo |
47-
NativeMethods.MinidumpType.MiniDumpWithTokenInformation,
41+
NativeMethods.MinidumpType.MiniDumpWithDataSegs |
42+
NativeMethods.MinidumpType.MiniDumpWithHandleData |
43+
NativeMethods.MinidumpType.MiniDumpWithUnloadedModules |
44+
NativeMethods.MinidumpType.MiniDumpWithFullMemoryInfo |
45+
NativeMethods.MinidumpType.MiniDumpWithThreadInfo |
46+
NativeMethods.MinidumpType.MiniDumpWithTokenInformation,
4847
MiniDumpTypeOption.Mini => NativeMethods.MinidumpType.MiniDumpWithThreadInfo,
4948
_ => NativeMethods.MinidumpType.MiniDumpNormal,
5049
};

src/Microsoft.TestPlatform.ObjectModel/Navigation/FullSymbolReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private void PopulateCacheForTypeAndMethodSymbols()
309309
ValidateArg.NotNullOrEmpty(typeName, nameof(typeName));
310310

311311
IDiaEnumSymbols? enumSymbols = null;
312-
IDiaSymbol? typeSymbol = null;
312+
IDiaSymbol? typeSymbol;
313313
IDiaSymbol? global = null;
314314

315315
try
@@ -378,7 +378,7 @@ private void PopulateCacheForTypeAndMethodSymbols()
378378
ValidateArg.NotNullOrEmpty(methodName, nameof(methodName));
379379

380380
IDiaEnumSymbols? enumSymbols = null;
381-
IDiaSymbol? methodSymbol = null;
381+
IDiaSymbol? methodSymbol;
382382
Dictionary<string, IDiaSymbol> methodSymbolsForType;
383383

384384
try

src/Microsoft.TestPlatform.PlatformAbstractions/common/System/ProcessHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ public object LaunchProcess(string processPath, string? arguments, string? worki
6666
catch (Exception)
6767
{
6868
process.Dispose();
69-
process = null;
7069

7170
//EqtTrace.Error("TestHost Object {0} failed to launch with the following exception: {1}", processPath, exception.Message);
7271
throw;

src/vstest.console/CommandLine/Executor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,11 @@ private int GetArgumentProcessors(string[] args, out List<IArgumentProcessor> pr
276276
processors.Sort((p1, p2) => Comparer<ArgumentProcessorPriority>.Default.Compare(p1.Metadata.Value.Priority, p2.Metadata.Value.Priority));
277277
foreach (var processor in processors)
278278
{
279-
IArgumentExecutor? executorInstance;
280279
try
281280
{
282281
// Ensure the instance is created. Note that the Lazy not only instantiates
283282
// the argument processor, but also initializes it.
284-
executorInstance = processor.Executor?.Value;
283+
var executorInstance = processor.Executor?.Value;
285284
}
286285
catch (Exception ex)
287286
{

src/vstest.console/Processors/Utilities/ArgumentProcessorFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation(IA
266266
var processorExecutor = processor.Executor;
267267
var lazyArgumentProcessor = new Lazy<IArgumentExecutor>(() =>
268268
{
269-
IArgumentExecutor? instance = null;
269+
IArgumentExecutor? instance;
270270
try
271271
{
272272
instance = processorExecutor!.Value;
@@ -307,7 +307,7 @@ private static IArgumentProcessor WrapLazyProcessorToInitializeOnInstantiation(
307307
var processorExecutor = processor.Executor;
308308
var lazyArgumentProcessor = new Lazy<IArgumentExecutor>(() =>
309309
{
310-
IArgumentsExecutor? instance = null;
310+
IArgumentsExecutor? instance;
311311
try
312312
{
313313
instance = (IArgumentsExecutor)processorExecutor!.Value;

0 commit comments

Comments
 (0)