Skip to content

Commit 4b073f2

Browse files
committed
Moving CM type registration to Initialize()
1 parent 473bf80 commit 4b073f2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Controls/ToolStrips/ToolStripMenuItem.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ protected override AccessibleObject CreateAccessibilityInstance()
196196

197197
private void Initialize()
198198
{
199+
if (Control.UseComponentModelRegisteredTypes)
200+
{
201+
// Register the type with the ComponentModel so as to be trim safe
202+
TypeDescriptor.RegisterType<Keys>();
203+
}
204+
199205
Overflow = ToolStripItemOverflow.Never;
200206
MouseDownAndUpMustBeInSameItem = false;
201207
SupportsDisabledHotTracking = true;
@@ -1114,8 +1120,7 @@ internal void SetNativeTargetWindow(IWin32Window window)
11141120
}
11151121
else
11161122
{
1117-
// Call the trim safe API
1118-
TypeDescriptor.RegisterType<Keys>();
1123+
// Call the trim safe API, Keys type has been registered at Initialize()
11191124
return TypeDescriptor.GetConverterFromRegisteredType(typeof(Keys)).ConvertToString(context: null, CultureInfo.CurrentUICulture, shortcutKeys);
11201125
}
11211126
}

0 commit comments

Comments
 (0)