зеркало из https://github.com/dotnet/winforms.git
Merge pull request #11407 from LakshanF/TypeRegisterationTest
Get TrimTest to 0 trim warnings
This commit is contained in:
Коммит
f0811e2c36
|
@ -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>
|
||||
|
@ -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.
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">Použití BinaryFormatter není podporováno.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">Použití BinaryFormatter není podporováno.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">Objekt child není podřízeným ovládacím prvkem tohoto nadřazeného objektu.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Vyvolá se, když je změněna vlastnost AutoSize.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Chcete-li nahradit toto výchozí dialogové okno, nastavte popisovač události
|
|||
<target state="translated">Umožňuje uživateli procházet webové stránky uvnitř formuláře.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Operace {0} se součástí se nezdařila. Generovaný kód chyby je 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">Die Verwendung von BinaryFormatter wird nicht unterstützt.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">Die Verwendung von BinaryFormatter wird nicht unterstützt.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">"child" ist kein untergeordnetes Steuerelement dieses übergeordneten Elements.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Tritt ein, wenn sich die AutoSize-Eigenschaft geändert hat.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Behandeln Sie das DataError-Ereignis, um dieses Standarddialogfeld zu ersetzen.<
|
|||
<target state="translated">Ermöglicht dem Benutzer das Besuchen von Webseiten im Formular.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Fehler beim {0}-Vorgang für die Komponente. Fehlercode: 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">No se admite el uso de BinaryFormatter.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">No se admite el uso de BinaryFormatter.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' no es un control secundario de este primario.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Tiene lugar cuando la propiedad AutoSize ha cambiado.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Para reemplazar este cuadro de diálogo predeterminado controle el evento DataEr
|
|||
<target state="translated">Permite al usuario explorar páginas web dentro del formulario.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Error de la operación {0} en el componente con el código de error 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">L’utilisation de BinaryFormatter n’est pas prise en charge.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">L’utilisation de BinaryFormatter n’est pas prise en charge.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' n'est pas un contrôle enfant de ce parent.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Se produit lorsque la propriété AutoSize est modifiée.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Pour remplacer cette boîte de dialogue par défaut, traitez l'événement DataE
|
|||
<target state="translated">Permet à l'utilisateur de parcourir les pages web au sein de votre formulaire.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">L'opération {0} sur le composant a échoué avec le code d'erreur 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">L'uso di BinaryFormatter non è supportato.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">L'uso di BinaryFormatter non è supportato.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' non è un controllo figlio di questo elemento.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Generato alla modifica della proprietà AutoSize.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Per sostituire questa finestra di dialogo predefinita, gestire l'evento DataErro
|
|||
<target state="translated">Consente all'utente di esplorare pagine Web all'interno del form.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Operazione {0} sul componente non riuscita con codice di errore 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">BinaryFormatter の使用はサポートされていません。</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">BinaryFormatter の使用はサポートされていません。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'子' はこの親の子コントロールではありません。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">AutoSize プロパティが変更したときに発生します。</target>
|
||||
|
@ -4639,6 +4644,11 @@ To replace this default dialog please handle the DataError event.</source>
|
|||
<target state="translated">フォーム内の Web ページをユーザーが参照できるようにします。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">コンポーネントの操作 {0} がエラー コード 0x{1:X} を生成して、成功しませんでした。</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">BinaryFormatter 사용은 지원되지 않습니다.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">BinaryFormatter 사용은 지원되지 않습니다.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child'는 이 부모의 자식 컨트롤이 아닙니다.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">AutoSize 속성이 변경되면 발생합니다.</target>
|
||||
|
@ -4639,6 +4644,11 @@ To replace this default dialog please handle the DataError event.</source>
|
|||
<target state="translated">사용자가 폼에서 웹 페이지를 찾을 수 있습니다.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">구성 요소의 {0} 작업이 실패했습니다. 오류 코드 0x{1:X}를 생성합니다.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">Używanie elementu BinaryFormatter nie jest obsługiwane.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">Używanie elementu BinaryFormatter nie jest obsługiwane.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">Element 'child' nie jest formantem podrzędnym dla tego formantu.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Występuje, gdy właściwość AutoSize zostanie zmieniona.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Aby zamienić to domyślne okno dialogowe, obsłuż zdarzenie DataError.</target
|
|||
<target state="translated">Umożliwia użytkownikowi przeglądanie stron sieci Web w formularzu.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Niepowodzenie operacji {0} dla składnika, kod błędu 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">Não há suporte para o uso do BinaryFormatter.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">Não há suporte para o uso do BinaryFormatter.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' não é um controle filho deste pai.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Ocorre quando a propriedade AutoSize é alterada.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Para substituir a caixa de diálogo padrão, manipule o evento DataError.</targe
|
|||
<target state="translated">Permite que o usuário navegue pelas páginas da Web dentro do formulário.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">A operação {0} no componente não teve êxito, gerando o código de erro 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">Использование BinaryFormatter не поддерживается.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">Использование BinaryFormatter не поддерживается.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' не является дочерним элементом управления этого родительского элемента.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">Возникает при изменении свойства AutoSize.</target>
|
||||
|
@ -4639,6 +4644,11 @@ To replace this default dialog please handle the DataError event.</source>
|
|||
<target state="translated">Позволяет пользователю просматривать веб-страницы внутри формы.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Невозможно выполнить операцию {0} для компонента; генерируется код ошибки 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">BinaryFormatter kullanımı desteklenmiyor.</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">BinaryFormatter kullanımı desteklenmiyor.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'alt' bu üstün alt denetimi değil.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">AutoSize özelliği değiştiğinde gerçekleşir.</target>
|
||||
|
@ -4639,6 +4644,11 @@ Bu varsayılan iletişim kutusunu değiştirmek için, lütfen DataError olayın
|
|||
<target state="translated">Kullanıcıların formunuzdaki Web sayfalarına gitmesine olanak tanır.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">Bileşen üzerindeki {0} işlemi başarılı olmadı, oluşturulan hata kodu 0x{1:X}.</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">不支持使用 BinaryFormatter。</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">不支持使用 BinaryFormatter。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">“child”不是此父级的子控件。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">在 AutoSize 属性更改时发生。</target>
|
||||
|
@ -4639,6 +4644,11 @@ To replace this default dialog please handle the DataError event.</source>
|
|||
<target state="translated">允许用户在窗体内浏览网页。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">该组件上的 {0} 操作失败,生成错误代码 0x{1:X}。</target>
|
||||
|
|
|
@ -288,8 +288,8 @@
|
|||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BinaryFormatterNotSupported">
|
||||
<source>Using the BinaryFormatter is not supported.</source>
|
||||
<target state="translated">不支援使用 BinaryFormatter。</target>
|
||||
<source>Using the BinaryFormatter is not supported in trimmed applications.</source>
|
||||
<target state="needs-review-translation">不支援使用 BinaryFormatter。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="BindableComponentBindingContextChangedDescr">
|
||||
|
@ -1662,6 +1662,11 @@
|
|||
<target state="translated">'child' 不是此父系的子控制項。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlNotSupportedInTrimming">
|
||||
<source>'{0}' is not supported in trimmed applications.</source>
|
||||
<target state="new">'{0}' is not supported in trimmed applications.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="ControlOnAutoSizeChangedDescr">
|
||||
<source>Occurs when the AutoSize property has changed.</source>
|
||||
<target state="translated">當 AutoSize 屬性變更時發生。</target>
|
||||
|
@ -4639,6 +4644,11 @@ To replace this default dialog please handle the DataError event.</source>
|
|||
<target state="translated">讓使用者可以瀏覽表單內部的 Web 網頁。</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DesignTimeFeaturesNotSupported">
|
||||
<source>Design time features are not supported.</source>
|
||||
<target state="new">Design time features are not supported.</target>
|
||||
<note />
|
||||
</trans-unit>
|
||||
<trans-unit id="DispInvokeFailed">
|
||||
<source>Operation {0} on the component did not succeed, generating the error code 0x{1:X}.</source>
|
||||
<target state="translated">元件的作業 {0} 失敗,產生錯誤碼 0x{1:X}。</target>
|
||||
|
|
|
@ -14,8 +14,23 @@ namespace System.Drawing.Design;
|
|||
/// </summary>
|
||||
public class UITypeEditor
|
||||
{
|
||||
// Feature switch, when set to false, UITypeEditor is not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Drawing.Design.UITypeEditor.IsSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
private static bool IsSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Drawing.Design.UITypeEditor.IsSupported", out bool isSupported)
|
||||
? isSupported
|
||||
: true;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
static UITypeEditor()
|
||||
{
|
||||
// Trimming doesn't support UITypeEditor
|
||||
if (!IsSupported)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Our set of intrinsic editors.
|
||||
Hashtable intrinsicEditors = new Hashtable
|
||||
{
|
||||
|
@ -47,6 +62,14 @@ public class UITypeEditor
|
|||
TypeDescriptor.AddEditorTable(typeof(UITypeEditor), intrinsicEditors);
|
||||
}
|
||||
|
||||
public UITypeEditor()
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(UITypeEditor)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if drop-down editors should be resizable by the user.
|
||||
/// </summary>
|
||||
|
|
|
@ -136,6 +136,15 @@ public partial class Control
|
|||
private short _accelCount = -1;
|
||||
private RECT* _adjustRect; // temporary rect used during OnPosRectChange && SetObjectRects
|
||||
|
||||
// Feature switch, when set to false, ActiveX is not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.ActiveXImpl.IsSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
private static bool IsSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.ActiveXImpl.IsSupported", out bool isSupported)
|
||||
? isSupported
|
||||
: true;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new ActiveXImpl.
|
||||
/// </summary>
|
||||
|
@ -1035,6 +1044,11 @@ public partial class Control
|
|||
/// <inheritdoc cref="IPersistPropertyBag.Load(IPropertyBag*, IErrorLog*)"/>
|
||||
internal unsafe void Load(IPropertyBag* propertyBag, IErrorLog* errorLog)
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(ActiveXImpl)));
|
||||
}
|
||||
|
||||
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(
|
||||
_control,
|
||||
[DesignerSerializationVisibilityAttribute.Visible]);
|
||||
|
@ -1134,6 +1148,11 @@ public partial class Control
|
|||
#pragma warning disable SYSLIB0011 // Type or member is obsolete
|
||||
if (!success)
|
||||
{
|
||||
if (!DataObject.ComposedDataObject.EnableUnsafeBinaryFormatterInNativeObjectSerialization)
|
||||
{
|
||||
throw new NotSupportedException(SR.BinaryFormatterNotSupported);
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
deserialized = new BinaryFormatter().Deserialize(stream);
|
||||
}
|
||||
|
@ -1420,6 +1439,11 @@ public partial class Control
|
|||
{
|
||||
Type? eventInterface = null;
|
||||
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(ActiveXImpl)));
|
||||
}
|
||||
|
||||
// Get the first declared interface, if any.
|
||||
if (controlType.GetCustomAttributes<ComSourceInterfacesAttribute>(inherit: false).FirstOrDefault()
|
||||
is { } comSourceInterfaces)
|
||||
|
@ -1469,6 +1493,11 @@ public partial class Control
|
|||
/// <inheritdoc cref="IPersistPropertyBag.Save(IPropertyBag*, BOOL, BOOL)"/>
|
||||
internal void Save(IPropertyBag* propertyBag, BOOL clearDirty, BOOL saveAllProperties)
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(ActiveXImpl)));
|
||||
}
|
||||
|
||||
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(
|
||||
_control,
|
||||
[DesignerSerializationVisibilityAttribute.Visible]);
|
||||
|
@ -1503,6 +1532,11 @@ public partial class Control
|
|||
{
|
||||
stream.SetLength(0);
|
||||
|
||||
if (!DataObject.ComposedDataObject.EnableUnsafeBinaryFormatterInNativeObjectSerialization)
|
||||
{
|
||||
throw new NotSupportedException(SR.BinaryFormatterNotSupported);
|
||||
}
|
||||
|
||||
#pragma warning disable SYSLIB0011 // Type or member is obsolete
|
||||
new BinaryFormatter().Serialize(stream, sourceValue);
|
||||
#pragma warning restore
|
||||
|
|
|
@ -56,6 +56,22 @@ public unsafe partial class Control :
|
|||
"Makes double buffered controls non-double buffered");
|
||||
#endif
|
||||
|
||||
// Feature switch, when set to false, design time features of controls are not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.Control.AreDesignTimeFeaturesSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
internal static bool AreDesignTimeFeaturesSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.Control.AreDesignTimeFeaturesSupported", out bool isEnabled)
|
||||
? isEnabled
|
||||
: true;
|
||||
|
||||
// Feature switch, when set to true, used for trimming to access ComponentModel in a trim safe manner
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.Control.UseComponentModelRegisteredTypes")]
|
||||
internal static bool UseComponentModelRegisteredTypes { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.Control.UseComponentModelRegisteredTypes", out bool isEnabled)
|
||||
? isEnabled
|
||||
: false;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
private static readonly uint WM_GETCONTROLNAME = PInvoke.RegisterWindowMessage("WM_GETCONTROLNAME");
|
||||
private static readonly uint WM_GETCONTROLTYPE = PInvoke.RegisterWindowMessage("WM_GETCONTROLTYPE");
|
||||
|
||||
|
@ -977,6 +993,12 @@ public unsafe partial class Control :
|
|||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public void ResetBindings()
|
||||
{
|
||||
if (!Binding.IsSupported)
|
||||
{
|
||||
// This gets called with Dispose that needs to be handled, a throwing is not appropriate in this case.
|
||||
return;
|
||||
}
|
||||
|
||||
ControlBindingsCollection? bindings = (ControlBindingsCollection?)Properties.GetObject(s_bindingsProperty);
|
||||
bindings?.Clear();
|
||||
}
|
||||
|
@ -1029,7 +1051,6 @@ public unsafe partial class Control :
|
|||
public virtual BindingContext? BindingContext
|
||||
{
|
||||
get => BindingContextInternal;
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
set => BindingContextInternal = value;
|
||||
}
|
||||
|
||||
|
@ -1670,6 +1691,11 @@ public unsafe partial class Control :
|
|||
{
|
||||
get
|
||||
{
|
||||
if (!Binding.IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(SR.BindingNotSupported);
|
||||
}
|
||||
|
||||
ControlBindingsCollection? bindings = (ControlBindingsCollection?)Properties.GetObject(s_bindingsProperty);
|
||||
if (bindings is null)
|
||||
{
|
||||
|
@ -13006,6 +13032,11 @@ public unsafe partial class Control :
|
|||
|
||||
if (site is not null && site.DesignMode && site.TryGetService(out changeService))
|
||||
{
|
||||
if (!AreDesignTimeFeaturesSupported)
|
||||
{
|
||||
throw new NotSupportedException(SR.DesignTimeFeaturesNotSupported);
|
||||
}
|
||||
|
||||
sizeProperty = TypeDescriptor.GetProperties(this)[PropertyNames.Size];
|
||||
locationProperty = TypeDescriptor.GetProperties(this)[PropertyNames.Location];
|
||||
Debug.Assert(sizeProperty is not null && locationProperty is not null, "Error retrieving Size/Location properties on Control.");
|
||||
|
|
|
@ -155,6 +155,11 @@ public abstract partial class ButtonBase : Control, ICommandBindingTargetProvide
|
|||
{
|
||||
if (value != Color.Empty)
|
||||
{
|
||||
if (!AreDesignTimeFeaturesSupported)
|
||||
{
|
||||
throw new NotSupportedException(SR.DesignTimeFeaturesNotSupported);
|
||||
}
|
||||
|
||||
PropertyDescriptor? pd = TypeDescriptor.GetProperties(this)["UseVisualStyleBackColor"];
|
||||
pd?.SetValue(this, false);
|
||||
}
|
||||
|
|
|
@ -135,6 +135,11 @@ public abstract class ListControl : Control
|
|||
{
|
||||
get
|
||||
{
|
||||
if (!Binding.IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(SR.BindingNotSupported);
|
||||
}
|
||||
|
||||
if (_displayMemberConverter is null)
|
||||
{
|
||||
PropertyDescriptorCollection? props = DataManager?.GetItemProperties();
|
||||
|
@ -422,6 +427,11 @@ public abstract class ListControl : Control
|
|||
{
|
||||
if (item is not null && !string.IsNullOrEmpty(field))
|
||||
{
|
||||
if (!Binding.IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(SR.BindingNotSupported);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// if we have a dataSource, then use that to display the string
|
||||
|
@ -527,7 +537,15 @@ public abstract class ListControl : Control
|
|||
}
|
||||
|
||||
// Try Formatter.FormatObject
|
||||
s_stringTypeConverter ??= TypeDescriptor.GetConverter(typeof(string));
|
||||
if (!UseComponentModelRegisteredTypes)
|
||||
{
|
||||
s_stringTypeConverter ??= TypeDescriptor.GetConverter(typeof(string));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
s_stringTypeConverter ??= TypeDescriptor.GetConverterFromRegisteredType(typeof(string));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -45,7 +45,15 @@ public class OpacityConverter : TypeConverter
|
|||
double percent;
|
||||
try
|
||||
{
|
||||
percent = (double)TypeDescriptor.GetConverter(typeof(double)).ConvertFrom(context, culture, text)!;
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
percent = (double)TypeDescriptor.GetConverter(typeof(double)).ConvertFrom(context, culture, text)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
percent = (double)TypeDescriptor.GetConverterFromRegisteredType(typeof(double)).ConvertFrom(context, culture, text)!;
|
||||
}
|
||||
|
||||
// Assume they meant a percentage if it is > 1.0, else they actually
|
||||
// typed the correct double.
|
||||
|
|
|
@ -387,7 +387,6 @@ public partial class ToolStrip : ScrollableControl, IArrangedElement, ISupportTo
|
|||
return null;
|
||||
}
|
||||
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
set
|
||||
{
|
||||
if (Properties.GetObject(s_propBindingContext) != value)
|
||||
|
|
|
@ -196,6 +196,12 @@ public partial class ToolStripMenuItem : ToolStripDropDownItem
|
|||
|
||||
private void Initialize()
|
||||
{
|
||||
if (Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
// Register the type with the ComponentModel so as to be trim safe
|
||||
TypeDescriptor.RegisterType<Keys>();
|
||||
}
|
||||
|
||||
Overflow = ToolStripItemOverflow.Never;
|
||||
MouseDownAndUpMustBeInSameItem = false;
|
||||
SupportsDisabledHotTracking = true;
|
||||
|
@ -1108,7 +1114,15 @@ public partial class ToolStripMenuItem : ToolStripDropDownItem
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
return TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(context: null, CultureInfo.CurrentUICulture, shortcutKeys);
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
return TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(context: null, CultureInfo.CurrentUICulture, shortcutKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API, Keys type has been registered at Initialize()
|
||||
return TypeDescriptor.GetConverterFromRegisteredType(typeof(Keys)).ConvertToString(context: null, CultureInfo.CurrentUICulture, shortcutKeys);
|
||||
}
|
||||
}
|
||||
|
||||
internal override bool IsBeingTabbedTo()
|
||||
|
|
|
@ -28,7 +28,6 @@ public abstract class BindableComponent : Component, IBindableComponent
|
|||
{
|
||||
get => _bindingContext ??= [];
|
||||
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
set
|
||||
{
|
||||
if (!Equals(_bindingContext, value))
|
||||
|
|
|
@ -12,10 +12,14 @@ namespace System.Windows.Forms;
|
|||
[TypeConverter(typeof(ListBindingConverter))]
|
||||
public partial class Binding
|
||||
{
|
||||
// Feature switch, when set to false, binding is not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.Binding.IsSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
internal static bool IsSupported => AppContext.TryGetSwitch("System.Windows.Forms.Binding.IsSupported", out bool isSupported) ? isSupported : true;
|
||||
#pragma warning restore IDE0075 //Simplify conditional expression
|
||||
internal static bool IsSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.Binding.IsSupported", out bool isSupported)
|
||||
? isSupported
|
||||
: true;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
private BindingManagerBase? _bindingManagerBase;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ public partial class BindingContext : ICollection
|
|||
/// <summary>
|
||||
/// Initializes a new instance of the System.Windows.Forms.BindingContext class.
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
public BindingContext()
|
||||
{
|
||||
_listManagers = [];
|
||||
|
|
|
@ -12,7 +12,6 @@ public interface IBindableComponent : IComponent
|
|||
BindingContext? BindingContext
|
||||
{
|
||||
get;
|
||||
[RequiresUnreferencedCode(ComponentModelTrimIncompatibilityMessage)]
|
||||
set;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,15 @@ namespace System.Windows.Forms;
|
|||
/// </summary>
|
||||
public class ImageIndexConverter : Int32Converter
|
||||
{
|
||||
// Feature switch, when set to false, ImageIndexConverter is not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.ImageIndexConverter.IsSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
private static bool IsSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.ImageIndexConverter.IsSupported", out bool isSupported)
|
||||
? isSupported
|
||||
: true;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that indicates whether a <see langword="null" /> value is valid in
|
||||
/// the <see cref="TypeConverter.StandardValuesCollection" /> collection.
|
||||
|
@ -83,6 +92,11 @@ public class ImageIndexConverter : Int32Converter
|
|||
/// </returns>
|
||||
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext? context)
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(ImageIndexConverter)));
|
||||
}
|
||||
|
||||
if (context is not null && context.Instance is not null)
|
||||
{
|
||||
object? instance = context.Instance;
|
||||
|
|
|
@ -26,7 +26,6 @@ internal static class Formatter
|
|||
/// If the caller is expecting a nullable value back, we must also re-wrap the final result
|
||||
/// inside a nullable value before returning.
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(ComponentModelTrimIncompatibilityMessage)]
|
||||
public static object? FormatObject(
|
||||
object? value,
|
||||
Type targetType,
|
||||
|
@ -84,7 +83,6 @@ internal static class Formatter
|
|||
/// - Uses TypeConverters or IConvertible where appropriate
|
||||
/// - Throws a FormatException is no suitable conversion can be found
|
||||
/// </summary>
|
||||
[RequiresUnreferencedCode(ComponentModelTrimIncompatibilityMessage)]
|
||||
private static object? FormatObjectInternal(
|
||||
object? value,
|
||||
Type targetType,
|
||||
|
@ -137,13 +135,34 @@ internal static class Formatter
|
|||
// The converters for properties should take precedence. Unfortunately, we don't know whether we have one. Check vs. the
|
||||
// type's TypeConverter. We're punting the case where the property-provided converter is the same as the type's converter.
|
||||
Type sourceType = value.GetType();
|
||||
TypeConverter sourceTypeTypeConverter = TypeDescriptor.GetConverter(sourceType);
|
||||
|
||||
TypeConverter sourceTypeTypeConverter;
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
sourceTypeTypeConverter = TypeDescriptor.GetConverter(sourceType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
sourceTypeTypeConverter = TypeDescriptor.GetConverterFromRegisteredType(sourceType);
|
||||
}
|
||||
|
||||
if (sourceConverter is not null && sourceConverter != sourceTypeTypeConverter && sourceConverter.CanConvertTo(targetType))
|
||||
{
|
||||
return sourceConverter.ConvertTo(context: null, GetFormatterCulture(formatInfo), value, targetType);
|
||||
}
|
||||
|
||||
TypeConverter targetTypeTypeConverter = TypeDescriptor.GetConverter(targetType);
|
||||
TypeConverter targetTypeTypeConverter;
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
targetTypeTypeConverter = TypeDescriptor.GetConverter(targetType);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
targetTypeTypeConverter = TypeDescriptor.GetConverterFromRegisteredType(targetType);
|
||||
}
|
||||
|
||||
if (targetConverter is not null && targetConverter != targetTypeTypeConverter && targetConverter.CanConvertFrom(sourceType))
|
||||
{
|
||||
return targetConverter.ConvertFrom(context: null, GetFormatterCulture(formatInfo), value);
|
||||
|
|
|
@ -266,7 +266,6 @@ public class ContainerControl : ScrollableControl, IContainerControl
|
|||
return bm;
|
||||
}
|
||||
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
set => base.BindingContext = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -220,7 +220,6 @@ public partial class SplitContainer : ContainerControl, ISupportInitialize
|
|||
return BindingContextInternal;
|
||||
}
|
||||
|
||||
[RequiresUnreferencedCode(IBindableComponent.ComponentModelTrimIncompatibilityMessage)]
|
||||
set
|
||||
{
|
||||
BindingContextInternal = value;
|
||||
|
|
|
@ -11,6 +11,15 @@ internal sealed partial class MdiWindowDialog : Form
|
|||
private TableLayoutPanel _okCancelTableLayoutPanel;
|
||||
private Form? _active;
|
||||
|
||||
// Feature switch, when set to false, MdiWindowDialog is not supported in trimmed applications.
|
||||
[FeatureSwitchDefinition("System.Windows.Forms.MdiWindowDialog.IsSupported")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
private static bool IsSupported { get; } =
|
||||
AppContext.TryGetSwitch("System.Windows.Forms.MdiWindowDialog.IsSupported", out bool isSupported)
|
||||
? isSupported
|
||||
: true;
|
||||
#pragma warning restore IDE0075
|
||||
|
||||
public MdiWindowDialog()
|
||||
: base()
|
||||
{
|
||||
|
@ -74,6 +83,11 @@ internal sealed partial class MdiWindowDialog : Form
|
|||
[MemberNotNull(nameof(_okCancelTableLayoutPanel))]
|
||||
private void InitializeComponent()
|
||||
{
|
||||
if (!IsSupported)
|
||||
{
|
||||
throw new NotSupportedException(string.Format(SR.ControlNotSupportedInTrimming, nameof(MdiWindowDialog)));
|
||||
}
|
||||
|
||||
System.ComponentModel.ComponentResourceManager resources = new(typeof(MdiWindowDialog));
|
||||
_itemList = new ListBox();
|
||||
_okButton = new Button();
|
||||
|
|
|
@ -16,9 +16,12 @@ public unsafe partial class DataObject
|
|||
{
|
||||
internal unsafe partial class ComposedDataObject
|
||||
{
|
||||
// Feature switch, when set to false, BinaryFormatter is not supported in trimmed applications.
|
||||
// This field, using the default BinaryFormatter switch, is used to control trim warnings related to using BinaryFormatter in WinForms trimming.
|
||||
// The trimmer will generate a warning when set to true and will not generate a warning when set to false.
|
||||
[FeatureSwitchDefinition("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization")]
|
||||
#pragma warning disable IDE0075 // Simplify conditional expression - the simpler expression is hard to read
|
||||
private static bool EnableUnsafeBinaryFormatterInNativeObjectSerialization { get; } =
|
||||
internal static bool EnableUnsafeBinaryFormatterInNativeObjectSerialization { get; } =
|
||||
AppContext.TryGetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", out bool isEnabled)
|
||||
? isEnabled
|
||||
: true;
|
||||
|
|
|
@ -466,7 +466,18 @@ public sealed partial class TableLayoutSettings : LayoutSettings, ISerializable
|
|||
|
||||
void ISerializable.GetObjectData(SerializationInfo si, StreamingContext context)
|
||||
{
|
||||
TypeConverter converter = TypeDescriptor.GetConverter(this);
|
||||
TypeConverter converter;
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
converter = TypeDescriptor.GetConverter(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
TypeDescriptor.RegisterType<TableLayoutSettings>();
|
||||
converter = TypeDescriptor.GetConverterFromRegisteredType(this);
|
||||
}
|
||||
|
||||
string? stringVal = converter.ConvertToInvariantString(this);
|
||||
|
||||
if (!string.IsNullOrEmpty(stringVal))
|
||||
|
@ -485,6 +496,11 @@ public sealed partial class TableLayoutSettings : LayoutSettings, ISerializable
|
|||
{
|
||||
List<ControlInformation> controlsInfo = new(Owner!.Children.Count);
|
||||
|
||||
if (Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
TypeDescriptor.RegisterType<Control>();
|
||||
}
|
||||
|
||||
foreach (IArrangedElement element in Owner.Children)
|
||||
{
|
||||
if (element is Control c)
|
||||
|
@ -493,7 +509,17 @@ public sealed partial class TableLayoutSettings : LayoutSettings, ISerializable
|
|||
|
||||
// We need to go through the PropertyDescriptor for the Name property
|
||||
// since it is shadowed.
|
||||
PropertyDescriptor? prop = TypeDescriptor.GetProperties(c)["Name"];
|
||||
PropertyDescriptor? prop;
|
||||
if (!Control.UseComponentModelRegisteredTypes)
|
||||
{
|
||||
prop = TypeDescriptor.GetProperties(c)["Name"];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Call the trim safe API
|
||||
prop = TypeDescriptor.GetPropertiesFromRegisteredType(c)["Name"];
|
||||
}
|
||||
|
||||
if (prop is not null && prop.PropertyType == typeof(string))
|
||||
{
|
||||
controlInfo.Name = prop.GetValue(c);
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System.Collections;
|
||||
using System.Runtime.Serialization;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.Com;
|
||||
|
||||
namespace System.Windows.Forms.Tests;
|
||||
|
||||
public unsafe partial class Control_ActiveXImplTests
|
||||
{
|
||||
[WinFormsFact]
|
||||
public void ActiveXImpl_SaveLoad_BinaryFormatterProperty_FormatterEnabled()
|
||||
{
|
||||
using MyControl control = new();
|
||||
|
||||
// We need to have a type that doesn't have a TypeConverter that implements ISerializable to hit the
|
||||
// BinaryFormatter code path.
|
||||
SerializableStruct myValue = new() { Value = "HelloThere" };
|
||||
control.SerializableValue = myValue;
|
||||
IPersistStreamInit.Interface persistStream = control;
|
||||
|
||||
using MemoryStream memoryStream = new();
|
||||
using var istream = memoryStream.ToIStream();
|
||||
HRESULT hr = persistStream.Save(istream.Value, fClearDirty: BOOL.FALSE);
|
||||
Assert.True(hr.Succeeded);
|
||||
control.SerializableValue = default;
|
||||
|
||||
istream.Value->Seek(0, SeekOrigin.Begin);
|
||||
hr = persistStream.Load(istream.Value);
|
||||
Assert.True(hr.Succeeded);
|
||||
Assert.Equal(myValue, control.SerializableValue);
|
||||
}
|
||||
|
||||
private class MyControl : Control
|
||||
{
|
||||
public SerializableStruct SerializableValue { get; set; }
|
||||
}
|
||||
|
||||
private class BinaryFormatterPropertiesControl : Control
|
||||
{
|
||||
public Hashtable Table { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct SerializableStruct : ISerializable
|
||||
{
|
||||
public string Value { get; set; }
|
||||
|
||||
public readonly void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue(nameof(Value), Value, typeof(string));
|
||||
}
|
||||
|
||||
private SerializableStruct(SerializationInfo serializationInfo, StreamingContext streamingContext)
|
||||
{
|
||||
Value = (string)serializationInfo.GetValue(nameof(Value), typeof(string));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,4 +22,38 @@
|
|||
<ProjectReference Include="..\..\..\src\System.Windows.Forms.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- feature switches for trimming-->
|
||||
<ItemGroup>
|
||||
<RuntimeHostConfigurationOption Include="System.ComponentModel.Design.IDesignerHost.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.Binding.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.ComponentModel.DefaultValueAttribute.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Drawing.Design.UITypeEditor.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.ActiveXImpl.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.Control.AreDesignTimeFeaturesSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.MdiWindowDialog.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.ImageIndexConverter.IsSupported"
|
||||
Value="false"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.Primitives.TypeConverterHelper.UseComponentModelRegisteredTypes"
|
||||
Value="true"
|
||||
Trim="true" />
|
||||
<RuntimeHostConfigurationOption Include="System.Windows.Forms.Control.UseComponentModelRegisteredTypes"
|
||||
Value="true"
|
||||
Trim="true" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -32,30 +32,6 @@ public unsafe class Control_ActiveXImplTests
|
|||
Assert.Equal(Color.Bisque, control.BackColor);
|
||||
}
|
||||
|
||||
[WinFormsFact]
|
||||
public void ActiveXImpl_SaveLoad_BinaryFormatterProperty_FormatterEnabled()
|
||||
{
|
||||
using BinaryFormatterScope formatterScope = new(enable: true);
|
||||
using MyControl control = new();
|
||||
|
||||
// We need to have a type that doesn't have a TypeConverter that implements ISerializable to hit the
|
||||
// BinaryFormatter code path.
|
||||
SerializableStruct myValue = new() { Value = "HelloThere" };
|
||||
control.SerializableValue = myValue;
|
||||
IPersistStreamInit.Interface persistStream = control;
|
||||
|
||||
using MemoryStream memoryStream = new();
|
||||
using var istream = memoryStream.ToIStream();
|
||||
HRESULT hr = persistStream.Save(istream.Value, fClearDirty: BOOL.FALSE);
|
||||
Assert.True(hr.Succeeded);
|
||||
control.SerializableValue = default;
|
||||
|
||||
istream.Value->Seek(0, SeekOrigin.Begin);
|
||||
hr = persistStream.Load(istream.Value);
|
||||
Assert.True(hr.Succeeded);
|
||||
Assert.Equal(myValue, control.SerializableValue);
|
||||
}
|
||||
|
||||
[WinFormsFact]
|
||||
public void ActiveXImpl_SaveLoad_BinaryFormatterProperty_FormatterDisabled()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче