Skip to content

Commit

Permalink
Removing RUC from Default and Ambient attributes (dotnet#100821)
Browse files Browse the repository at this point in the history
* Removing RUC from Default and Ambient attributes

* FB

* FB2
  • Loading branch information
LakshanF authored and matouskozak committed Apr 30, 2024
1 parent 5658de3 commit 897c5bd
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/workflow/trimming/feature-switches.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ configurations but their defaults might vary as any SDK can set the defaults dif
| EnableGeneratedComInterfaceComImportInterop | System.Runtime.InteropServices.Marshalling.EnableGeneratedComInterfaceComImportInterop | When set to true, enables casting source-generated COM object wrappers to built-in COM-based COM interfaces. |
| _UseManagedNtlm | System.Net.Security.UseManagedNtlm | When set to true, uses built-in managed implementation of NTLM and SPNEGO algorithm for HTTP, SMTP authentication, and NegotiateAuthentication API instead of system provided GSSAPI implementation. |
| _ComObjectDescriptorSupport | System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported | When set to true, supports creating a TypeDescriptor based view of COM objects. |
| _DesignerHostSupport | System.ComponentModel.Design.IDesignerHost.IsSupported | When set to true, supports creating design components at runtime. |
| _DefaultValueAttributeSupport | System.ComponentModel.DefaultValueAttribute.IsSupported | When set to true, supports creating a DefaultValueAttribute at runtime. |

Any feature-switch which defines property can be set in csproj file or
on the command line as any other MSBuild property. Those without predefined property name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public AmbientValueAttribute(long value) { }
public AmbientValueAttribute(object? value) { }
public AmbientValueAttribute(float value) { }
public AmbientValueAttribute(string? value) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
public AmbientValueAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string value) { }
public object? Value { get { throw null; } }
public override bool Equals([System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] object? obj) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
<property name="Target">M:System.ComponentModel.TypeDescriptor.NodeFor(System.Object,System.Boolean)</property>
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app with System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported=true.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.ComponentModel.AmbientValueAttribute.#ctor(System.Type,System.String)</property>
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app with System.ComponentModel.Design.IDesignerHost.IsSupported=true.</property>
</attribute>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ public sealed class AmbientValueAttribute : Attribute
/// specified value to the specified type, and using the U.S. English culture as the
/// translation context.
/// </summary>
[RequiresUnreferencedCode(TypeConverter.RequiresUnreferencedCodeMessage)]
public AmbientValueAttribute([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type, string value)
{
// The try/catch here is because attributes should never throw exceptions. We would fail to
// load an otherwise normal class.

Debug.Assert(IDesignerHost.IsSupported, "Runtime instantiation of this attribute is not allowed with trimming.");
if (!IDesignerHost.IsSupported)
{
return;
}

try
{
_value = TypeDescriptor.GetConverter(type).ConvertFromInvariantString(value);
_value = TypeDescriptorGetConverter(type).ConvertFromInvariantString(value);

[RequiresUnreferencedCode("AmbientValueAttribute usage of TypeConverter is not compatible with trimming.")]
static TypeConverter TypeDescriptorGetConverter([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type) => TypeDescriptor.GetConverter(type);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ namespace System.ComponentModel.Design
public interface IDesignerHost : IServiceContainer
{
[FeatureSwitchDefinition("System.ComponentModel.Design.IDesignerHost.IsSupported")]
[FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]
#pragma warning disable IL4000
internal static bool IsSupported => AppContext.TryGetSwitch("System.ComponentModel.Design.IDesignerHost.IsSupported", out bool isSupported) ? isSupported : true;
#pragma warning restore IL4000

/// <summary>
/// Gets or sets a value indicating whether the designer host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,12 @@
<property name="Target">M:System.StartupHookProvider.ProcessStartupHooks(System.String)</property>
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app with System.StartupHookProvider.IsSupported=true.</property>
</attribute>
<attribute fullname="System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute">
<argument>ILLink</argument>
<argument>IL2026</argument>
<property name="Scope">member</property>
<property name="Target">M:System.ComponentModel.DefaultValueAttribute.#ctor(System.Type,System.String)</property>
<property name="Justification">This warning is left in the product so developers get an ILLink warning when trimming an app with System.ComponentModel.DefaultValueAttribute.IsSupported=true.</property>
</attribute>
</assembly>
</linker>
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ public class DefaultValueAttribute : Attribute
private static object? s_convertFromInvariantString;

[FeatureSwitchDefinition("System.ComponentModel.DefaultValueAttribute.IsSupported")]
[FeatureGuard(typeof(RequiresUnreferencedCodeAttribute))]
#pragma warning disable IL4000
internal static bool IsSupported => AppContext.TryGetSwitch("System.ComponentModel.DefaultValueAttribute.IsSupported", out bool isSupported) ? isSupported : true;
#pragma warning restore IL4000

/// <summary>
/// Initializes a new instance of the <see cref='DefaultValueAttribute'/>
/// class, converting the specified value to the specified type, and using the U.S. English
/// culture as the translation context.
/// </summary>
[RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
public DefaultValueAttribute(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type type,
string? value)
{
// The null check and try/catch here are because attributes should never throw exceptions.
// We would fail to load an otherwise normal class.

Debug.Assert(IsSupported, "Runtime instantiation of this attribute is not allowed with trimming.");
if (!IsSupported)
{
Debug.Assert(!IsSupported, "Runtime instantiation of this attribute is not allowed.");
return;
}

Expand Down Expand Up @@ -69,7 +71,7 @@ public DefaultValueAttribute(
_value = Convert.ChangeType(value, type, CultureInfo.InvariantCulture);
}

[RequiresUnreferencedCode("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
[RequiresUnreferencedCode("DefaultValueAttribute usage of TypeConverter is not compatible with trimming.")]
// Looking for ad hoc created TypeDescriptor.ConvertFromInvariantString(Type, string)
static bool TryConvertFromInvariantString(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type typeToConvert,
Expand Down
1 change: 0 additions & 1 deletion src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8047,7 +8047,6 @@ public DefaultValueAttribute(object? value) { }
public DefaultValueAttribute(sbyte value) { }
public DefaultValueAttribute(float value) { }
public DefaultValueAttribute(string? value) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute("Generic TypeConverters may require the generic types to be annotated. For example, NullableConverter requires the underlying type to be DynamicallyAccessedMembers All.")]
public DefaultValueAttribute([System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All)] System.Type type, string? value) { }
[System.CLSCompliantAttribute(false)]
public DefaultValueAttribute(ushort value) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Trim managed NTLM on Linux when it's not explicitly requested -->
<_UseManagedNtlm Condition="'$(_UseManagedNtlm)' == '' and $(RuntimeIdentifier.StartsWith('linux'))">false</_UseManagedNtlm>
<_ComObjectDescriptorSupport Condition="'$(_ComObjectDescriptorSupport)' == ''">false</_ComObjectDescriptorSupport>
<_DesignerHostSupport Condition="'$(_DesignerHostSupport)' == ''">false</_DesignerHostSupport>
<_DefaultValueAttributeSupport Condition="'$(_DefaultValueAttributeSupport)' == ''">false</_DefaultValueAttributeSupport>
</PropertyGroup>


Expand Down

0 comments on commit 897c5bd

Please sign in to comment.