Skip to content

Commit

Permalink
Cleanup trimming warnings from Primitives project (#7304)
Browse files Browse the repository at this point in the history
- IL2050 requires more ComWrappers work, don't want touch that
- IL2026 is `RequiresUnreferencedCodeAttribute` which require a bit more
brainpower.  Better keep that for later when more code would be annotated.

Jab at #4649
  • Loading branch information
kant2002 committed Jun 15, 2022
1 parent 7afcb6c commit 1c7c06f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Expand Up @@ -11,7 +11,7 @@
IL Trim warnings which should be removed in order to make WinForms trimmable
See https://github.com/dotnet/winforms/issues/4649
-->
<NoWarn>$(NoWarn);IL2026;IL2046;IL2050;IL2067</NoWarn>
<NoWarn>$(NoWarn);IL2026;IL2050</NoWarn>
<Deterministic>true</Deterministic>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<UsePublicApiAnalyzers>true</UsePublicApiAnalyzers>
Expand Down
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace System
{
internal static class TrimmingConstants
{
internal const string TypeConverterGetPropertiesMessage = "The Type of value cannot be statically discovered. The public parameterless constructor or the 'Default' static field may be trimmed from the Attribute's Type.";
}
}
Expand Up @@ -5,6 +5,7 @@
#if DEBUG
using System.Diagnostics;
#endif
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using static Interop;

Expand Down Expand Up @@ -83,7 +84,9 @@ public IntPtr Result
/// <summary>
/// Gets the <see cref="LParam"/> value, and converts the value to an object.
/// </summary>
public object? GetLParam(Type cls) => Marshal.PtrToStructure(LParamInternal, cls);
public object? GetLParam(
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
Type cls) => Marshal.PtrToStructure(LParamInternal, cls);

internal static Message Create(IntPtr hWnd, User32.WM msg, nint wparam, nint lparam)
=> Create(hWnd, (int)msg, wparam, lparam);
Expand Down
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows.Forms.Primitives.Resources;

Expand Down Expand Up @@ -160,6 +161,7 @@ public override object CreateInstance(ITypeDescriptorContext? context, IDictiona

public override bool GetCreateInstanceSupported(ITypeDescriptorContext? context) => true;

[RequiresUnreferencedCode(TrimmingConstants.TypeConverterGetPropertiesMessage)]
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Padding), attributes);
Expand Down

0 comments on commit 1c7c06f

Please sign in to comment.