* Add DynamicallyAccessedMembers All to TypeBuilder and EnumBuilder CreateType methods.
Contributes to #45623
return fieldBuilder;
}
+ [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
public TypeInfo? CreateTypeInfo()
{
return m_typeBuilder.CreateTypeInfo();
}
// CreateType cause EnumBuilder to be baked.
+ [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
public Type? CreateType()
{
return m_typeBuilder.CreateType();
#region Create Type
+ [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public TypeInfo? CreateTypeInfo()
{
lock (SyncRoot)
}
}
+ [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
public Type? CreateType()
{
lock (SyncRoot)
}
}
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2083:UnrecognizedReflectionPattern",
+ Justification = "Reflection.Emit is not subject to trimming")]
+ [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
private TypeInfo? CreateTypeNoLock()
{
if (IsCreated())
public override System.RuntimeTypeHandle TypeHandle { get { throw null; } }
public System.Reflection.Emit.FieldBuilder UnderlyingField { get { throw null; } }
public override System.Type UnderlyingSystemType { get { throw null; } }
+ [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
public System.Reflection.Emit.FieldBuilder DefineLiteral(string literalName, object? literalValue) { throw null; }
protected override System.Reflection.TypeAttributes GetAttributeFlagsImpl() { throw null; }
public override System.RuntimeTypeHandle TypeHandle { get { throw null; } }
public override System.Type UnderlyingSystemType { get { throw null; } }
public void AddInterfaceImplementation([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type interfaceType) { }
+ [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public System.Type? CreateType() { throw null; }
+ [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)]
public System.Reflection.TypeInfo? CreateTypeInfo() { throw null; }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[]? parameterTypes) { throw null; }
public System.Reflection.Emit.ConstructorBuilder DefineConstructor(System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, System.Type[]? parameterTypes, System.Type[][]? requiredCustomModifiers, System.Type[][]? optionalCustomModifiers) { throw null; }
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<linker>
- <assembly fullname="System.Text.RegularExpressions, PublicKeyToken=b03f5f7f11d50a3a">
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
- <argument>IL2067</argument>
- <property name="Scope">member</property>
- <property name="Target">M:System.Text.RegularExpressions.RegexAssemblyCompiler.DefineType(System.Reflection.Emit.ModuleBuilder,System.String,System.Boolean,System.Boolean,System.Type)</property>
- </attribute>
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
- <argument>IL2070</argument>
- <property name="Scope">member</property>
- <property name="Target">M:System.Text.RegularExpressions.RegexAssemblyCompiler.GenerateCreateInstance(System.Type)</property>
- </attribute>
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
- <argument>IL2070</argument>
- <property name="Scope">member</property>
- <property name="Target">M:System.Text.RegularExpressions.RegexAssemblyCompiler.GenerateRegexDefaultCtor(System.String,System.Text.RegularExpressions.RegexOptions,System.Type,System.Text.RegularExpressions.RegexCode,System.TimeSpan)</property>
- </attribute>
- </assembly>
-</linker>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<linker>
- <assembly fullname="System.Text.RegularExpressions, PublicKeyToken=b03f5f7f11d50a3a">
- <attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
- <argument>ILLink</argument>
- <argument>IL2060</argument>
- <property name="Scope">member</property>
- <property name="Target">M:System.Text.RegularExpressions.RegexCompiler.#cctor</property>
- </attribute>
- </assembly>
-</linker>
\ No newline at end of file
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections;
-using System.Threading;
+using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Reflection.Emit;
+using System.Threading;
#if DEBUG // until it can be fully implemented
namespace System.Text.RegularExpressions
}
/// <summary>Generates a very simple factory method.</summary>
- internal void GenerateCreateInstance(Type type)
+ private void GenerateCreateInstance([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type)
{
// return new Type();
Newobj(type.GetConstructor(Type.EmptyTypes)!);
Ret();
}
- private void GenerateRegexDefaultCtor(string pattern, RegexOptions options, Type regexRunnerFactoryType, RegexCode code, TimeSpan matchTimeout)
+ private void GenerateRegexDefaultCtor(
+ string pattern,
+ RegexOptions options,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type regexRunnerFactoryType,
+ RegexCode code,
+ TimeSpan matchTimeout)
{
// Call the base ctor and store pattern, options, and factory.
// base.ctor();
}
/// <summary>Begins the definition of a new type with a specified base class</summary>
- private static TypeBuilder DefineType(ModuleBuilder moduleBuilder, string typeName, bool isPublic, bool isSealed, Type inheritFromClass)
+ private static TypeBuilder DefineType(
+ ModuleBuilder moduleBuilder,
+ string typeName,
+ bool isPublic,
+ bool isSealed,
+ [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type inheritFromClass)
{
TypeAttributes attrs = TypeAttributes.Class | TypeAttributes.BeforeFieldInit | (isPublic ? TypeAttributes.Public : TypeAttributes.NotPublic);
if (isSealed)
/// RegexCompiler translates a block of RegexCode to MSIL, and creates a
/// subclass of the RegexRunner type.
/// </summary>
+ [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2060:MakeGenericMethod",
+ Target = "M:System.Text.RegularExpressions.RegexCompiler.#cctor",
+ Justification = "The referenced methods don't have any DynamicallyAccessedMembers annotations. See https://github.com/mono/linker/issues/1727")]
internal abstract class RegexCompiler
{
private static readonly FieldInfo s_runtextbegField = RegexRunnerField("runtextbeg");
}
}
+ [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
public Type? CreateType()
{
return _tb.CreateType();
}
+ [return: DynamicallyAccessedMembersAttribute(DynamicallyAccessedMemberTypes.All)]
public TypeInfo? CreateTypeInfo()
{
return _tb.CreateTypeInfo();
// We require emitted types to have all members on their bases to be accessible.
// This is basically an identity function for `this`.
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2083:UnrecognizedReflectionPattern",
- Justification = "Reflection emitted types have all of their members")]
+ Justification = "Reflection.Emit is not subject to trimming")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
- public
- TypeInfo? CreateTypeInfo()
+ public TypeInfo? CreateTypeInfo()
{
/* handle nesting_type */
if (createTypeCalled)