[uikit] Preserve method associated with `updateSearchResultsForSearchController:`. Fixes #5024 (#5027)

This method is called back from iOS (or tvOS) so there's no managed
reference pointing to it. However we know that if it's (private inner)
type is present it's because the callback (from native) is possible so
we can preserve the method conditionally (to the type presence).

https://github.com/xamarin/xamarin-macios/issues/5024
This commit is contained in:
Sebastien Pouliot 2018-10-22 21:54:54 -04:00 коммит произвёл GitHub
Родитель 74102bce2d
Коммит b403da0d85
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 17 добавлений и 0 удалений

Просмотреть файл

@ -5,6 +5,7 @@
#if !WATCH
using System;
using Foundation;
namespace UIKit {
@ -17,6 +18,8 @@ namespace UIKit {
this.cback = cback;
IsDirectBinding = false;
}
[Preserve (Conditional = true)] // called back from native, no direct managed reference (except on the type itself)
public override void UpdateSearchResultsForSearchController (UISearchController searchController)
{
cback (searchController);

Просмотреть файл

@ -1038,6 +1038,20 @@ namespace LinkSdk {
Assert.NotNull (provider, "provider");
Assert.That (provider.ID, Is.EqualTo (new Guid ("981af8af-a3a3-419a-9f01-a518e3a17c1c")), "correct provider");
}
[Test]
public void Github5024 ()
{
TestRuntime.AssertXcodeVersion (6,0);
var sc = new UISearchController ((UIViewController) null);
sc.SetSearchResultsUpdater ((vc) => { });
var a = typeof (UISearchController).AssemblyQualifiedName;
var n = a.Replace ("UIKit.UISearchController", "UIKit.UISearchController+__Xamarin_UISearchResultsUpdating");
var t = Type.GetType (n);
Assert.NotNull (t, "private inner type");
Assert.IsNotNull (t.GetMethod ("UpdateSearchResultsForSearchController"), "preserved");
}
#endif // !__WATCHOS__
[Test]