// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
+
namespace System.Reflection
{
#if CORERT
return signatureType.TryResolve(genericMethod.GetGenericArguments());
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Used to find matching method overloads. Only used for assignability checks.")]
private static Type? TryResolve(this SignatureType signatureType, Type[] genericMethodParameters)
{
if (signatureType.IsSZArray)
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods)]
public virtual IEnumerable<MethodInfo> GetDeclaredMethods(string name)
{
- foreach (MethodInfo method in GetMethods(TypeInfo.DeclaredOnlyLookup))
+ foreach (MethodInfo method in GetDeclaredOnlyMethods(this))
{
if (method.Name == name)
yield return method;
}
+
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "The yield return state machine doesn't propagate annotations")]
+ static MethodInfo[] GetDeclaredOnlyMethods(
+ Type type) => type.GetMethods(TypeInfo.DeclaredOnlyLookup);
}
public virtual IEnumerable<ConstructorInfo> DeclaredConstructors
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicNestedTypes | DynamicallyAccessedMemberTypes.NonPublicNestedTypes)]
get
{
- foreach (Type t in GetNestedTypes(TypeInfo.DeclaredOnlyLookup))
+ foreach (Type t in GetDeclaredOnlyNestedTypes(this))
{
yield return t.GetTypeInfo();
}
+
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "The yield return state machine doesn't propagate annotations")]
+ static Type[] GetDeclaredOnlyNestedTypes(
+ Type type) => type.GetNestedTypes(TypeInfo.DeclaredOnlyLookup);
}
}
}
}
- public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir, Type? usingResourceSet)
+ public static ResourceManager CreateFileBasedResourceManager(string baseName, string resourceDir,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
+ Type? usingResourceSet)
{
return new ResourceManager(baseName, resourceDir, usingResourceSet);
}
using System.Collections;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Reflection;
// Returns the preferred IResourceWriter class for this kind of ResourceSet.
// Subclasses of ResourceSet using their own Readers &; should override
// GetDefaultReader and GetDefaultWriter.
+ // TODO: https://github.com/mono/linker/issues/943
+ [DynamicDependency(DynamicallyAccessedMemberTypes.PublicConstructors, "System.Resources.ResourceWriter", "System.Resources.Writer")]
public virtual Type GetDefaultWriter()
{
- Assembly resourceWriterAssembly = Assembly.Load("System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");
- return resourceWriterAssembly.GetType("System.Resources.ResourceWriter", throwOnError: true)!;
+ return Type.GetType("System.Resources.ResourceWriter, System.Resources.Writer", throwOnError: true)!;
}
public virtual IDictionaryEnumerator GetEnumerator()
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static extern bool IsDefinedInternal(ICustomAttributeProvider obj, Type AttributeType);
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Linker analyzes base properties and marks them")]
private static PropertyInfo? GetBasePropertyDefinition(RuntimePropertyInfo property)
{
MethodInfo? method = property.GetGetMethod(true);
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Linker analyzes base events and marks them")]
private static EventInfo? GetBaseEventDefinition(RuntimeEventInfo evt)
{
MethodInfo? method = evt.GetAddMethod(true);
// We require emitted types to have all members on their bases to be accessible.
// This is basically an identity function for `this`.
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Reflection emitted types have all of their members")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public
TypeInfo? CreateTypeInfo()
return generic_params;
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Linker thinks Type.GetConstructor(ConstructorInfo) is one of the public APIs because it doesn't analyze method signatures. We already have ConstructorInfo.")]
public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)
{
/*FIXME I would expect the same checks of GetMethod here*/
return InflateType(type, type_arguments, method_args);
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2006:UnrecognizedReflectionPattern",
+ Justification = "Reflection emitted types have all of their members")]
internal static Type? InflateType(Type? type, Type[]? type_args, Type[]? method_args)
{
if (type == null)