Skip to content

Commit 0b8a683

Browse files
remove redundant GetTypeInfo (#4519)
Co-authored-by: Amaury Levé <amauryleve@microsoft.com>
1 parent 5814a77 commit 0b8a683

File tree

57 files changed

+214
-281
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+214
-281
lines changed

src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private static void GetManagedNameAndHierarchy(MethodBase method, bool useClosed
201201
hierarchyValues[HierarchyConstants.Levels.ClassIndex] = managedTypeName.Substring(hierarchyPos[1] + 1, hierarchyPos[2] - hierarchyPos[1] - 1);
202202
hierarchyValues[HierarchyConstants.Levels.NamespaceIndex] = managedTypeName.Substring(hierarchyPos[0], hierarchyPos[1] - hierarchyPos[0]);
203203
}
204-
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.GetTypeInfo()?.Assembly?.GetName()?.Name ?? string.Empty;
204+
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.Assembly?.GetName()?.Name ?? string.Empty;
205205
}
206206

207207
/// <summary>

src/Microsoft.TestPlatform.Client/TestPlatform.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using System.Reflection;
98

109
using Microsoft.VisualStudio.TestPlatform.Client.Discovery;
1110
using Microsoft.VisualStudio.TestPlatform.Client.Execution;
@@ -276,7 +275,7 @@ private static void AddExtensionAssembliesFromExtensionDirectory()
276275
}
277276

278277
string extensionsFolder = Path.Combine(
279-
Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation())!,
278+
Path.GetDirectoryName(typeof(TestPlatform).Assembly.GetAssemblyLocation())!,
280279
"Extensions");
281280
if (!fileHelper.DirectoryExists(extensionsFolder))
282281
{

src/Microsoft.TestPlatform.Common/DataCollection/DataCollectorConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Reflection;
87

98
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.Utilities;
109
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
@@ -155,6 +154,6 @@ private static object[] GetAttributes(Type dataCollectorType, Type attributeType
155154

156155
// If any attribute constructor on the type throws, the exception will bubble up through
157156
// the "GetCustomAttributes" method.
158-
return dataCollectorType.GetTypeInfo().GetCustomAttributes(attributeType, true).ToArray();
157+
return dataCollectorType.GetCustomAttributes(attributeType, true).ToArray();
159158
}
160159
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ internal static IList<string> GetResolutionPaths(string extensionAssembly)
349349
var extensionDirectory = Path.GetDirectoryName(Path.GetFullPath(extensionAssembly))!;
350350
resolutionPaths.Add(extensionDirectory);
351351

352-
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.GetAssemblyLocation())!;
352+
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).Assembly.GetAssemblyLocation())!;
353353
if (!resolutionPaths.Contains(currentDirectory))
354354
{
355355
resolutionPaths.Add(currentDirectory);
@@ -374,7 +374,7 @@ internal IList<string> GetDefaultResolutionPaths()
374374
}
375375

376376
// Keep current directory for resolution
377-
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.GetAssemblyLocation())!;
377+
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).Assembly.GetAssemblyLocation())!;
378378
if (!resolutionPaths.Contains(currentDirectory))
379379
{
380380
resolutionPaths.Add(currentDirectory);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static void GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(Assem
156156

157157
if (types.Count == 0)
158158
{
159-
types.AddRange(assembly.GetTypes().Where(type => type.GetTypeInfo() is { } typeInfo && typeInfo.IsClass && !typeInfo.IsAbstract));
159+
types.AddRange(assembly.GetTypes().Where(type => type.IsClass && !type.IsAbstract));
160160
}
161161
}
162162
catch (ReflectionTypeLoadException e)
@@ -166,7 +166,7 @@ private static void GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(Assem
166166
if (e.Types?.Length > 0)
167167
{
168168
// Unloaded types on e.Types are null, make sure we skip them.
169-
types.AddRange(e.Types.Where(type => type != null && type.GetTypeInfo().IsClass && !type.GetTypeInfo().IsAbstract)!);
169+
types.AddRange(e.Types.Where(type => type != null && type.IsClass && !type.IsAbstract)!);
170170
}
171171

172172
if (e.LoaderExceptions != null)
@@ -209,7 +209,7 @@ private static void GetTestExtensionFromType<TPluginInfo>(
209209
string filePath)
210210
where TPluginInfo : TestPluginInformation
211211
{
212-
if (!extensionType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
212+
if (!extensionType.IsAssignableFrom(type))
213213
{
214214
return;
215215
}

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestDiscovererPluginInformation.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static List<string> GetFileExtensions(Type testDiscovererType)
9090
{
9191
var fileExtensions = new List<string>();
9292

93-
var attributes = testDiscovererType.GetTypeInfo().GetCustomAttributes(typeof(FileExtensionAttribute), inherit: false).ToArray();
93+
var attributes = testDiscovererType.GetCustomAttributes(typeof(FileExtensionAttribute), inherit: false).ToArray();
9494
if (attributes != null && attributes.Length > 0)
9595
{
9696
foreach (var attribute in attributes)
@@ -115,7 +115,7 @@ private static string GetDefaultExecutorUri(Type testDiscovererType)
115115
{
116116
var result = string.Empty;
117117

118-
var attributes = testDiscovererType.GetTypeInfo().GetCustomAttributes(typeof(DefaultExecutorUriAttribute), inherit: false).ToArray();
118+
var attributes = testDiscovererType.GetCustomAttributes(typeof(DefaultExecutorUriAttribute), inherit: false).ToArray();
119119
if (attributes != null && attributes.Length > 0)
120120
{
121121
DefaultExecutorUriAttribute executorUriAttribute = (DefaultExecutorUriAttribute)attributes[0];
@@ -138,7 +138,7 @@ private static AssemblyType GetAssemblyType(Type testDiscovererType)
138138
{
139139

140140
// Get Category
141-
var attribute = testDiscovererType.GetTypeInfo().GetCustomAttribute(typeof(CategoryAttribute));
141+
var attribute = testDiscovererType.GetCustomAttribute(typeof(CategoryAttribute));
142142
var category = (attribute as CategoryAttribute)?.Category;
143143

144144
// Get assembly type from category.
@@ -153,7 +153,7 @@ private static AssemblyType GetAssemblyType(Type testDiscovererType)
153153
/// <param name="testDiscovererType">Data type of the test discoverer</param>
154154
private static bool GetIsDirectoryBased(Type testDiscovererType)
155155
{
156-
var attribute = testDiscovererType.GetTypeInfo().GetCustomAttribute(typeof(DirectoryBasedTestDiscovererAttribute), inherit: false);
156+
var attribute = testDiscovererType.GetCustomAttribute(typeof(DirectoryBasedTestDiscovererAttribute), inherit: false);
157157
return attribute is DirectoryBasedTestDiscovererAttribute;
158158
}
159159
}

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensionPluginInformation.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Reflection;
87

98
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
109

@@ -68,7 +67,7 @@ private static string GetExtensionUri(Type testLoggerType)
6867
{
6968
string extensionUri = string.Empty;
7069

71-
object[] attributes = testLoggerType.GetTypeInfo().GetCustomAttributes(typeof(ExtensionUriAttribute), false).ToArray();
70+
object[] attributes = testLoggerType.GetCustomAttributes(typeof(ExtensionUriAttribute), false).ToArray();
7271
if (attributes.Length > 0)
7372
{
7473
ExtensionUriAttribute extensionUriAttribute = (ExtensionUriAttribute)attributes[0];
@@ -81,7 +80,7 @@ private static string GetExtensionUri(Type testLoggerType)
8180

8281
if (extensionUri.IsNullOrEmpty())
8382
{
84-
EqtTrace.Error("The type \"{0}\" defined in \"{1}\" does not have ExtensionUri attribute.", testLoggerType.ToString(), testLoggerType.GetTypeInfo().Module.Name);
83+
EqtTrace.Error("The type \"{0}\" defined in \"{1}\" does not have ExtensionUri attribute.", testLoggerType.ToString(), testLoggerType.Module.Name);
8584
}
8685

8786
return extensionUri;

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestExtensions.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Reflection;
87

98
using Microsoft.VisualStudio.TestPlatform.Common.DataCollector;
109
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
@@ -430,7 +429,7 @@ internal static Dictionary<string, TPluginInfo> GetExtensionsDiscoveredFromAssem
430429
var testPluginInformation = extension.Value as TestPluginInformation;
431430
// TODO: Avoid ArgumentNullException here
432431
var extensionType = Type.GetType(testPluginInformation?.AssemblyQualifiedName!);
433-
if (string.Equals(extensionType?.GetTypeInfo().Assembly.GetAssemblyLocation(), extensionAssembly))
432+
if (string.Equals(extensionType?.Assembly.GetAssemblyLocation(), extensionAssembly))
434433
{
435434
extensions.Add(extension.Key, extension.Value);
436435
}

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestLoggerPluginInformation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Reflection;
87

98
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
109

@@ -54,7 +53,7 @@ private static string GetFriendlyName(Type testLoggerType)
5453
{
5554
string friendlyName = string.Empty;
5655

57-
object[] attributes = testLoggerType.GetTypeInfo().GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
56+
object[] attributes = testLoggerType.GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
5857
if (attributes.Length > 0)
5958
{
6059
FriendlyNameAttribute friendlyNameAttribute = (FriendlyNameAttribute)attributes[0];

src/Microsoft.TestPlatform.Common/ExtensionFramework/Utilities/TestRunTimePluginInformation.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Reflection;
87

98
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
109

@@ -54,7 +53,7 @@ private static string GetFriendlyName(Type? testHostType)
5453
{
5554
string friendlyName = string.Empty;
5655

57-
object[]? attributes = testHostType?.GetTypeInfo().GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
56+
object[]? attributes = testHostType?.GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
5857
if (attributes != null && attributes.Length > 0)
5958
{
6059
FriendlyNameAttribute friendlyNameAttribute = (FriendlyNameAttribute)attributes[0];

0 commit comments

Comments
 (0)