Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove redundant GetTypeInfo #4519

Merged
merged 13 commits into from
Jun 6, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static void GetManagedNameAndHierarchy(MethodBase method, bool useClosed
hierarchyValues[HierarchyConstants.Levels.ClassIndex] = managedTypeName.Substring(hierarchyPos[1] + 1, hierarchyPos[2] - hierarchyPos[1] - 1);
hierarchyValues[HierarchyConstants.Levels.NamespaceIndex] = managedTypeName.Substring(hierarchyPos[0], hierarchyPos[1] - hierarchyPos[0]);
}
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.GetTypeInfo()?.Assembly?.GetName()?.Name ?? string.Empty;
hierarchyValues[HierarchyConstants.Levels.ContainerIndex] = method.DeclaringType?.Assembly?.GetName()?.Name ?? string.Empty;
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.TestPlatform.Client/TestPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Client.Discovery;
using Microsoft.VisualStudio.TestPlatform.Client.Execution;
Expand Down Expand Up @@ -292,7 +291,7 @@ private static void AddExtensionAssembliesFromExtensionDirectory()
}

string extensionsFolder = Path.Combine(
Path.GetDirectoryName(typeof(TestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation())!,
Path.GetDirectoryName(typeof(TestPlatform).Assembly.GetAssemblyLocation())!,
"Extensions");
if (!fileHelper.DirectoryExists(extensionsFolder))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

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

// If any attribute constructor on the type throws, the exception will bubble up through
// the "GetCustomAttributes" method.
return dataCollectorType.GetTypeInfo().GetCustomAttributes(attributeType, true).ToArray();
return dataCollectorType.GetCustomAttributes(attributeType, true).ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ internal static IList<string> GetResolutionPaths(string extensionAssembly)
var extensionDirectory = Path.GetDirectoryName(Path.GetFullPath(extensionAssembly))!;
resolutionPaths.Add(extensionDirectory);

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

// Keep current directory for resolution
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.GetAssemblyLocation())!;
var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).Assembly.GetAssemblyLocation())!;
if (!resolutionPaths.Contains(currentDirectory))
{
resolutionPaths.Add(currentDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private static void GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(Assem

if (types.Count == 0)
{
types.AddRange(assembly.GetTypes().Where(type => type.GetTypeInfo() is { } typeInfo && typeInfo.IsClass && !typeInfo.IsAbstract));
types.AddRange(assembly.GetTypes().Where(type => type.IsClass && !type.IsAbstract));
}
}
catch (ReflectionTypeLoadException e)
Expand All @@ -166,7 +166,7 @@ private static void GetTestExtensionsFromAssembly<TPluginInfo, TExtension>(Assem
if (e.Types?.Length > 0)
{
// Unloaded types on e.Types are null, make sure we skip them.
types.AddRange(e.Types.Where(type => type != null && type.GetTypeInfo().IsClass && !type.GetTypeInfo().IsAbstract)!);
types.AddRange(e.Types.Where(type => type != null && type.IsClass && !type.IsAbstract)!);
}

if (e.LoaderExceptions != null)
Expand Down Expand Up @@ -209,7 +209,7 @@ private static void GetTestExtensionFromType<TPluginInfo>(
string filePath)
where TPluginInfo : TestPluginInformation
{
if (!extensionType.GetTypeInfo().IsAssignableFrom(type.GetTypeInfo()))
if (!extensionType.IsAssignableFrom(type))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static List<string> GetFileExtensions(Type testDiscovererType)
{
var fileExtensions = new List<string>();

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

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

// Get Category
var attribute = testDiscovererType.GetTypeInfo().GetCustomAttribute(typeof(CategoryAttribute));
var attribute = testDiscovererType.GetCustomAttribute(typeof(CategoryAttribute));
var category = (attribute as CategoryAttribute)?.Category;

// Get assembly type from category.
Expand All @@ -153,7 +153,7 @@ private static AssemblyType GetAssemblyType(Type testDiscovererType)
/// <param name="testDiscovererType">Data type of the test discoverer</param>
private static bool GetIsDirectoryBased(Type testDiscovererType)
{
var attribute = testDiscovererType.GetTypeInfo().GetCustomAttribute(typeof(DirectoryBasedTestDiscovererAttribute), inherit: false);
var attribute = testDiscovererType.GetCustomAttribute(typeof(DirectoryBasedTestDiscovererAttribute), inherit: false);
return attribute is DirectoryBasedTestDiscovererAttribute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Expand Down Expand Up @@ -68,7 +67,7 @@ private static string GetExtensionUri(Type testLoggerType)
{
string extensionUri = string.Empty;

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

if (extensionUri.IsNullOrEmpty())
{
EqtTrace.Error("The type \"{0}\" defined in \"{1}\" does not have ExtensionUri attribute.", testLoggerType.ToString(), testLoggerType.GetTypeInfo().Module.Name);
EqtTrace.Error("The type \"{0}\" defined in \"{1}\" does not have ExtensionUri attribute.", testLoggerType.ToString(), testLoggerType.Module.Name);
}

return extensionUri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Common.DataCollector;
using Microsoft.VisualStudio.TestPlatform.Common.Telemetry;
Expand Down Expand Up @@ -430,7 +429,7 @@ internal static Dictionary<string, TPluginInfo> GetExtensionsDiscoveredFromAssem
var testPluginInformation = extension.Value as TestPluginInformation;
// TODO: Avoid ArgumentNullException here
var extensionType = Type.GetType(testPluginInformation?.AssemblyQualifiedName!);
if (string.Equals(extensionType?.GetTypeInfo().Assembly.GetAssemblyLocation(), extensionAssembly))
if (string.Equals(extensionType?.Assembly.GetAssemblyLocation(), extensionAssembly))
{
extensions.Add(extension.Key, extension.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Expand Down Expand Up @@ -54,7 +53,7 @@ private static string GetFriendlyName(Type testLoggerType)
{
string friendlyName = string.Empty;

object[] attributes = testLoggerType.GetTypeInfo().GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
object[] attributes = testLoggerType.GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
if (attributes.Length > 0)
{
FriendlyNameAttribute friendlyNameAttribute = (FriendlyNameAttribute)attributes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Expand Down Expand Up @@ -54,7 +53,7 @@ private static string GetFriendlyName(Type? testHostType)
{
string friendlyName = string.Empty;

object[]? attributes = testHostType?.GetTypeInfo().GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
object[]? attributes = testHostType?.GetCustomAttributes(typeof(FriendlyNameAttribute), false).ToArray();
if (attributes != null && attributes.Length > 0)
{
FriendlyNameAttribute friendlyNameAttribute = (FriendlyNameAttribute)attributes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Expand Down Expand Up @@ -68,7 +67,7 @@ private static string GetTestSettingsName(Type testSettingsProviderType)
{
string settingName = string.Empty;

object[] attributes = testSettingsProviderType.GetTypeInfo().GetCustomAttributes(typeof(SettingsNameAttribute), false).ToArray();
object[] attributes = testSettingsProviderType.GetCustomAttributes(typeof(SettingsNameAttribute), false).ToArray();
if (attributes != null && attributes.Length > 0)
{
SettingsNameAttribute settingsNameAttribute = (SettingsNameAttribute)attributes[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions;
using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces;
Expand All @@ -25,7 +24,7 @@ public InstallationContext(IFileHelper fileHelper)

public bool TryGetVisualStudioDirectory(out string visualStudioDirectory)
{
var vsInstallPath = new DirectoryInfo(typeof(InstallationContext).GetTypeInfo().Assembly.GetAssemblyLocation()).Parent?.Parent?.Parent?.FullName;
var vsInstallPath = new DirectoryInfo(typeof(InstallationContext).Assembly.GetAssemblyLocation()).Parent?.Parent?.Parent?.FullName;
if (!vsInstallPath.IsNullOrEmpty())
{
var pathToDevenv = Path.Combine(vsInstallPath, DevenvExe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
Expand Down Expand Up @@ -53,7 +52,7 @@ internal DefaultDataCollectionLauncher(IProcessHelper processHelper, IMessageLog
/// <returns>ProcessId of launched Process. 0 means not launched.</returns>
public override int LaunchDataCollector(IDictionary<string, string?>? environmentVariables, IList<string> commandLineArguments)
{
var dataCollectorDirectory = Path.GetDirectoryName(typeof(DefaultDataCollectionLauncher).GetTypeInfo().Assembly.GetAssemblyLocation());
var dataCollectorDirectory = Path.GetDirectoryName(typeof(DefaultDataCollectionLauncher).Assembly.GetAssemblyLocation());
TPDebug.Assert(dataCollectorDirectory is not null, "dataCollectorDirectory is not null");

var currentProcessPath = _processHelper.GetCurrentProcessFileName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;

using Microsoft.VisualStudio.TestPlatform.Common.Logging;
using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions;
Expand Down Expand Up @@ -62,7 +61,7 @@ internal DotnetDataCollectionLauncher(IProcessHelper processHelper, IFileHelper
/// <returns>ProcessId of launched Process. 0 means not launched.</returns>
public override int LaunchDataCollector(IDictionary<string, string?>? environmentVariables, IList<string> commandLineArguments)
{
var dataCollectorDirectory = Path.GetDirectoryName(typeof(DefaultDataCollectionLauncher).GetTypeInfo().Assembly.GetAssemblyLocation());
var dataCollectorDirectory = Path.GetDirectoryName(typeof(DefaultDataCollectionLauncher).Assembly.GetAssemblyLocation());
TPDebug.Assert(dataCollectorDirectory is not null, "dataCollectorDirectory is null");

var dataCollectorAssemblyPath = Path.Combine(dataCollectorDirectory, DataCollectorProcessName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
Expand Down Expand Up @@ -100,12 +99,12 @@ protected InProcDataCollectionExtensionManager(string? runSettings, ITestEventsP
/// <returns>
/// The <see cref="IInProcDataCollector"/>.
/// </returns>
protected virtual IInProcDataCollector CreateDataCollector(string assemblyQualifiedName, string codebase, XmlElement configuration, TypeInfo interfaceTypeInfo)
protected virtual IInProcDataCollector CreateDataCollector(string assemblyQualifiedName, string codebase, XmlElement configuration, Type interfaceType)
{
var inProcDataCollector = new InProcDataCollector(
codebase,
assemblyQualifiedName,
interfaceTypeInfo,
interfaceType,
configuration?.OuterXml);

inProcDataCollector.LoadDataCollector(_inProcDataCollectionSink);
Expand Down Expand Up @@ -215,7 +214,7 @@ private void InitializeInProcDataCollectors(string? runSettings)

_inProcDataCollectorSettingsCollection = inProcDataCollectionRunSettings!.DataCollectorSettingsList;

var interfaceTypeInfo = typeof(InProcDataCollection).GetTypeInfo();
var interfaceTypeInfo = typeof(InProcDataCollection);
foreach (var inProcDc in _inProcDataCollectorSettingsCollection)
{
var codeBase = GetCodebase(inProcDc.CodeBase!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ internal class InProcDataCollector : IInProcDataCollector
public InProcDataCollector(
string codeBase,
string assemblyQualifiedName,
TypeInfo interfaceTypeInfo,
Type interfaceType,
string? configXml)
: this(codeBase, assemblyQualifiedName, interfaceTypeInfo, configXml, new PlatformAssemblyLoadContext(), TestPluginCache.Instance)
: this(codeBase, assemblyQualifiedName, interfaceType, configXml, new PlatformAssemblyLoadContext(), TestPluginCache.Instance)
{
}

Expand All @@ -63,7 +63,7 @@ public InProcDataCollector(
/// </param>
/// <param name="assemblyLoadContext">
/// </param>
internal InProcDataCollector(string codeBase, string assemblyQualifiedName, TypeInfo interfaceTypeInfo, string? configXml, IAssemblyLoadContext assemblyLoadContext, TestPluginCache testPluginCache)
internal InProcDataCollector(string codeBase, string assemblyQualifiedName, Type interfaceType, string? configXml, IAssemblyLoadContext assemblyLoadContext, TestPluginCache testPluginCache)
{
_configXml = configXml;
_assemblyLoadContext = assemblyLoadContext;
Expand All @@ -75,15 +75,15 @@ internal InProcDataCollector(string codeBase, string assemblyQualifiedName, Type
{
// If we're loading coverlet collector we skip to check the version of assembly
// to allow upgrade through nuget package
filterPredicate = x => Constants.CoverletDataCollectorTypeName.Equals(x.FullName) && interfaceTypeInfo.IsAssignableFrom(x.GetTypeInfo());
filterPredicate = x => Constants.CoverletDataCollectorTypeName.Equals(x.FullName) && interfaceType.IsAssignableFrom(x);

// Coverlet collector is consumed as nuget package we need to add assemblies directory to resolver to correctly load references.
TPDebug.Assert(Path.IsPathRooted(codeBase), "Absolute path expected");
testPluginCache.AddResolverSearchDirectories(new string[] { Path.GetDirectoryName(codeBase)! });
}
else
{
filterPredicate = x => string.Equals(x.AssemblyQualifiedName, assemblyQualifiedName) && interfaceTypeInfo.IsAssignableFrom(x.GetTypeInfo());
filterPredicate = x => string.Equals(x.AssemblyQualifiedName, assemblyQualifiedName) && interfaceType.IsAssignableFrom(x);
}

_dataCollectorType = assembly?.GetTypes().FirstOrDefault(filterPredicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;

using Microsoft.VisualStudio.TestPlatform.Common.DataCollection;
Expand Down Expand Up @@ -348,7 +347,7 @@ private static string GetTimestampedLogFile(string logFile)
return settingsXml;
}

var extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(ITestPlatform).GetTypeInfo().Assembly.GetAssemblyLocation())!, "Extensions");
var extensionsFolder = Path.Combine(Path.GetDirectoryName(typeof(ITestPlatform).Assembly.GetAssemblyLocation())!, "Extensions");

using var stream = new StringReader(settingsXml);
using var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
Expand Down Expand Up @@ -296,7 +295,7 @@ private static bool IsDiscovererFromDeprecatedLocations(
return false;
}

var discovererLocation = discoverer.Value.GetType().GetTypeInfo().Assembly.GetAssemblyLocation();
var discovererLocation = discoverer.Value.GetType().Assembly.GetAssemblyLocation();

return Path.GetDirectoryName(discovererLocation)!
.Equals(Constants.DefaultAdapterLocation, StringComparison.OrdinalIgnoreCase);
Expand Down
Loading