diff --git a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs index c4b69c84f1e742..45d664d1ddf63e 100644 --- a/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs +++ b/src/libraries/System.ComponentModel.Primitives/ref/System.ComponentModel.Primitives.cs @@ -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) { } + 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; } @@ -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; } diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerAttribute.cs index bde0162bbdf0f4..51472cdeed5b6b 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/DesignerAttribute.cs @@ -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 { @@ -17,7 +17,7 @@ public sealed class DesignerAttribute : Attribute /// Initializes a new instance of the class using the name of the type that /// provides design-time services. /// - 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"; @@ -27,7 +27,7 @@ public DesignerAttribute(string designerTypeName) /// Initializes a new instance of the class using the type that provides /// design-time services. /// - public DesignerAttribute(Type designerType) + public DesignerAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType) { if (designerType == null) { @@ -42,7 +42,9 @@ public DesignerAttribute(Type designerType) /// Initializes a new instance of the class using the designer type and the /// base class for the designer. /// - 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; @@ -52,7 +54,9 @@ public DesignerAttribute(string designerTypeName, string designerBaseTypeName) /// Initializes a new instance of the class, using the name of the designer /// class and the base class for the designer. /// - public DesignerAttribute(string designerTypeName, Type designerBaseType) + public DesignerAttribute( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string designerTypeName, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType) { if (designerTypeName == null) { @@ -71,7 +75,9 @@ public DesignerAttribute(string designerTypeName, Type designerBaseType) /// Initializes a new instance of the class using the types of the designer and /// designer base class. /// - public DesignerAttribute(Type designerType, Type designerBaseType) + public DesignerAttribute( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerType, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type designerBaseType) { if (designerType == null) { @@ -89,11 +95,14 @@ public DesignerAttribute(Type designerType, Type designerBaseType) /// /// Gets the name of the base type of this designer. /// + // Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878 + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public string DesignerBaseTypeName { get; } /// /// Gets the name of the designer type associated with this designer attribute. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public string DesignerTypeName { get; } /// diff --git a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EditorAttribute.cs b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EditorAttribute.cs index d1f3e27f7c7779..ce23595bc2b1cb 100644 --- a/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EditorAttribute.cs +++ b/src/libraries/System.ComponentModel.Primitives/src/System/ComponentModel/EditorAttribute.cs @@ -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 { /// @@ -25,7 +27,9 @@ public EditorAttribute() /// Initializes a new instance of the class with the type name and base type /// name of the editor. /// - 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; @@ -34,7 +38,9 @@ public EditorAttribute(string typeName, string? baseTypeName) /// /// Initializes a new instance of the class. /// - public EditorAttribute(string typeName, Type baseType) + public EditorAttribute( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType) { if (typeName == null) { @@ -52,7 +58,9 @@ public EditorAttribute(string typeName, Type baseType) /// /// Initializes a new instance of the class. /// - public EditorAttribute(Type type, Type baseType) + public EditorAttribute( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type baseType) { if (type == null) { @@ -70,11 +78,13 @@ public EditorAttribute(Type type, Type baseType) /// /// Gets the name of the base class or interface serving as a lookup key for this editor. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public string? EditorBaseTypeName { get; } /// /// Gets the name of the editor class. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public string EditorTypeName { get; } /// diff --git a/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs b/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs index 29397fc17ead12..5782cac664427f 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/ref/System.ComponentModel.TypeConverter.cs @@ -287,6 +287,7 @@ protected CustomTypeDescriptor(System.ComponentModel.ICustomTypeDescriptor paren public virtual System.ComponentModel.TypeConverter GetConverter() { throw null; } public virtual System.ComponentModel.EventDescriptor GetDefaultEvent() { throw null; } public virtual System.ComponentModel.PropertyDescriptor GetDefaultProperty() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] public virtual object GetEditor(System.Type editorBaseType) { throw null; } public virtual System.ComponentModel.EventDescriptorCollection GetEvents() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] @@ -565,6 +566,7 @@ public partial interface ICustomTypeDescriptor System.ComponentModel.TypeConverter GetConverter(); System.ComponentModel.EventDescriptor GetDefaultEvent(); System.ComponentModel.PropertyDescriptor GetDefaultProperty(); + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object GetEditor(System.Type editorBaseType); System.ComponentModel.EventDescriptorCollection GetEvents(); [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] @@ -628,8 +630,9 @@ public enum InheritanceLevel [System.AttributeUsageAttribute(System.AttributeTargets.Class)] public partial class InstallerTypeAttribute : System.Attribute { - public InstallerTypeAttribute(string typeName) { } - public InstallerTypeAttribute(System.Type installerType) { } + public InstallerTypeAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName) { } + public InstallerTypeAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type installerType) { } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public virtual System.Type InstallerType { get { throw null; } } public override bool Equals(object obj) { throw null; } public override int GetHashCode() { throw null; } @@ -704,9 +707,9 @@ internal LicenseManager() { } public static System.ComponentModel.LicenseContext CurrentContext { get { throw null; } set { } } public static System.ComponentModel.LicenseUsageMode UsageMode { get { throw null; } } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - public static object CreateWithContext(System.Type type, System.ComponentModel.LicenseContext creationContext) { throw null; } + public static object CreateWithContext([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, System.ComponentModel.LicenseContext creationContext) { throw null; } [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] - public static object CreateWithContext(System.Type type, System.ComponentModel.LicenseContext creationContext, object[] args) { throw null; } + public static object CreateWithContext([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type, System.ComponentModel.LicenseContext creationContext, object[] args) { throw null; } public static bool IsLicensed(System.Type type) { throw null; } public static bool IsValid(System.Type type) { throw null; } public static bool IsValid(System.Type type, object instance, out System.ComponentModel.License license) { throw null; } @@ -725,8 +728,9 @@ public sealed partial class LicenseProviderAttribute : System.Attribute { public static readonly System.ComponentModel.LicenseProviderAttribute Default; public LicenseProviderAttribute() { } - public LicenseProviderAttribute(string typeName) { } - public LicenseProviderAttribute(System.Type type) { } + public LicenseProviderAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName) { } + public LicenseProviderAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type type) { } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public System.Type LicenseProvider { get { throw null; } } public override object TypeId { get { throw null; } } public override bool Equals(object value) { throw null; } @@ -1040,7 +1044,7 @@ protected PropertyDescriptor(string name, System.Attribute[] attrs) : base (defa public virtual bool SupportsChangeEvents { get { throw null; } } public virtual void AddValueChanged(object component, System.EventHandler handler) { } public abstract bool CanResetValue(object component); - protected object CreateInstance(System.Type type) { throw null; } + protected object CreateInstance([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type type) { throw null; } public override bool Equals(object obj) { throw null; } protected override void FillAttributes(System.Collections.IList attributeList) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The PropertyDescriptor's PropertyType cannot be statically discovered.")] @@ -1051,11 +1055,12 @@ protected override void FillAttributes(System.Collections.IList attributeList) { public System.ComponentModel.PropertyDescriptorCollection GetChildProperties(object instance) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("The 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.RequiresUnreferencedCode("The PropertyDescriptor's PropertyType cannot be statically discovered.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The 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; } - protected System.Type GetTypeFromName(string typeName) { throw null; } + [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] + protected System.Type GetTypeFromName([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName) { throw null; } public abstract object GetValue(object component); protected internal System.EventHandler GetValueChangedHandler(object component) { throw null; } protected virtual void OnValueChanged(object component, System.EventArgs e) { } @@ -1117,8 +1122,8 @@ void System.Collections.IList.RemoveAt(int index) { } public partial class PropertyTabAttribute : System.Attribute { public PropertyTabAttribute() { } - public PropertyTabAttribute(string tabClassName) { } - public PropertyTabAttribute(string tabClassName, System.ComponentModel.PropertyTabScope tabScope) { } + public PropertyTabAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName) { } + public PropertyTabAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName, System.ComponentModel.PropertyTabScope tabScope) { } public PropertyTabAttribute(System.Type tabClass) { } public PropertyTabAttribute(System.Type tabClass, System.ComponentModel.PropertyTabScope tabScope) { } public System.Type[] TabClasses { get { throw null; } } @@ -1127,6 +1132,7 @@ public PropertyTabAttribute(System.Type tabClass, System.ComponentModel.Property public bool Equals(System.ComponentModel.PropertyTabAttribute other) { throw null; } public override bool Equals(object other) { throw null; } public override int GetHashCode() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Types referenced by tabClassNames may be trimmed.")] protected void InitializeArrays(string[] tabClassNames, System.ComponentModel.PropertyTabScope[] tabScopes) { } protected void InitializeArrays(System.Type[] tabClasses, System.ComponentModel.PropertyTabScope[] tabScopes) { } } @@ -1140,9 +1146,10 @@ public enum PropertyTabScope [System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=true)] public sealed partial class ProvidePropertyAttribute : System.Attribute { - public ProvidePropertyAttribute(string propertyName, string receiverTypeName) { } - public ProvidePropertyAttribute(string propertyName, System.Type receiverType) { } + public ProvidePropertyAttribute(string propertyName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string receiverTypeName) { } + public ProvidePropertyAttribute(string propertyName, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] System.Type receiverType) { } public string PropertyName { get { throw null; } } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public string ReceiverTypeName { get { throw null; } } public override object TypeId { get { throw null; } } public override bool Equals(object obj) { throw null; } @@ -1236,9 +1243,11 @@ public partial class ToolboxItemAttribute : System.Attribute public static readonly System.ComponentModel.ToolboxItemAttribute Default; public static readonly System.ComponentModel.ToolboxItemAttribute None; public ToolboxItemAttribute(bool defaultType) { } - public ToolboxItemAttribute(string toolboxItemTypeName) { } - public ToolboxItemAttribute(System.Type toolboxItemType) { } + public ToolboxItemAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] string toolboxItemTypeName) { } + public ToolboxItemAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type toolboxItemType) { } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public System.Type ToolboxItemType { get { throw null; } } + [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] public string ToolboxItemTypeName { get { throw null; } } public override bool Equals(object obj) { throw null; } public override int GetHashCode() { throw null; } @@ -1334,7 +1343,7 @@ public abstract partial class TypeDescriptionProvider { protected TypeDescriptionProvider() { } protected TypeDescriptionProvider(System.ComponentModel.TypeDescriptionProvider parent) { } - public virtual object CreateInstance(System.IServiceProvider provider, System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } + public virtual object CreateInstance(System.IServiceProvider provider, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } public virtual System.Collections.IDictionary GetCache(object instance) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")] public virtual System.ComponentModel.ICustomTypeDescriptor GetExtendedTypeDescriptor(object instance) { throw null; } @@ -1368,6 +1377,7 @@ public static event System.ComponentModel.RefreshEventHandler Refreshed { add { [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] public static System.ComponentModel.TypeDescriptionProvider AddAttributes(System.Type type, params System.Attribute[] attributes) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Types specified in table may be trimmed, or have their static construtors trimmed.")] public static void AddEditorTable(System.Type editorBaseType, System.Collections.Hashtable table) { } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] public static void AddProvider(System.ComponentModel.TypeDescriptionProvider provider, object instance) { } @@ -1383,7 +1393,7 @@ public static void CreateAssociation(object primary, object secondary) { } public static System.ComponentModel.Design.IDesigner CreateDesigner(System.ComponentModel.IComponent component, System.Type designerBaseType) { throw null; } public static System.ComponentModel.EventDescriptor CreateEvent(System.Type componentType, System.ComponentModel.EventDescriptor oldEventDescriptor, params System.Attribute[] attributes) { throw null; } public static System.ComponentModel.EventDescriptor CreateEvent(System.Type componentType, string name, System.Type type, params System.Attribute[] attributes) { throw null; } - public static object CreateInstance(System.IServiceProvider provider, System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } + public static object CreateInstance(System.IServiceProvider provider, [System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)] System.Type objectType, System.Type[] argTypes, object[] args) { throw null; } public static System.ComponentModel.PropertyDescriptor CreateProperty([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type componentType, System.ComponentModel.PropertyDescriptor oldPropertyDescriptor, params System.Attribute[] attributes) { throw null; } public static System.ComponentModel.PropertyDescriptor CreateProperty([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type componentType, string name, System.Type type, params System.Attribute[] attributes) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] @@ -1423,11 +1433,12 @@ public static void CreateAssociation(object primary, object secondary) { } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] public static System.ComponentModel.PropertyDescriptor GetDefaultProperty(object component, bool noCustomTypeDesc) { throw null; } public static System.ComponentModel.PropertyDescriptor GetDefaultProperty([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type componentType) { throw null; } - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of component cannot be statically discovered.")] public static object GetEditor(object component, System.Type editorBaseType) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] - [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed. The Type of component cannot be statically discovered.")] public static object GetEditor(object component, System.Type editorBaseType, bool noCustomTypeDesc) { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] public static object GetEditor([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, System.Type editorBaseType) { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] public static System.ComponentModel.EventDescriptorCollection GetEvents(object component) { throw null; } @@ -1923,9 +1934,12 @@ public partial interface ITypeResolutionService System.Reflection.Assembly GetAssembly(System.Reflection.AssemblyName name); System.Reflection.Assembly GetAssembly(System.Reflection.AssemblyName name, bool throwOnError); string GetPathOfAssembly(System.Reflection.AssemblyName name); - System.Type GetType(string name); - System.Type GetType(string name, bool throwOnError); - System.Type GetType(string name, bool throwOnError, bool ignoreCase); + [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + System.Type GetType([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name); + [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + System.Type GetType([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name, bool throwOnError); + [return: System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + System.Type GetType([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name, bool throwOnError, bool ignoreCase); void ReferenceAssembly(System.Reflection.AssemblyName name); } public partial class MenuCommand diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.Suppressions.xml b/src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.Suppressions.xml index 558d9f107eb5a0..66fca33d8cb89b 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.Suppressions.xml +++ b/src/libraries/System.ComponentModel.TypeConverter/src/ILLink/ILLink.Suppressions.xml @@ -1,168 +1,24 @@  - - ILLink - IL2026 - member - M:System.ComponentModel.PropertyDescriptor.GetTypeFromName(System.String) - - - ILLink - IL2026 - member - M:System.ComponentModel.PropertyTabAttribute.get_TabClasses - - - ILLink - IL2026 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetTypeFromName(System.String) - - - ILLink - IL2026 - member - M:System.ComponentModel.TypeDescriptor.ComNativeDescriptorProxy.#ctor - - - ILLink - IL2057 - member - M:System.ComponentModel.InstallerTypeAttribute.get_InstallerType - - - ILLink - IL2057 - member - M:System.ComponentModel.LicenseProviderAttribute.get_LicenseProvider - - - ILLink - IL2057 - member - M:System.ComponentModel.PropertyDescriptor.GetTypeFromName(System.String) - - - ILLink - IL2057 - member - M:System.ComponentModel.PropertyTabAttribute.get_TabClasses - ILLink IL2057 member M:System.ComponentModel.ReflectPropertyDescriptor.FillAttributes(System.Collections.IList) - - ILLink - IL2057 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.GetIntrinsicTypeEditor(System.Collections.Hashtable,System.Type) - - - ILLink - IL2057 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.GetTypeFromName(System.String) - - - ILLink - IL2057 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetEditorAttribute(System.ComponentModel.AttributeCollection,System.Type) - - - ILLink - IL2057 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetTypeFromName(System.String) - - - ILLink - IL2057 - member - M:System.ComponentModel.ToolboxItemAttribute.get_ToolboxItemType - - - ILLink - IL2057 - member - M:System.ComponentModel.TypeDescriptor.CreateDesigner(System.ComponentModel.IComponent,System.Type) - - - ILLink - IL2059 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.GetEditorTable(System.Type) - - - ILLink - IL2067 - member - M:System.ComponentModel.LicenseManager.CreateWithContext(System.Type,System.ComponentModel.LicenseContext,System.Object[]) - - - ILLink - IL2067 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.CreateInstance(System.IServiceProvider,System.Type,System.Type[],System.Object[]) - - - ILLink - IL2067 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.CreateInstance(System.Type,System.Type) - - - ILLink - IL2067 - member - M:System.ComponentModel.TypeDescriptionProvider.CreateInstance(System.IServiceProvider,System.Type,System.Type[],System.Object[]) - ILLink IL2070 member M:System.ComponentModel.MemberDescriptor.FindMethod(System.Type,System.String,System.Type[],System.Type,System.Boolean) - - ILLink - IL2070 - member - M:System.ComponentModel.PropertyDescriptor.CreateInstance(System.Type) - - - ILLink - IL2070 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.CreateInstance(System.IServiceProvider,System.Type,System.Type[],System.Object[]) - - - ILLink - IL2070 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.CreateInstance(System.Type,System.Type) - - - ILLink - IL2072 - member - M:System.ComponentModel.LicenseManager.ValidateInternalRecursive(System.ComponentModel.LicenseContext,System.Type,System.Object,System.Boolean,System.ComponentModel.License@,System.String@) - ILLink IL2072 member M:System.ComponentModel.MaskedTextProvider.Clone - - ILLink - IL2072 - member - M:System.ComponentModel.TypeDescriptor.ComNativeDescriptorProxy.#ctor - ILLink IL2075 @@ -193,18 +49,6 @@ member M:System.ComponentModel.ReflectPropertyDescriptor.FillAttributes(System.Collections.IList) - - ILLink - IL2075 - member - M:System.ComponentModel.ReflectPropertyDescriptor.get_SetMethodValue - - - ILLink - IL2075 - member - M:System.ComponentModel.ReflectTypeDescriptionProvider.GetIntrinsicTypeEditor(System.Collections.Hashtable,System.Type) - ILLink IL2080 @@ -217,12 +61,6 @@ member M:System.ComponentModel.ReflectPropertyDescriptor.FillAttributes(System.Collections.IList) - - ILLink - IL2080 - member - M:System.ComponentModel.ReflectPropertyDescriptor.get_SetMethodValue - ILLink IL2026 @@ -253,12 +91,6 @@ member M:System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System#ComponentModel#ICustomTypeDescriptor#GetDefaultProperty - - ILLink - IL2026 - member - M:System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System#ComponentModel#ICustomTypeDescriptor#GetEditor(System.Type) - ILLink IL2062 diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/CustomTypeDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/CustomTypeDescriptor.cs index fd6e5f7167774b..163d8b59624954 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/CustomTypeDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/CustomTypeDescriptor.cs @@ -95,6 +95,7 @@ public virtual TypeConverter GetConverter() /// The GetEditor method returns an editor of the given type that is /// to be associated with the class this type descriptor is representing. /// + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode)] public virtual object GetEditor(Type editorBaseType) => _parent?.GetEditor(editorBaseType); /// diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/DelegatingTypeDescriptionProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/DelegatingTypeDescriptionProvider.cs index 5e05f31d18b22d..b82e5924ffa594 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/DelegatingTypeDescriptionProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/DelegatingTypeDescriptionProvider.cs @@ -32,7 +32,11 @@ internal DelegatingTypeDescriptionProvider(Type type) /// data type. If the method is not interested in providing a substitute /// instance, it should call base. /// - public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) + public override object CreateInstance( + IServiceProvider provider, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type[] argTypes, + object[] args) { return Provider.CreateInstance(provider, objectType, argTypes, args); } diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/ITypeResolutionService.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/ITypeResolutionService.cs index db2b1ce1470919..b02ea35f3bb510 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/ITypeResolutionService.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/ITypeResolutionService.cs @@ -1,6 +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.Diagnostics.CodeAnalysis; using System.Reflection; namespace System.ComponentModel.Design @@ -23,17 +24,20 @@ public interface ITypeResolutionService /// /// Loads a type with the given name. /// - Type GetType(string name); + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + Type GetType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name); /// /// Loads a type with the given name. /// - Type GetType(string name, bool throwOnError); + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + Type GetType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name, bool throwOnError); /// /// Loads a type with the given name. /// - Type GetType(string name, bool throwOnError, bool ignoreCase); + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] + Type GetType([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string name, bool throwOnError, bool ignoreCase); /// /// References the given assembly name. Once an assembly has diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/PropertyTabAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/PropertyTabAttribute.cs index 19038d77f08d53..73eca9e8a4fd28 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/PropertyTabAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/PropertyTabAttribute.cs @@ -38,7 +38,10 @@ public PropertyTabAttribute(Type tabClass) : this(tabClass, PropertyTabScope.Com /// Basic constructor that creates a property tab attribute that will create a tab /// of the specified type. /// - public PropertyTabAttribute(string tabClassName) : this(tabClassName, PropertyTabScope.Component) + public PropertyTabAttribute( + // Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878 + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName) + : this(tabClassName, PropertyTabScope.Component) { } @@ -60,7 +63,10 @@ public PropertyTabAttribute(Type tabClass, PropertyTabScope tabScope) /// Basic constructor that creates a property tab attribute that will create a tab /// of the specified type. /// - public PropertyTabAttribute(string tabClassName, PropertyTabScope tabScope) + public PropertyTabAttribute( + // Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878 + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string tabClassName, + PropertyTabScope tabScope) { _tabClassNames = new string[] { tabClassName }; if (tabScope < PropertyTabScope.Document) @@ -79,43 +85,52 @@ public Type[] TabClasses { if (_tabClasses == null && _tabClassNames != null) { - _tabClasses = new Type[_tabClassNames.Length]; - for (int i = 0; i < _tabClassNames.Length; i++) - { - int commaIndex = _tabClassNames[i].IndexOf(','); - string className = null; - string assemblyName = null; + InitializeTabClasses(); + } + return _tabClasses; + } + } - if (commaIndex != -1) - { - className = _tabClassNames[i].AsSpan(0, commaIndex).Trim().ToString(); - assemblyName = _tabClassNames[i].AsSpan(commaIndex + 1).Trim().ToString(); - } - else - { - className = _tabClassNames[i]; - } + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "The APIs that specify _tabClassNames are either marked with DynamicallyAccessedMembers or RequiresUnreferencedCode.")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", + Justification = "The APIs that specify _tabClassNames are either marked with DynamicallyAccessedMembers or RequiresUnreferencedCode.")] + private void InitializeTabClasses() + { + _tabClasses = new Type[_tabClassNames.Length]; + for (int i = 0; i < _tabClassNames.Length; i++) + { + int commaIndex = _tabClassNames[i].IndexOf(','); + string className = null; + string assemblyName = null; - _tabClasses[i] = Type.GetType(className, false); + if (commaIndex != -1) + { + className = _tabClassNames[i].AsSpan(0, commaIndex).Trim().ToString(); + assemblyName = _tabClassNames[i].AsSpan(commaIndex + 1).Trim().ToString(); + } + else + { + className = _tabClassNames[i]; + } + + _tabClasses[i] = Type.GetType(className, false); - if (_tabClasses[i] == null) + if (_tabClasses[i] == null) + { + if (assemblyName != null) + { + Assembly a = Assembly.Load(assemblyName); + if (a != null) { - if (assemblyName != null) - { - Assembly a = Assembly.Load(assemblyName); - if (a != null) - { - _tabClasses[i] = a.GetType(className, true); - } - } - else - { - throw new TypeLoadException(SR.Format(SR.PropertyTabAttributeTypeLoadException, className)); - } + _tabClasses[i] = a.GetType(className, true); } } + else + { + throw new TypeLoadException(SR.Format(SR.PropertyTabAttributeTypeLoadException, className)); + } } - return _tabClasses; } } @@ -128,9 +143,9 @@ public Type[] TabClasses public override bool Equals(object other) { - if (other is PropertyTabAttribute) + if (other is PropertyTabAttribute propertyTabAttribute) { - return Equals((PropertyTabAttribute)other); + return Equals(propertyTabAttribute); } return false; } @@ -158,7 +173,6 @@ public bool Equals(PropertyTabAttribute other) return true; } - /// /// Returns the hashcode for this object. /// @@ -167,6 +181,7 @@ public bool Equals(PropertyTabAttribute other) /// /// Utiliity function to set the types of tab classes this PropertyTabAttribute specifies. /// + [RequiresUnreferencedCode("The Types referenced by tabClassNames may be trimmed.")] protected void InitializeArrays(string[] tabClassNames, PropertyTabScope[] tabScopes) { InitializeArrays(tabClassNames, null, tabScopes); diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ICustomTypeDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ICustomTypeDescriptor.cs index f194821f7d36fb..579f2ca9100dae 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ICustomTypeDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ICustomTypeDescriptor.cs @@ -44,6 +44,7 @@ public interface ICustomTypeDescriptor /// /// Gets an editor of the specified type for this object. /// + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode)] object GetEditor(Type editorBaseType); /// diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/InstallerTypeAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/InstallerTypeAttribute.cs index d88952b15c829f..2ad8d8941c9524 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/InstallerTypeAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/InstallerTypeAttribute.cs @@ -11,12 +11,13 @@ namespace System.ComponentModel [AttributeUsage(AttributeTargets.Class)] public class InstallerTypeAttribute : Attribute { + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private readonly string _typeName; /// /// Initializes a new instance of the System.Windows.Forms.ComponentModel.InstallerTypeAttribute class. /// - public InstallerTypeAttribute(Type installerType) + public InstallerTypeAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type installerType) { if (installerType == null) { @@ -26,7 +27,7 @@ public InstallerTypeAttribute(Type installerType) _typeName = installerType.AssemblyQualifiedName; } - public InstallerTypeAttribute(string typeName) + public InstallerTypeAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName) { _typeName = typeName; } @@ -34,6 +35,7 @@ public InstallerTypeAttribute(string typeName) /// /// Gets the type of installer associated with this attribute. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public virtual Type InstallerType => Type.GetType(_typeName); public override bool Equals(object obj) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseManager.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseManager.cs index c340d12247eeef..d3acf78aff558c 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseManager.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseManager.cs @@ -4,6 +4,7 @@ using System.Collections; using System.ComponentModel.Design; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.Versioning; using System.Threading; @@ -118,7 +119,9 @@ private static void CacheProvider(Type type, LicenseProvider provider) /// as the context in which the licensed instance can be used. /// [UnsupportedOSPlatform("browser")] - public static object CreateWithContext(Type type, LicenseContext creationContext) + public static object CreateWithContext( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, + LicenseContext creationContext) { return CreateWithContext(type, creationContext, Array.Empty()); } @@ -129,7 +132,10 @@ public static object CreateWithContext(Type type, LicenseContext creationContext /// instance can be used. /// [UnsupportedOSPlatform("browser")] - public static object CreateWithContext(Type type, LicenseContext creationContext, object[] args) + public static object CreateWithContext( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type, + LicenseContext creationContext, + object[] args) { object created = null; diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseProviderAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseProviderAttribute.cs index 9760e6eeaed5e5..6b7fd3615940b1 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseProviderAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseProviderAttribute.cs @@ -17,7 +17,9 @@ public sealed class LicenseProviderAttribute : Attribute /// public static readonly LicenseProviderAttribute Default = new LicenseProviderAttribute(); + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] private Type _licenseProviderType; + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] private readonly string _licenseProviderName; /// @@ -32,7 +34,7 @@ public LicenseProviderAttribute() : this((string)null) /// Initializes a new instance of the class with /// the specified type. /// - public LicenseProviderAttribute(string typeName) + public LicenseProviderAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName) { _licenseProviderName = typeName; } @@ -41,7 +43,7 @@ public LicenseProviderAttribute(string typeName) /// Initializes a new instance of the class with /// the specified type of license provider. /// - public LicenseProviderAttribute(Type type) + public LicenseProviderAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type type) { _licenseProviderType = type; } @@ -49,6 +51,7 @@ public LicenseProviderAttribute(Type type) /// /// Gets the license provider to use with the associated class. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public Type LicenseProvider { get diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/PropertyDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/PropertyDescriptor.cs index c9381b807aa616..d87e76a86a4d06 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/PropertyDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/PropertyDescriptor.cs @@ -184,7 +184,8 @@ public override bool Equals(object obj) /// /// Creates an instance of the specified type. /// - protected object CreateInstance(Type type) + protected object CreateInstance( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type) { Type[] typeArgs = new Type[] { typeof(Type) }; ConstructorInfo ctor = type.GetConstructor(typeArgs); @@ -241,7 +242,7 @@ public virtual PropertyDescriptorCollection GetChildProperties(object instance, /// /// Gets an editor of the specified type. /// - [RequiresUnreferencedCode("The PropertyDescriptor's PropertyType cannot be statically discovered.")] + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode + " The PropertyDescriptor's PropertyType cannot be statically discovered.")] public virtual object GetEditor(Type editorBaseType) { object editor = null; @@ -342,7 +343,10 @@ protected override object GetInvocationTarget(Type type, object instance) /// /// Gets a type using its name. /// - protected Type GetTypeFromName(string typeName) + [RequiresUnreferencedCode("Calls ComponentType.Assembly.GetType on the non-fully qualified typeName, which the trimmer cannot recognize.")] + [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] + protected Type GetTypeFromName( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName) { if (typeName == null || typeName.Length == 0) { diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ProvidePropertyAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ProvidePropertyAttribute.cs index 1499556226f935..7eca6e49fdac36 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ProvidePropertyAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ProvidePropertyAttribute.cs @@ -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 { /// @@ -12,7 +14,9 @@ public sealed class ProvidePropertyAttribute : Attribute /// /// Initializes a new instance of the class. /// - public ProvidePropertyAttribute(string propertyName, Type receiverType) + public ProvidePropertyAttribute( + string propertyName, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type receiverType) { if (receiverType == null) { @@ -26,7 +30,9 @@ public ProvidePropertyAttribute(string propertyName, Type receiverType) /// /// Initializes a new instance of the class. /// - public ProvidePropertyAttribute(string propertyName, string receiverTypeName) + public ProvidePropertyAttribute( + string propertyName, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string receiverTypeName) { PropertyName = propertyName; ReceiverTypeName = receiverTypeName; @@ -40,6 +46,8 @@ public ProvidePropertyAttribute(string propertyName, string receiverTypeName) /// /// Gets the name of the data type this property can extend /// + // Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878 + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] public string ReceiverTypeName { get; } public override bool Equals(object obj) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs index 49517569e96483..42219da04c9774 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectPropertyDescriptor.cs @@ -396,6 +396,8 @@ private MethodInfo ResetMethodValue /// private MethodInfo SetMethodValue { + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2075:UnrecognizedReflectionPattern", + Justification = "_componentClass is annotated with All, but the trimmer is still warning on getting properties on BaseType. https://github.com/mono/linker/issues/1882")] get { if (!_state[s_bitSetQueried] && _state[s_bitSetOnDemand]) @@ -404,7 +406,7 @@ private MethodInfo SetMethodValue if (_setMethod == null) { - for (Type t = ComponentType.BaseType; t != null && t != typeof(object); t = t.BaseType) + for (Type t = _componentClass.BaseType; t != null && t != typeof(object); t = t.BaseType) { BindingFlags bindingFlags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance; PropertyInfo p = t.GetProperty(name, bindingFlags, binder: null, PropertyType, Type.EmptyTypes, null); diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.ReflectedTypeData.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.ReflectedTypeData.cs index 3ddd16dd19ea15..87e6d0dd612911 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.ReflectedTypeData.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.ReflectedTypeData.cs @@ -293,7 +293,7 @@ internal PropertyDescriptor GetDefaultProperty(object instance) /// /// Retrieves the editor for the given base type. /// - [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")] + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode + " The Type of instance cannot be statically discovered.")] internal object GetEditor(object instance, Type editorBaseType) { EditorAttribute typeAttr; @@ -484,7 +484,14 @@ internal PropertyDescriptorCollection GetProperties() /// that this PropertyDescriptor came from is first checked, /// then a global Type.GetType is performed. /// - private Type GetTypeFromName(string typeName) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", + Justification = "Calling _type.Assembly.GetType on a non-assembly qualified type will still work. See https://github.com/mono/linker/issues/1895")] + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", + Justification = "Using the non-assembly qualified type name will still work.")] + private Type GetTypeFromName( + // this method doesn't create the type, but all callers are annotated with PublicConstructors, + // so use that value to ensure the Type will be preserved + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string typeName) { if (string.IsNullOrEmpty(typeName)) { diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs index c2a136f65d5c71..e6e7341e9239f9 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ReflectTypeDescriptionProvider.cs @@ -201,6 +201,7 @@ private static EnumConverter CreateEnumConverter(Type type) /// TypeDescriptor will search an editor /// table for the editor type, if one can be found. /// + [RequiresUnreferencedCode("The Types specified in table may be trimmed, or have their static construtors trimmed.")] internal static void AddEditorTable(Type editorBaseType, Hashtable table) { if (editorBaseType == null) @@ -227,7 +228,11 @@ internal static void AddEditorTable(Type editorBaseType, Hashtable table) /// /// CreateInstance implementation. We delegate to Activator. /// - public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) + public override object CreateInstance( + IServiceProvider provider, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type[] argTypes, + object[] args) { Debug.Assert(objectType != null, "Should have arg-checked before coming in here"); @@ -271,7 +276,9 @@ public override object CreateInstance(IServiceProvider provider, Type objectType /// type implements a Type constructor, and if it does it invokes that ctor. /// Otherwise, it just tries to create the type. /// - private static object CreateInstance(Type objectType, Type callingType) + private static object CreateInstance( + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type callingType) { return objectType.GetConstructor(s_typeConstructor)?.Invoke(new object[] { callingType }) ?? Activator.CreateInstance(objectType); @@ -364,7 +371,7 @@ internal PropertyDescriptor GetDefaultProperty([DynamicallyAccessedMembers(Dynam /// /// Retrieves the editor for the given base type. /// - [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")] + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode + " The Type of instance cannot be statically discovered.")] internal object GetEditor([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, object instance, Type editorBaseType) { ReflectedTypeData td = GetTypeData(type, true); @@ -374,6 +381,7 @@ internal object GetEditor([DynamicallyAccessedMembers(DynamicallyAccessedMemberT /// /// Retrieves a default editor table for the given editor base type. /// + [RequiresUnreferencedCode("The Types specified in EditorTables may be trimmed, or have their static construtors trimmed.")] private static Hashtable GetEditorTable(Type editorBaseType) { Hashtable editorTables = EditorTables; @@ -484,7 +492,7 @@ internal PropertyDescriptor GetExtendedDefaultProperty(object instance) /// /// Retrieves the editor for the given base type. /// - [RequiresUnreferencedCode("The Type of instance cannot be statically discovered.")] + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode + " The Type of instance cannot be statically discovered.")] internal object GetExtendedEditor(object instance, Type editorBaseType) { return GetEditor(instance.GetType(), instance, editorBaseType); @@ -914,7 +922,12 @@ public override ICustomTypeDescriptor GetTypeDescriptor([DynamicallyAccessedMemb /// /// Retrieves a type from a name. /// - private static Type GetTypeFromName(string typeName) + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2057:TypeGetType", + Justification = "typeName is annotated with DynamicallyAccessedMembers, which will preserve the type. " + + "Using the non-assembly qualified type name will still work.")] + private static Type GetTypeFromName( + // Using PublicParameterlessConstructor to preserve the type. See https://github.com/mono/linker/issues/1878 + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] string typeName) { Type t = Type.GetType(typeName); @@ -1295,6 +1308,7 @@ internal void Refresh(Type type) /// for types as needed. These instances are stored back into the table /// for the base type, and for the original component type, for fast access. /// + [RequiresUnreferencedCode(TypeDescriptor.EditorRequiresUnreferencedCode)] private static object GetIntrinsicTypeEditor(Hashtable table, Type callingType) { object hashEntry = null; diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemAttribute.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemAttribute.cs index 8b7a63387a5f1c..ce6f1eb1acd952 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemAttribute.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemAttribute.cs @@ -11,7 +11,9 @@ namespace System.ComponentModel [AttributeUsage(AttributeTargets.All)] public class ToolboxItemAttribute : Attribute { + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private Type _toolboxItemType; + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] private readonly string _toolboxItemTypeName; /// @@ -44,7 +46,7 @@ public ToolboxItemAttribute(bool defaultType) /// /// Initializes a new instance of ToolboxItemAttribute and specifies the name of the type. /// - public ToolboxItemAttribute(string toolboxItemTypeName) + public ToolboxItemAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] string toolboxItemTypeName) { _toolboxItemTypeName = toolboxItemTypeName ?? throw new ArgumentNullException(nameof(toolboxItemTypeName)); } @@ -52,7 +54,7 @@ public ToolboxItemAttribute(string toolboxItemTypeName) /// /// Initializes a new instance of ToolboxItemAttribute and specifies the type of the toolbox item. /// - public ToolboxItemAttribute(Type toolboxItemType) + public ToolboxItemAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type toolboxItemType) { if (toolboxItemType == null) { @@ -66,6 +68,7 @@ public ToolboxItemAttribute(Type toolboxItemType) /// /// Gets the toolbox item's type. /// + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public Type ToolboxItemType { get @@ -88,6 +91,7 @@ public Type ToolboxItemType } } + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] public string ToolboxItemTypeName => _toolboxItemTypeName ?? string.Empty; public override bool Equals(object obj) diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs index 2c4ad1fcbdba1c..125a3f16ee0613 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptionProvider.cs @@ -50,7 +50,11 @@ protected TypeDescriptionProvider(TypeDescriptionProvider parent) /// parent provider was passed. If a parent provider was passed, this /// method will invoke the parent provider's CreateInstance method. /// - public virtual object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) + public virtual object CreateInstance( + IServiceProvider provider, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type[] argTypes, + object[] args) { if (_parent != null) { diff --git a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs index d4136ddb87fbef..c68ecce6c4950c 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/TypeDescriptor.cs @@ -19,6 +19,7 @@ namespace System.ComponentModel public sealed class TypeDescriptor { internal const DynamicallyAccessedMemberTypes ReflectTypesDynamicallyAccessedMembers = DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicFields; + internal const string EditorRequiresUnreferencedCode = "Editors registered in TypeDescriptor.AddEditorTable may be trimmed."; // Note: this is initialized at class load because we // lock on it for thread safety. It is used from nearly @@ -167,6 +168,7 @@ public static TypeDescriptionProvider AddAttributes(object instance, params Attr /// an editor table for the editor type, if one can be found. /// [EditorBrowsable(EditorBrowsableState.Advanced)] + [RequiresUnreferencedCode("The Types specified in table may be trimmed, or have their static construtors trimmed.")] public static void AddEditorTable(Type editorBaseType, Hashtable table) { ReflectTypeDescriptionProvider.AddEditorTable(editorBaseType, table); @@ -430,7 +432,11 @@ public static EventDescriptor CreateEvent(Type componentType, EventDescriptor ol /// a TypeDescriptionProvider object that is associated with the given /// data type. If it finds one, it will delegate the call to that object. /// - public static object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) + public static object CreateInstance( + IServiceProvider provider, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type[] argTypes, + object[] args) { if (objectType == null) { @@ -953,7 +959,7 @@ internal static ICustomTypeDescriptor GetExtendedDescriptor(object component) /// Gets an editor with the specified base type for the /// specified component. /// - [RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode + " The Type of component cannot be statically discovered.")] public static object GetEditor(object component, Type editorBaseType) { return GetEditor(component, editorBaseType, false); @@ -964,7 +970,7 @@ public static object GetEditor(object component, Type editorBaseType) /// specified component. /// [EditorBrowsable(EditorBrowsableState.Advanced)] - [RequiresUnreferencedCode("The Type of component cannot be statically discovered.")] + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode + " The Type of component cannot be statically discovered.")] public static object GetEditor(object component, Type editorBaseType, bool noCustomTypeDesc) { if (editorBaseType == null) @@ -978,6 +984,7 @@ public static object GetEditor(object component, Type editorBaseType, bool noCus /// /// Gets an editor with the specified base type for the specified type. /// + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode)] public static object GetEditor( [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, Type editorBaseType) @@ -2444,7 +2451,6 @@ public static IComNativeDescriptorHandler ComNativeDescriptorHandler } } - /// /// The RemoveAssociation method removes an association with an object. /// @@ -2708,6 +2714,7 @@ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() return _handler.GetDefaultProperty(_instance); } + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode)] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return _handler.GetEditor(_instance, editorBaseType); @@ -2919,10 +2926,12 @@ private sealed class ComNativeDescriptorProxy : TypeDescriptionProvider { private readonly TypeDescriptionProvider _comNativeDescriptor; + [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2072:UnrecognizedReflectionPattern", + Justification = "The trimmer can't find the ComNativeDescriptor type when System.Windows.Forms isn't available. " + + "When System.Windows.Forms is available, the type will be seen by the trimmer and the ctor will be preserved.")] public ComNativeDescriptorProxy() { - Assembly assembly = Assembly.Load("System.Windows.Forms"); - Type realComNativeDescriptor = assembly.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor", throwOnError: true); + Type realComNativeDescriptor = Type.GetType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor, System.Windows.Forms", throwOnError: true); _comNativeDescriptor = (TypeDescriptionProvider)Activator.CreateInstance(realComNativeDescriptor); } @@ -3012,6 +3021,7 @@ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() /// /// ICustomTypeDescriptor implementation. /// + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode)] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { if (editorBaseType == null) @@ -3109,7 +3119,11 @@ internal TypeDescriptionNode(TypeDescriptionProvider provider) /// Implements CreateInstance. This just walks the linked list /// looking for someone who implements the call. /// - public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args) + public override object CreateInstance( + IServiceProvider provider, + [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type objectType, + Type[] argTypes, + object[] args) { if (objectType == null) { @@ -3398,7 +3412,7 @@ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() /// /// ICustomTypeDescriptor implementation. /// - [UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode", Justification = "The ctor of this Type has RequiresUnreferencedCode.")] + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode)] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { if (editorBaseType == null) @@ -3722,6 +3736,7 @@ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() /// /// ICustomTypeDescriptor implementation. /// + [RequiresUnreferencedCode(EditorRequiresUnreferencedCode)] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { if (editorBaseType == null) diff --git a/src/libraries/System.Data.Common/ref/System.Data.Common.cs b/src/libraries/System.Data.Common/ref/System.Data.Common.cs index 9995c1d06557ae..28821d99590ddf 100644 --- a/src/libraries/System.Data.Common/ref/System.Data.Common.cs +++ b/src/libraries/System.Data.Common/ref/System.Data.Common.cs @@ -468,6 +468,7 @@ public void EndEdit() { } System.ComponentModel.TypeConverter System.ComponentModel.ICustomTypeDescriptor.GetConverter() { throw null; } System.ComponentModel.EventDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent() { throw null; } System.ComponentModel.PropertyDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object System.ComponentModel.ICustomTypeDescriptor.GetEditor(System.Type editorBaseType) { throw null; } System.ComponentModel.EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] @@ -2058,6 +2059,7 @@ void System.Collections.IDictionary.Remove(object keyword) { } System.ComponentModel.TypeConverter System.ComponentModel.ICustomTypeDescriptor.GetConverter() { throw null; } System.ComponentModel.EventDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent() { throw null; } System.ComponentModel.PropertyDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object System.ComponentModel.ICustomTypeDescriptor.GetEditor(System.Type editorBaseType) { throw null; } System.ComponentModel.EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] @@ -2235,6 +2237,7 @@ protected DbDataRecord() { } System.ComponentModel.TypeConverter System.ComponentModel.ICustomTypeDescriptor.GetConverter() { throw null; } System.ComponentModel.EventDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent() { throw null; } System.ComponentModel.PropertyDescriptor System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty() { throw null; } + [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object System.ComponentModel.ICustomTypeDescriptor.GetEditor(System.Type editorBaseType) { throw null; } System.ComponentModel.EventDescriptorCollection System.ComponentModel.ICustomTypeDescriptor.GetEvents() { throw null; } [System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DataRecordInternal.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DataRecordInternal.cs index e18d3aff22e3a6..25cac0596df8a0 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DataRecordInternal.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DataRecordInternal.cs @@ -334,6 +334,7 @@ PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() return null; } + [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return null; diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs index 1bd2205a641680..c5de3d5c35e514 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbConnectionStringBuilder.cs @@ -576,6 +576,7 @@ AttributeCollection ICustomTypeDescriptor.GetAttributes() { return TypeDescriptor.GetAttributes(this, true); } + [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this, editorBaseType, true); diff --git a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataRecord.cs b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataRecord.cs index 11ba1945f3f292..f1c2cc55517f6d 100644 --- a/src/libraries/System.Data.Common/src/System/Data/Common/DbDataRecord.cs +++ b/src/libraries/System.Data.Common/src/System/Data/Common/DbDataRecord.cs @@ -83,6 +83,7 @@ protected virtual DbDataReader GetDbDataReader(int i) PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() => null; + [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) => null; EventDescriptorCollection ICustomTypeDescriptor.GetEvents() => new EventDescriptorCollection(null); diff --git a/src/libraries/System.Data.Common/src/System/Data/DataRowView.cs b/src/libraries/System.Data.Common/src/System/Data/DataRowView.cs index 50e01e4852f9d8..f093ac0cc6c04c 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataRowView.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataRowView.cs @@ -239,7 +239,10 @@ public void EndEdit() TypeConverter ICustomTypeDescriptor.GetConverter() => null; EventDescriptor ICustomTypeDescriptor.GetDefaultEvent() => null; PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty() => null; + + [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) => null; + EventDescriptorCollection ICustomTypeDescriptor.GetEvents() => new EventDescriptorCollection(null); [RequiresUnreferencedCode("The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.")] diff --git a/src/libraries/System.Data.Common/src/System/Data/DataViewManagerListItemTypeDescriptor.cs b/src/libraries/System.Data.Common/src/System/Data/DataViewManagerListItemTypeDescriptor.cs index 734b4f5d597a83..5b3e662200b406 100644 --- a/src/libraries/System.Data.Common/src/System/Data/DataViewManagerListItemTypeDescriptor.cs +++ b/src/libraries/System.Data.Common/src/System/Data/DataViewManagerListItemTypeDescriptor.cs @@ -66,6 +66,7 @@ internal DataView GetDataView(DataTable table) /// /// Retrieves the an editor for this object. /// + [RequiresUnreferencedCode("Editors registered in TypeDescriptor.AddEditorTable may be trimmed.")] object ICustomTypeDescriptor.GetEditor(Type editorBaseType) => null; ///