Skip to content

Commit

Permalink
Remove DAM from design-time attributes (dotnet#98378)
Browse files Browse the repository at this point in the history
I noticed these attributes were bringing in a lot of designer code in WinForms due to the DAM
annotation. However, I don't think the DAM annotation is appropriate for attributes meant for
design time. I would instead inspect the code using these attributes to get RUC, or find a different
way to preserve the code.
  • Loading branch information
agocke committed Feb 22, 2024
1 parent 9da5359 commit 2d90448
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,12 @@ public DescriptionAttribute(string description) { }
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Interface, AllowMultiple=true, Inherited=true)]
public sealed partial class DesignerAttribute : System.Attribute
{
public DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName) { }
public DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerBaseTypeName) { }
public DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type designerBaseType) { }
public DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type designerType) { }
public DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type designerType, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type designerBaseType) { }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public DesignerAttribute(string designerTypeName) { }
public DesignerAttribute(string designerTypeName, string designerBaseTypeName) { }
public DesignerAttribute(string designerTypeName, System.Type designerBaseType) { }
public DesignerAttribute(System.Type designerType) { }
public DesignerAttribute(System.Type designerType, System.Type designerBaseType) { }
public string DesignerBaseTypeName { get { throw null; } }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public string DesignerTypeName { get { throw null; } }
public override object TypeId { get { throw null; } }
public override bool Equals(object? obj) { throw null; }
Expand Down Expand Up @@ -164,12 +162,10 @@ public DisplayNameAttribute(string displayName) { }
public sealed partial class EditorAttribute : System.Attribute
{
public EditorAttribute() { }
public EditorAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string? baseTypeName) { }
public EditorAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type baseType) { }
public EditorAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type baseType) { }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
public EditorAttribute(string typeName, string? baseTypeName) { }
public EditorAttribute(string typeName, System.Type baseType) { }
public EditorAttribute(System.Type type, System.Type baseType) { }
public string? EditorBaseTypeName { get { throw null; } }
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
public string EditorTypeName { get { throw null; } }
public override object TypeId { get { throw null; } }
public override bool Equals(object? obj) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class DesignerAttribute : Attribute
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the name of the type that
/// provides design-time services.
/// </summary>
public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName)
public DesignerAttribute(string designerTypeName)
{
ArgumentNullException.ThrowIfNull(designerTypeName);

Expand All @@ -29,7 +29,7 @@ public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTy
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the type that provides
/// design-time services.
/// </summary>
public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType)
public DesignerAttribute(Type designerType)
{
ArgumentNullException.ThrowIfNull(designerType);

Expand All @@ -41,9 +41,7 @@ public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTy
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the designer type and the
/// base class for the designer.
/// </summary>
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerBaseTypeName)
public DesignerAttribute(string designerTypeName, string designerBaseTypeName)
{
ArgumentNullException.ThrowIfNull(designerTypeName);

Expand All @@ -55,9 +53,7 @@ public DesignerAttribute(
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class, using the name of the designer
/// class and the base class for the designer.
/// </summary>
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType)
public DesignerAttribute(string designerTypeName, Type designerBaseType)
{
ArgumentNullException.ThrowIfNull(designerTypeName);
ArgumentNullException.ThrowIfNull(designerBaseType);
Expand All @@ -70,9 +66,7 @@ public DesignerAttribute(
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the types of the designer and
/// designer base class.
/// </summary>
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType)
public DesignerAttribute(Type designerType, Type designerBaseType)
{
ArgumentNullException.ThrowIfNull(designerType);
ArgumentNullException.ThrowIfNull(designerBaseType);
Expand All @@ -85,13 +79,11 @@ public DesignerAttribute(
/// Gets the name of the base type of this designer.
/// </summary>
// Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public string DesignerBaseTypeName { get; }

/// <summary>
/// Gets the name of the designer type associated with this designer attribute.
/// </summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public string DesignerTypeName { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public EditorAttribute()
/// Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class with the type name and base type
/// name of the editor.
/// </summary>
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string? baseTypeName)
public EditorAttribute(string typeName, string? baseTypeName)
{
ArgumentNullException.ThrowIfNull(typeName);

Expand All @@ -40,9 +38,7 @@ public EditorAttribute(
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.
/// </summary>
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType)
public EditorAttribute(string typeName, Type baseType)
{
ArgumentNullException.ThrowIfNull(typeName);
ArgumentNullException.ThrowIfNull(baseType);
Expand All @@ -54,9 +50,7 @@ public EditorAttribute(
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.
/// </summary>
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType)
public EditorAttribute(Type type, Type baseType)
{
ArgumentNullException.ThrowIfNull(type);
ArgumentNullException.ThrowIfNull(baseType);
Expand All @@ -68,13 +62,11 @@ public EditorAttribute(
/// <summary>
/// Gets the name of the base class or interface serving as a lookup key for this editor.
/// </summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
public string? EditorBaseTypeName { get; }

/// <summary>
/// Gets the name of the editor class.
/// </summary>
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
public string EditorTypeName { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ protected CustomTypeDescriptor(System.ComponentModel.ICustomTypeDescriptor? pare
public virtual System.ComponentModel.EventDescriptor? GetDefaultEvent() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("PropertyDescriptor's PropertyType cannot be statically discovered.")]
public virtual System.ComponentModel.PropertyDescriptor? GetDefaultProperty() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming.")]
public virtual object? GetEditor(System.Type editorBaseType) { throw null; }
public virtual System.ComponentModel.EventDescriptorCollection GetEvents() { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
Expand Down Expand Up @@ -589,7 +589,7 @@ public partial interface ICustomTypeDescriptor
System.ComponentModel.EventDescriptor? GetDefaultEvent();
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("PropertyDescriptor's PropertyType cannot be statically discovered.")]
System.ComponentModel.PropertyDescriptor? GetDefaultProperty();
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming.")]
object? GetEditor(System.Type editorBaseType);
System.ComponentModel.EventDescriptorCollection GetEvents();
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
Expand Down Expand Up @@ -1089,7 +1089,7 @@ protected override void FillAttributes(System.Collections.IList attributeList) {
public System.ComponentModel.PropertyDescriptorCollection GetChildProperties(object instance) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("PropertyDescriptor's PropertyType cannot be statically discovered. The Type of instance cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")]
public virtual System.ComponentModel.PropertyDescriptorCollection GetChildProperties(object? instance, System.Attribute[]? filter) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. PropertyDescriptor's PropertyType cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming. PropertyDescriptor's PropertyType cannot be statically discovered.")]
public virtual object? GetEditor(System.Type editorBaseType) { throw null; }
public override int GetHashCode() { throw null; }
protected override object? GetInvocationTarget(System.Type type, object instance) { throw null; }
Expand Down Expand Up @@ -1483,12 +1483,12 @@ public static void CreateAssociation(object primary, object secondary) { }
public static System.ComponentModel.PropertyDescriptor? GetDefaultProperty(object component, bool noCustomTypeDesc) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("PropertyDescriptor's PropertyType cannot be statically discovered.")]
public static System.ComponentModel.PropertyDescriptor? GetDefaultProperty([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type componentType) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of component cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming. The Type of component cannot be statically discovered.")]
public static object? GetEditor(object component, System.Type editorBaseType) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of component cannot be statically discovered.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming. The Type of component cannot be statically discovered.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
public static object? GetEditor(object component, System.Type editorBaseType, bool noCustomTypeDesc) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Design-time attributes are not preserved when trimming. Types referenced by attributes like EditorAttribute and DesignerAttribute may not be available after trimming.")]
public static object? GetEditor([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, System.Type editorBaseType) { throw null; }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The Type of component cannot be statically discovered.")]
public static System.ComponentModel.EventDescriptorCollection GetEvents(object component) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/en-us/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0015</DiagnosticId>
<Target>M:System.ComponentModel.TypeDescriptor.CreateDesigner(System.ComponentModel.IComponent,System.Type):[T:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute]</Target>
<Left>ref/net9.0/System.ComponentModel.TypeConverter.dll</Left>
<Right>lib/net9.0/System.ComponentModel.TypeConverter.dll</Right>
</Suppression>
</Suppressions>
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public virtual AttributeCollection GetAttributes()
/// The GetEditor method returns an editor of the given type that is
/// to be associated with the class this type descriptor is representing.
/// </summary>
[RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode)]
[RequiresUnreferencedCode(TypeDescriptor.DesignTimeAttributeTrimmed)]
public virtual object? GetEditor(Type editorBaseType) => _parent?.GetEditor(editorBaseType);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public interface ICustomTypeDescriptor
/// <summary>
/// Gets an editor of the specified type for this object.
/// </summary>
[RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode)]
[RequiresUnreferencedCode(TypeDescriptor.DesignTimeAttributeTrimmed)]
object? GetEditor(Type editorBaseType);

/// <summary>
Expand Down
Loading

0 comments on commit 2d90448

Please sign in to comment.