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

Resolve ILLink warnings in System.ComponentModel.TypeConverter (Round 2) #49467

Merged
merged 5 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -89,12 +89,14 @@ 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(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 DesignerAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName) { }
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
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 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 @@ -162,10 +164,12 @@ public DisplayNameAttribute(string displayName) { }
public sealed partial class EditorAttribute : System.Attribute
{
public EditorAttribute() { }
public EditorAttribute(string typeName, string? baseTypeName) { }
public EditorAttribute(string typeName, System.Type baseType) { }
public EditorAttribute(System.Type type, System.Type baseType) { }
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 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
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel.Design;
using System.Diagnostics.CodeAnalysis;

namespace System.ComponentModel
{
Expand All @@ -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(string designerTypeName)
public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName)
{
DesignerTypeName = designerTypeName ?? throw new ArgumentNullException(nameof(designerTypeName));
DesignerBaseTypeName = "System.ComponentModel.Design.IDesigner, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
Expand All @@ -27,7 +27,7 @@ public DesignerAttribute(string designerTypeName)
/// Initializes a new instance of the <see cref='System.ComponentModel.DesignerAttribute'/> class using the type that provides
/// design-time services.
/// </summary>
public DesignerAttribute(Type designerType)
public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType)
{
if (designerType == null)
{
Expand All @@ -42,7 +42,9 @@ public DesignerAttribute(Type designerType)
/// 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(string designerTypeName, string designerBaseTypeName)
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerBaseTypeName)
{
DesignerTypeName = designerTypeName ?? throw new ArgumentNullException(nameof(designerTypeName));
DesignerBaseTypeName = designerBaseTypeName;
Expand All @@ -52,7 +54,9 @@ public DesignerAttribute(string designerTypeName, string designerBaseTypeName)
/// 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(string designerTypeName, Type designerBaseType)
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType)
{
if (designerTypeName == null)
{
Expand All @@ -71,7 +75,9 @@ public DesignerAttribute(string designerTypeName, Type designerBaseType)
/// 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(Type designerType, Type designerBaseType)
public DesignerAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType)
{
if (designerType == null)
{
Expand All @@ -89,11 +95,14 @@ public DesignerAttribute(Type designerType, Type designerBaseType)
/// <summary>
/// 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)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we want this actually. Are the designers ever used at runtime?
The problem is that this will basically force include the designer types and some code from them into apps - but they will never be used (since they're designers, those should not run at runtime).
Also - the only method which accesses this TypeDescriptor.CreateDesigner is already marked with RUC - and I think we should not allow calling it on a trimmed app.

Technically the annotation is correct, I'm questioning if it's the right thing to do for size.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only method which accesses this TypeDescriptor.CreateDesigner is already marked with RUC - and I think we should not allow calling it on a trimmed app.

Just because a method is marked with RUC doesn't mean it can't be called in a trimmed app.

Maybe if this becomes a size issue for WinForms, they can strip out DesignerAttribute instances by default - similar to how we strip out some attributes in Blazor WASM that aren't needed at runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good point that a better size solution is to strip out the attribute as a whole.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These attributes can be and are used at runtime by PropertyGrid control, and can be used by custom designers (e.g. a report viewer)

public string DesignerTypeName { get; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// 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.ComponentModel
{
/// <summary>
Expand All @@ -25,7 +27,9 @@ 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(string typeName, string? baseTypeName)
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string? baseTypeName)
{
EditorTypeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
EditorBaseTypeName = baseTypeName;
Expand All @@ -34,7 +38,9 @@ public EditorAttribute(string typeName, string? baseTypeName)
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.
/// </summary>
public EditorAttribute(string typeName, Type baseType)
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType)
{
if (typeName == null)
{
Expand All @@ -52,7 +58,9 @@ public EditorAttribute(string typeName, Type baseType)
/// <summary>
/// Initializes a new instance of the <see cref='System.ComponentModel.EditorAttribute'/> class.
/// </summary>
public EditorAttribute(Type type, Type baseType)
public EditorAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType)
{
if (type == null)
{
Expand All @@ -70,11 +78,13 @@ public EditorAttribute(Type type, Type baseType)
/// <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
Loading