Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get TrimTest to 0 trim warnings #11407

Merged
merged 19 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ namespace System.ComponentModel;

internal static class TypeConverterHelper
{
// Feature switch, when set to true, used for trimming to access ComponentModel in a trim safe manner
[FeatureSwitchDefinition("System.Windows.Forms.Primitives.TypeConverterHelper.UseComponentModelRegisteredTypes")]
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
private static bool UseComponentModelRegisteredTypes { get; } =
AppContext.TryGetSwitch("System.Windows.Forms.Primitives.TypeConverterHelper.UseComponentModelRegisteredTypes", out bool isEnabled)
? isEnabled
: false;
#pragma warning restore IDE0075

/// <summary>
/// Converts the given text to list of objects, using the specified context and culture information.
/// </summary>
Expand All @@ -28,7 +37,18 @@ internal static class TypeConverterHelper
return false;
}

TypeConverter converter = TypeDescriptor.GetConverter(typeof(T));
TypeConverter converter;
if (!UseComponentModelRegisteredTypes)
{
converter = TypeDescriptor.GetConverter(typeof(T));
}
else
{
// Call the trim safe API
TypeDescriptor.RegisterType<T>();
converter = TypeDescriptor.GetConverterFromRegisteredType(typeof(T));
}

for (int i = 0; i < output.Length; i++)
{
// Note: ConvertFromString will raise exception if value cannot be converted.
Expand Down
8 changes: 7 additions & 1 deletion src/System.Windows.Forms/src/Resources/SR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6968,6 +6968,12 @@ Stack trace where the illegal operation occurred was:
<value>Binding operations are not supported when application trimming is enabled.</value>
</data>
<data name="BinaryFormatterNotSupported" xml:space="preserve">
<value>Using the BinaryFormatter is not supported.</value>
<value>Using the BinaryFormatter is not supported in trimmed applications.</value>
</data>
<data name="ControlNotSupportedInTrimming" xml:space="preserve">
<value>'{0}' is not supported in trimmed applications.</value>
</data>
<data name="DesignTimeFeaturesNotSupported" xml:space="preserve">
<value>Design time features are not supported.</value>
</data>
</root>
14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions src/System.Windows.Forms/src/Resources/xlf/SR.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading