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 unnecessary GetTypeInfo() calls. #51339

Merged
merged 3 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private static Expression Convert(Expression expression, Type type, bool forceVa
{
// Don't convert if the expression is already assignable
if (type.IsAssignableFrom(expression.Type)
&& (!expression.Type.GetTypeInfo().IsValueType || !forceValueTypeConversion))
&& (!expression.Type.IsValueType || !forceValueTypeConversion))
{
return expression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,7 @@ private void SetResourceAccessorByPropertyLookup()
Debug.Assert(_errorMessageResourceType != null);
Debug.Assert(!string.IsNullOrEmpty(_errorMessageResourceName));
var property = _errorMessageResourceType
.GetTypeInfo().GetDeclaredProperty(_errorMessageResourceName);
if (property != null && !ValidationAttributeStore.IsStatic(property))
{
property = null;
}
.GetProperty(_errorMessageResourceName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly);

if (property != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ private static void EnsureValidationContext(ValidationContext validationContext)
internal static bool IsPublic(PropertyInfo p) =>
(p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic);

internal static bool IsStatic(PropertyInfo p) =>
(p.GetMethod != null && p.GetMethod.IsStatic) || (p.SetMethod != null && p.SetMethod.IsStatic);

/// <summary>
/// Private abstract class for all store items
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public static bool IsValidInstanceType(MemberInfo member, Type instanceType)
// been boxed or not.
if (targetType.IsInterface)
{
foreach (Type interfaceType in instanceType.GetTypeInfo().ImplementedInterfaces)
foreach (Type interfaceType in instanceType.GetInterfaces())
{
if (AreReferenceAssignable(targetType, interfaceType))
{
Expand Down Expand Up @@ -808,7 +808,7 @@ private static bool IsImplicitNullableConversion(Type source, Type destination)

if (definition.IsInterface)
{
foreach (Type itype in type.GetTypeInfo().ImplementedInterfaces)
foreach (Type itype in type.GetInterfaces())
{
Type? found = FindGenericType(definition, itype);
if (found != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private Type GetEquivalentType(Type type)
}
if (equiv == null)
{
var interfacesWithInfo = pubType.GetInterfaces().Select(IntrospectionExtensions.GetTypeInfo).ToArray();
var interfacesWithInfo = pubType.GetInterfaces();
var singleTypeGenInterfacesWithGetType = interfacesWithInfo
.Where(i => i.IsGenericType && i.GenericTypeArguments.Length == 1)
.Select(i => new { Info = i, GenType = i.GetGenericTypeDefinition() })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1209,9 +1209,9 @@ private static bool ShouldBeReplaced(
{
while (currentType != typeToBeReplaced)
{
TypeInfo currentInfo = currentType.GetTypeInfo();
const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

foreach (PropertyInfo info in currentInfo.DeclaredProperties)
foreach (PropertyInfo info in currentType.GetProperties(DeclaredOnlyLookup))
{
if (info.Name == memberInfoToBeReplaced.Name)
{
Expand All @@ -1232,7 +1232,7 @@ private static bool ShouldBeReplaced(
}
}

foreach (FieldInfo info in currentInfo.DeclaredFields)
foreach (FieldInfo info in currentType.GetFields(DeclaredOnlyLookup))
{
if (info.Name == memberInfoToBeReplaced.Name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static class DispatchProxyGenerator
// Proxy instances are not cached. Their lifetime is entirely owned by the caller of DispatchProxy.Create.
private static readonly Dictionary<Type, Dictionary<Type, GeneratedTypeInfo>> s_baseTypeAndInterfaceToGeneratedProxyType = new Dictionary<Type, Dictionary<Type, GeneratedTypeInfo>>();
private static readonly ProxyAssembly s_proxyAssembly = new ProxyAssembly();
private static readonly MethodInfo s_dispatchProxyInvokeMethod = typeof(DispatchProxy).GetTypeInfo().GetDeclaredMethod("Invoke")!;
private static readonly MethodInfo s_dispatchProxyInvokeMethod = typeof(DispatchProxy).GetMethod("Invoke", BindingFlags.NonPublic | BindingFlags.Instance)!;
private static readonly MethodInfo s_getTypeFromHandleMethod = typeof(Type).GetRuntimeMethod("GetTypeFromHandle", new Type[] { typeof(RuntimeTypeHandle) })!;
private static readonly MethodInfo s_makeGenericMethodMethod = typeof(MethodInfo).GetMethod("MakeGenericMethod", new Type[] { typeof(Type[]) })!;

Expand Down