Remove some unnecessary GetTypeInfo usage (#44414)
authorStephen Toub <stoub@microsoft.com>
Mon, 9 Nov 2020 21:11:41 +0000 (16:11 -0500)
committerGitHub <noreply@github.com>
Mon, 9 Nov 2020 21:11:41 +0000 (13:11 -0800)
16 files changed:
src/libraries/System.Drawing.Common/src/System/Drawing/Bitmap.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/FontConverter.cs
src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ImageFormatConverter.cs
src/libraries/System.Drawing.Common/src/System/Drawing/ToolboxBitmapAttribute.Unix.cs
src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/PropertyValue.cs
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/TraceLogging/SimpleTypeInfos.cs
src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
src/libraries/System.Private.Xml.Linq/src/System/Xml/Linq/XHelper.cs
src/libraries/System.Private.Xml/src/ILLink/ILLink.Suppressions.xml
src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationReader.cs
src/libraries/System.Private.Xml/src/System/Xml/Serialization/ReflectionXmlSerializationWriter.cs
src/libraries/System.Security.AccessControl/src/System/Security/AccessControl/ObjectSecurity.cs
src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/IRCollection.cs
src/libraries/System.Text.Encoding.CodePages/src/System/Text/BaseCodePageEncoding.cs

index 7142f89..f35f980 100644 (file)
@@ -74,7 +74,7 @@ namespace System.Drawing
             if (type == null)
                 throw new NullReferenceException();
 
-            Stream? s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource);
+            Stream? s = type.Assembly.GetManifestResourceStream(type, resource);
             if (s == null)
             {
                 string msg = string.Format("Resource '{0}' was not found.", resource);
index 99a327b..ec5d71b 100644 (file)
@@ -87,7 +87,7 @@ namespace System.Drawing
 
                 if (destinationType == typeof(InstanceDescriptor))
                 {
-                    ConstructorInfo? met = typeof(Font).GetTypeInfo().GetConstructor(new Type[] { typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit) });
+                    ConstructorInfo? met = typeof(Font).GetConstructor(new Type[] { typeof(string), typeof(float), typeof(FontStyle), typeof(GraphicsUnit) });
                     object[] args = new object[4];
                     args[0] = font.Name;
                     args[1] = font.Size;
index 4cb6653..9c4b2dd 100644 (file)
@@ -247,7 +247,7 @@ namespace System.Drawing
             if (type == null)
                 throw new NullReferenceException();
 
-            using (Stream? s = type.GetTypeInfo().Assembly.GetManifestResourceStream(type, resource))
+            using (Stream? s = type.Assembly.GetManifestResourceStream(type, resource))
             {
                 if (s == null)
                 {
@@ -259,7 +259,7 @@ namespace System.Drawing
 
         internal Icon(string resourceName, bool undisposable)
         {
-            using (Stream? s = typeof(Icon).GetTypeInfo().Assembly.GetManifestResourceStream(resourceName))
+            using (Stream? s = typeof(Icon).Assembly.GetManifestResourceStream(resourceName))
             {
                 if (s == null)
                 {
index 908477d..5fc55f1 100644 (file)
@@ -101,11 +101,11 @@ namespace System.Drawing
 
                     if (strFormat != null)
                     {
-                        return new InstanceDescriptor(typeof(ImageFormat).GetTypeInfo().GetProperty(strFormat), null);
+                        return new InstanceDescriptor(typeof(ImageFormat).GetProperty(strFormat), null);
                     }
                     else
                     {
-                        ConstructorInfo? ctor = typeof(ImageFormat).GetTypeInfo().GetConstructor(new Type[] { typeof(Guid) });
+                        ConstructorInfo? ctor = typeof(ImageFormat).GetConstructor(new Type[] { typeof(Guid) });
                         return new InstanceDescriptor(ctor, new object[] { imgFormat.Guid });
                     }
                 }
index d3815a0..51708e3 100644 (file)
@@ -122,7 +122,7 @@ namespace System.Drawing
 
             try
             {
-                using (System.IO.Stream? s = t.GetTypeInfo().Assembly.GetManifestResourceStream(t.Namespace + "." + imageName))
+                using (System.IO.Stream? s = t.Assembly.GetManifestResourceStream(t.Namespace + "." + imageName))
                 {
                     if (s == null)
                     {
index 52ce76b..1652352 100644 (file)
@@ -59,7 +59,7 @@ namespace System.Drawing
                     Type? driver_type = asm.GetType("System.Windows.Forms.XplatUICarbon");
                     if (driver_type != null)
                     {
-                        return (Delegate?)driver_type.GetTypeInfo().GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null);
+                        return (Delegate?)driver_type.GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null);
                     }
                 }
             }
index a40f619..0e730ab 100644 (file)
@@ -164,7 +164,7 @@ namespace System.Diagnostics.Tracing
         /// </summary>
         public static Func<PropertyValue, PropertyValue> GetPropertyGetter(PropertyInfo property)
         {
-            if (property.DeclaringType!.GetTypeInfo().IsValueType)
+            if (property.DeclaringType!.IsValueType)
                 return GetBoxedValueTypePropertyGetter(property);
             else
                 return GetReferenceTypePropertyGetter(property);
@@ -180,7 +180,7 @@ namespace System.Diagnostics.Tracing
         {
             Type type = property.PropertyType;
 
-            if (type.GetTypeInfo().IsEnum)
+            if (type.IsEnum)
                 type = Enum.GetUnderlyingType(type);
 
             Func<object?, PropertyValue> factory = GetFactory(type);
@@ -224,7 +224,7 @@ namespace System.Diagnostics.Tracing
                 }
                 else
                 {
-                    if (type.GetTypeInfo().IsEnum)
+                    if (type.IsEnum)
                         type = Enum.GetUnderlyingType(type);
 
                     if (type == typeof(bool)) { var f = (Func<TContainer, bool>)GetGetMethod(property, type); return container => new PropertyValue(f((TContainer)container.ReferenceValue!)); }
index 5b26919..e51c6c7 100644 (file)
@@ -275,7 +275,7 @@ namespace System.Diagnostics.Tracing
             Type[] typeArgs = type.GenericTypeArguments;
             Debug.Assert(typeArgs.Length == 1);
             this.valueInfo = TraceLoggingTypeInfo.GetInstance(typeArgs[0], recursionCheck);
-            this.valueGetter = PropertyValue.GetPropertyGetter(type.GetTypeInfo().GetDeclaredProperty("Value")!);
+            this.valueGetter = PropertyValue.GetPropertyGetter(type.GetProperty("Value")!);
         }
 
         public override void WriteMetadata(
index 1037481..6e5e7eb 100644 (file)
@@ -44,7 +44,7 @@ namespace System
                 Func<string, object> createDirectory = LazyInitializer.EnsureInitialized(ref s_directoryCreateDirectory, static () =>
                 {
                     Type dirType = Type.GetType("System.IO.Directory, System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", throwOnError: true)!;
-                    MethodInfo mi = dirType.GetTypeInfo().GetDeclaredMethod("CreateDirectory")!;
+                    MethodInfo mi = dirType.GetMethod("CreateDirectory", BindingFlags.Public | BindingFlags.Static)!;
                     return mi.CreateDelegate<Func<string, object>>();
                 });
                 createDirectory(path);
index f127fe0..dd0b194 100644 (file)
@@ -13,10 +13,7 @@ namespace System.Xml.Linq
         {
             Debug.Assert(type != null);
 
-            if (o == null)
-                return false;
-
-            return type.GetTypeInfo().IsAssignableFrom(o.GetType().GetTypeInfo());
+            return o != null && type.IsAssignableFrom(o.GetType());
         }
     }
 }
index e9162ee..2feabe0 100644 (file)
@@ -83,7 +83,7 @@
       <argument>ILLink</argument>
       <argument>IL2070</argument>
       <property name="Scope">member</property>
-      <property name="Target">M:System.Xml.Serialization.ReflectionXmlSerializationReader.FindDefaultConstructor(System.Reflection.TypeInfo)</property>
+      <property name="Target">M:System.Xml.Serialization.ReflectionXmlSerializationReader.GetDefaultConstructor(System.Type)</property>
     </attribute>
     <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
       <argument>ILLink</argument>
       <property name="Target">M:System.Xml.Xsl.Runtime.XmlExtensionFunction.CanBind</property>
     </attribute>
   </assembly>
-</linker>
\ No newline at end of file
+</linker>
index 0458a4e..9234435 100644 (file)
@@ -1295,27 +1295,9 @@ namespace System.Xml.Serialization
             return obj;
         }
 
-        private ConstructorInfo? GetDefaultConstructor(Type type)
-        {
-            if (type.IsValueType)
-                return null;
-
-            ConstructorInfo? ctor = FindDefaultConstructor(type.GetTypeInfo());
-            return ctor;
-        }
-
-        private static ConstructorInfo? FindDefaultConstructor(TypeInfo ti)
-        {
-            foreach (ConstructorInfo ci in ti.DeclaredConstructors)
-            {
-                if (!ci.IsStatic && ci.GetParameters().Length == 0)
-                {
-                    return ci;
-                }
-            }
-
-            return null;
-        }
+        private ConstructorInfo? GetDefaultConstructor(Type type) =>
+            type.IsValueType ? null :
+            type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null);
 
         private object? WriteEncodedStructMethod(StructMapping structMapping)
         {
index 705dfcb..1bbf66d 100644 (file)
@@ -576,7 +576,7 @@ namespace System.Xml.Serialization
                     if (m.CheckShouldPersist)
                     {
                         string methodInvoke = "ShouldSerialize" + m.Name;
-                        MethodInfo method = o!.GetType().GetTypeInfo().GetDeclaredMethod(methodInvoke)!;
+                        MethodInfo method = o!.GetType().GetMethod(methodInvoke, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)!;
                         shouldPersist = (bool)method.Invoke(o, Array.Empty<object>())!;
                     }
 
@@ -608,7 +608,7 @@ namespace System.Xml.Serialization
                     if (m.CheckShouldPersist)
                     {
                         string methodInvoke = "ShouldSerialize" + m.Name;
-                        MethodInfo method = o!.GetType().GetTypeInfo().GetDeclaredMethod(methodInvoke)!;
+                        MethodInfo method = o!.GetType().GetMethod(methodInvoke, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly)!;
                         shouldPersist = (bool)method.Invoke(o, Array.Empty<object>())!;
                     }
 
index e49e9d0..b07608c 100644 (file)
@@ -675,7 +675,7 @@ namespace System.Security.AccessControl
                 throw new ArgumentNullException(nameof(rule));
             }
 
-            if (!this.AccessRuleType.GetTypeInfo().IsAssignableFrom(rule.GetType().GetTypeInfo()))
+            if (!this.AccessRuleType.IsAssignableFrom(rule.GetType()))
             {
                 throw new ArgumentException(
                     SR.AccessControl_InvalidAccessRuleType,
@@ -701,7 +701,7 @@ namespace System.Security.AccessControl
                 throw new ArgumentNullException(nameof(rule));
             }
 
-            if (!this.AuditRuleType.GetTypeInfo().IsAssignableFrom(rule.GetType().GetTypeInfo()))
+            if (!this.AuditRuleType.IsAssignableFrom(rule.GetType()))
             {
                 throw new ArgumentException(
                     SR.AccessControl_InvalidAuditRuleType,
index 131ff6d..4951152 100644 (file)
@@ -165,7 +165,7 @@ namespace System.Security.Principal
             // Target type must be a subclass of IdentityReference
             //
 
-            if (!targetType.GetTypeInfo().IsSubclassOf(typeof(IdentityReference)))
+            if (!targetType.IsSubclassOf(typeof(IdentityReference)))
             {
                 throw new ArgumentException(SR.IdentityReference_MustBeIdentityReference, nameof(targetType));
             }
index 46c8a59..1a48d4a 100644 (file)
@@ -157,7 +157,7 @@ namespace System.Text
             // NOTE: We must reflect on a public type that is exposed in the contract here
             // (i.e. CodePagesEncodingProvider), otherwise we will not get a reference to
             // the right assembly.
-            Stream? stream = typeof(CodePagesEncodingProvider).GetTypeInfo().Assembly.GetManifestResourceStream(tableName);
+            Stream? stream = typeof(CodePagesEncodingProvider).Assembly.GetManifestResourceStream(tableName);
 
             if (stream == null)
             {