Skip to content

Commit d7187b0

Browse files
authored
Remove unnecessary calls to GetTypeInfo (#27974)
1 parent 77fe36f commit d7187b0

File tree

88 files changed

+216
-227
lines changed

Some content is hidden

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

88 files changed

+216
-227
lines changed

src/Components/Server/src/BlazorPack/SequenceOfT.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ private class SequenceSegment : ReadOnlySequenceSegment<T>
299299
/// <summary>
300300
/// A value indicating whether the element is a value type.
301301
/// </summary>
302-
private static readonly bool IsValueTypeElement = typeof(T).GetTypeInfo().IsValueType;
302+
private static readonly bool IsValueTypeElement = typeof(T).IsValueType;
303303

304304
/// <summary>
305305
/// Gets the backing array, when using an <see cref="ArrayPool{T}"/> instead of a <see cref="MemoryPool{T}"/>.

src/Components/WebAssembly/Sdk/tools/Application.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -71,7 +71,7 @@ public Application(
7171

7272
private string GetInformationalVersion()
7373
{
74-
var assembly = typeof(Application).GetTypeInfo().Assembly;
74+
var assembly = typeof(Application).Assembly;
7575
var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
7676
return attribute.InformationalVersion;
7777
}
@@ -95,4 +95,4 @@ private static string[] ExpandResponseFiles(string[] args)
9595
return expandedArgs.ToArray();
9696
}
9797
}
98-
}
98+
}

src/Components/WebAssembly/WebAssembly/test/Hosting/EntrypointInvokerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static class Program
137137
var compilation = CSharpCompilation.Create(
138138
$"TestAssembly-{Guid.NewGuid().ToString("D")}",
139139
new[] { syntaxTree },
140-
new[] { MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location) },
140+
new[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location) },
141141
new CSharpCompilationOptions(OutputKind.ConsoleApplication));
142142
using var ms = new MemoryStream();
143143
var compilationResult = compilation.Emit(ms);

src/DataProtection/DataProtection/test/TypeForwardingActivatorTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,14 @@ private void CreateInstance_ForwardsAcrossVersionChangesImpl(Version newVersion)
110110
{
111111
var activator = new TypeForwardingActivator(null);
112112

113-
var typeInfo = typeof(ClassWithParameterlessCtor).GetTypeInfo();
114-
var typeName = typeInfo.FullName;
115-
var assemblyName = typeInfo.Assembly.GetName();
113+
var type = typeof(ClassWithParameterlessCtor);
114+
var typeName = type.FullName;
115+
var assemblyName = type.Assembly.GetName();
116116

117117
assemblyName.Version = newVersion;
118118
var newName = $"{typeName}, {assemblyName}";
119119

120-
Assert.NotEqual(typeInfo.AssemblyQualifiedName, newName);
120+
Assert.NotEqual(type.AssemblyQualifiedName, newName);
121121
Assert.IsType<ClassWithParameterlessCtor>(activator.CreateInstance(typeof(object), newName, out var forwarded));
122122
Assert.True(forwarded, "Should have forwarded this type to new version or namespace");
123123
}

src/DefaultBuilder/src/WebHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static IWebHost Start(RequestDelegate app) =>
4242
/// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
4343
public static IWebHost Start(string url, RequestDelegate app)
4444
{
45-
var startupAssemblyName = app.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name;
45+
var startupAssemblyName = app.GetMethodInfo().DeclaringType!.Assembly.GetName().Name;
4646
return StartWith(url: url, configureServices: null, app: appBuilder => appBuilder.Run(app), applicationName: startupAssemblyName);
4747
}
4848

@@ -64,7 +64,7 @@ public static IWebHost Start(Action<IRouteBuilder> routeBuilder) =>
6464
/// <returns>A started <see cref="IWebHost"/> that hosts the application.</returns>
6565
public static IWebHost Start(string url, Action<IRouteBuilder> routeBuilder)
6666
{
67-
var startupAssemblyName = routeBuilder.GetMethodInfo().DeclaringType!.GetTypeInfo().Assembly.GetName().Name;
67+
var startupAssemblyName = routeBuilder.GetMethodInfo().DeclaringType!.Assembly.GetName().Name;
6868
return StartWith(url, services => services.AddRouting(), appBuilder => appBuilder.UseRouter(routeBuilder), applicationName: startupAssemblyName);
6969
}
7070

src/Features/JsonPatch/src/Converters/TypedJsonPatchDocumentConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override object ReadJson(
2626
return null;
2727
}
2828

29-
var genericType = objectType.GetTypeInfo().GenericTypeArguments[0];
29+
var genericType = objectType.GenericTypeArguments[0];
3030

3131
// load jObject
3232
var jObject = JArray.Load(reader);
@@ -61,4 +61,4 @@ public override object ReadJson(
6161
}
6262
}
6363
}
64-
}
64+
}

src/Features/JsonPatch/src/Internal/ConversionResultProvider.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -63,11 +63,10 @@ public static ConversionResult CopyTo(object value, Type typeToConvertTo)
6363

6464
private static bool IsNullableType(Type type)
6565
{
66-
var typeInfo = type.GetTypeInfo();
67-
if (typeInfo.IsValueType)
66+
if (type.IsValueType)
6867
{
6968
// value types are only nullable if they are Nullable<T>
70-
return typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
69+
return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>);
7170
}
7271
else
7372
{

src/Features/JsonPatch/src/Internal/DynamicObjectAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -66,7 +66,7 @@ public virtual bool TryRemove(
6666
// Setting the value to "null" will use the default value in case of value types, and
6767
// null in case of reference types
6868
object value = null;
69-
if (property.GetType().GetTypeInfo().IsValueType
69+
if (property.GetType().IsValueType
7070
&& Nullable.GetUnderlyingType(property.GetType()) == null)
7171
{
7272
value = Activator.CreateInstance(property.GetType());

src/Features/JsonPatch/src/Internal/PocoAdapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -94,7 +94,7 @@ public virtual bool TryRemove(
9494
// Setting the value to "null" will use the default value in case of value types, and
9595
// null in case of reference types
9696
object value = null;
97-
if (jsonProperty.PropertyType.GetTypeInfo().IsValueType
97+
if (jsonProperty.PropertyType.IsValueType
9898
&& Nullable.GetUnderlyingType(jsonProperty.PropertyType) == null)
9999
{
100100
value = Activator.CreateInstance(jsonProperty.PropertyType);

src/FileProviders/Embedded/test/EmbeddedFileProviderTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void ConstructorWithNullAssemblyThrowsArgumentException()
2323
public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExist()
2424
{
2525
// Arrange
26-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
26+
var provider = new EmbeddedFileProvider(GetType().Assembly);
2727

2828
// Act
2929
var fileInfo = provider.GetFileInfo("DoesNotExist.Txt");
@@ -39,7 +39,7 @@ public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExist()
3939
public void GetFileInfo_ReturnsFilesAtRoot(string filePath)
4040
{
4141
// Arrange
42-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
42+
var provider = new EmbeddedFileProvider(GetType().Assembly);
4343
var expectedFileLength = 8;
4444

4545
// Act
@@ -59,7 +59,7 @@ public void GetFileInfo_ReturnsFilesAtRoot(string filePath)
5959
public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExistUnderSpecifiedNamespace()
6060
{
6161
// Arrange
62-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace + ".SubNamespace");
62+
var provider = new EmbeddedFileProvider(GetType().Assembly, Namespace + ".SubNamespace");
6363

6464
// Act
6565
var fileInfo = provider.GetFileInfo("File.txt");
@@ -73,7 +73,7 @@ public void GetFileInfo_ReturnsNotFoundFileInfo_IfFileDoesNotExistUnderSpecified
7373
public void GetFileInfo_ReturnsNotFoundIfPathStartsWithBackSlash()
7474
{
7575
// Arrange
76-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
76+
var provider = new EmbeddedFileProvider(GetType().Assembly);
7777

7878
// Act
7979
var fileInfo = provider.GetFileInfo("\\File.txt");
@@ -106,7 +106,7 @@ public static TheoryData GetFileInfo_LocatesFilesUnderSpecifiedNamespaceData
106106
public void GetFileInfo_LocatesFilesUnderSpecifiedNamespace(string path)
107107
{
108108
// Arrange
109-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace + ".Resources");
109+
var provider = new EmbeddedFileProvider(GetType().Assembly, Namespace + ".Resources");
110110

111111
// Act
112112
var fileInfo = provider.GetFileInfo(path);
@@ -144,7 +144,7 @@ public static TheoryData GetFileInfo_LocatesFilesUnderSubDirectoriesData
144144
public void GetFileInfo_LocatesFilesUnderSubDirectories(string path)
145145
{
146146
// Arrange
147-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
147+
var provider = new EmbeddedFileProvider(GetType().Assembly);
148148

149149
// Act
150150
var fileInfo = provider.GetFileInfo(path);
@@ -165,7 +165,7 @@ public void GetFileInfo_LocatesFilesUnderSubDirectories(string path)
165165
public void GetDirectoryContents_ReturnsAllFilesInFileSystem(string path)
166166
{
167167
// Arrange
168-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, Namespace + ".Resources");
168+
var provider = new EmbeddedFileProvider(GetType().Assembly, Namespace + ".Resources");
169169

170170
// Act
171171
var files = provider.GetDirectoryContents(path);
@@ -185,7 +185,7 @@ public void GetDirectoryContents_ReturnsAllFilesInFileSystem(string path)
185185
public void GetDirectoryContents_ReturnsEmptySequence_IfResourcesDoNotExistUnderNamespace()
186186
{
187187
// Arrange
188-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "Unknown.Namespace");
188+
var provider = new EmbeddedFileProvider(GetType().Assembly, "Unknown.Namespace");
189189

190190
// Act
191191
var files = provider.GetDirectoryContents(string.Empty);
@@ -202,7 +202,7 @@ public void GetDirectoryContents_ReturnsEmptySequence_IfResourcesDoNotExistUnder
202202
public void GetDirectoryContents_ReturnsNotFoundDirectoryContents_IfHierarchicalPathIsSpecified(string path)
203203
{
204204
// Arrange
205-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
205+
var provider = new EmbeddedFileProvider(GetType().Assembly);
206206

207207
// Act
208208
var files = provider.GetDirectoryContents(path);
@@ -217,7 +217,7 @@ public void GetDirectoryContents_ReturnsNotFoundDirectoryContents_IfHierarchical
217217
public void Watch_ReturnsNoOpTrigger()
218218
{
219219
// Arange
220-
var provider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly);
220+
var provider = new EmbeddedFileProvider(GetType().Assembly);
221221

222222
// Act
223223
var token = provider.Watch("Resources/File.txt");
@@ -228,4 +228,4 @@ public void Watch_ReturnsNoOpTrigger()
228228
Assert.False(token.HasChanged);
229229
}
230230
}
231-
}
231+
}

0 commit comments

Comments
 (0)