diff --git a/src/frameworks.sources b/src/frameworks.sources index c6d65ce577..73dd001ba7 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -2183,7 +2183,6 @@ MACCATALYST_FRAMEWORKS = \ AdServices \ AdSupport \ AddressBook \ - AddressBookUI \ AppTrackingTransparency \ AudioToolbox \ AudioUnit \ diff --git a/src/generate-type-forwarders/Program.cs b/src/generate-type-forwarders/Program.cs index 177d9c8c7a..dd20209383 100644 --- a/src/generate-type-forwarders/Program.cs +++ b/src/generate-type-forwarders/Program.cs @@ -97,7 +97,21 @@ namespace GenerateTypeForwarders { { if (method.IsPrivate) return; - if (!method.IsConstructor && method.IsSpecialName) + + if (method.IsConstructor) { + // we can have an internal ctor using internal types that are not generated leading to uncompilable code + // e.g. `internal DisplayedPropertiesCollection (ABFunc g, Action s)` + if (method.IsAssembly && method.HasParameters) { + foreach (var p in method.Parameters) { + // check is the type is public - if not it won't be generated + if (p.ParameterType.Resolve ().IsNotPublic) { + // but we can't skip the generation as without any .ctor the compiler will add a default, public one + // so we create a custom signature to ensure an (internal) ctor exists + p.ParameterType = method.DeclaringType; + } + } + } + } else if (method.IsSpecialName) return; if (method.Name == "Finalize") @@ -201,15 +215,14 @@ namespace GenerateTypeForwarders { if (nsobject && method.IsConstructor && !method.IsStatic) sb.Append ('\t', indent + 1).AppendLine (" : base (System.IntPtr.Zero)"); // if there is a base constructor with the same signature, call it - else if (method.IsConstructor && method.HasParameters && method.Parameters.Count > 0) { - var baseConstructors = method.DeclaringType.BaseType?.Resolve ()?.Methods?.Where (v => v.IsConstructor && v.Parameters.Count == method.Parameters.Count); - if (AllParameterTypeMatch (baseConstructors, method.Parameters, out var _)) { + else if (method.IsConstructor && method.HasParameters) { + var baseConstructors = method.DeclaringType.BaseType?.Resolve ()?.Methods?.Where (v => v.IsConstructor && v.HasParameters); + if (StartParameterTypeMatch (baseConstructors, method.Parameters, out var baseCtor)) { sb.Append ($"{strIndent}\t: base ("); - for (var i = 0; i < method.Parameters.Count; i++) { - var param = method.Parameters [i]; + for (var i = 0; i < baseCtor.Parameters.Count; i++) { if (i > 0) sb.Append (", "); - sb.Append ($"@{param.Name}"); + sb.Append ($"@{method.Parameters [i].Name}"); // need the original name } sb.AppendLine (")"); } @@ -272,6 +285,28 @@ namespace GenerateTypeForwarders { return false; } + static bool StartParameterTypeMatch (IEnumerable methods, IList parameters, out MethodDefinition matchingMethod) + { + matchingMethod = null; + + foreach (var method in methods) { + if (parameters.Count == 0) { + matchingMethod = method; + return true; + } + var parameterCount = method.HasParameters ? method.Parameters.Count : 0; + for (var i = 0; i < parameters.Count; i++) { + var a = method.Parameters [i]; + var b = parameters [i]; + if (a.ParameterType.FullName == b.ParameterType.FullName) { + matchingMethod = method; + return true; + } + } + } + return false; + } + static void EmitField (StringBuilder sb, FieldDefinition fd, int indent) { var strIndent = new string ('\t', indent); diff --git a/tests/linker/ios/link sdk/LinkSdkRegressionTest.cs b/tests/linker/ios/link sdk/LinkSdkRegressionTest.cs index 605e04a812..9899c8abd2 100644 --- a/tests/linker/ios/link sdk/LinkSdkRegressionTest.cs +++ b/tests/linker/ios/link sdk/LinkSdkRegressionTest.cs @@ -22,8 +22,10 @@ using System.Xml; using Mono.Data.Sqlite; #endif using MonoTouch; -#if !__TVOS__ && !__WATCHOS__ +#if HAS_ADDRESSBOOK using AddressBook; +#endif +#if HAS_ADDRESSBOOKUI using AddressBookUI; #endif #if !__WATCHOS__ @@ -172,7 +174,7 @@ namespace LinkSdk { Assert.That (m.GetType ().Name, Is.EqualTo ("RuntimeModule"), "RuntimeModule"); } -#if !__TVOS__ && !__WATCHOS__ +#if HAS_ADDRESSBOOK && HAS_ADDRESSBOOKUI [Test] // http://bugzilla.xamarin.com/show_bug.cgi?id=980 public void Bug980_AddressBook_NRE () @@ -199,7 +201,7 @@ namespace LinkSdk { TestRuntime.AssertSystemVersion (PlatformName.MacCatalyst, 14, 0, throwIfOtherPlatform: false); // The AddressBook framework was introduced in Mac Catalyst 14.0 Assert.IsNotNull (ABPersonAddressKey.City, "ABPersonAddressKey"); } -#endif // !__TVOS__ && !__WATCHOS__ +#endif // HAS_ADDRESSBOOKUI [Test] // http://bugzilla.xamarin.com/show_bug.cgi?id=1387 @@ -1166,4 +1168,4 @@ namespace LinkSdk { Assert.That (Thread.CurrentPrincipal.Identity.Name, Is.EqualTo ("abc"), "Name"); } } -} \ No newline at end of file +} diff --git a/tests/monotouch-test/AddressBook/AddressBookTest.cs b/tests/monotouch-test/AddressBook/AddressBookTest.cs index 685d4110a7..2553f90c9a 100644 --- a/tests/monotouch-test/AddressBook/AddressBookTest.cs +++ b/tests/monotouch-test/AddressBook/AddressBookTest.cs @@ -7,7 +7,7 @@ // Copyright 2012 Xamarin Inc. All rights reserved. // -#if !__TVOS__ && !__WATCHOS__ && !MONOMAC +#if HAS_ADDRESSBOOK using System; using Foundation; @@ -61,4 +61,4 @@ namespace MonoTouchFixtures.AddressBook { } } -#endif // !__TVOS__ && !__WATCHOS__ +#endif // HAS_ADDRESSBOOKUI diff --git a/tests/monotouch-test/AddressBookUI/AddressFormattingTest.cs b/tests/monotouch-test/AddressBookUI/AddressFormattingTest.cs index a996bb6080..054601e443 100644 --- a/tests/monotouch-test/AddressBookUI/AddressFormattingTest.cs +++ b/tests/monotouch-test/AddressBookUI/AddressFormattingTest.cs @@ -7,7 +7,7 @@ // Copyright 2012-2014, 2016 Xamarin Inc. All rights reserved. // -#if !__TVOS__ && !__WATCHOS__ && !MONOMAC +#if HAS_ADDRESSBOOKUI using System; using System.Globalization; @@ -76,4 +76,4 @@ namespace MonoTouchFixtures.AddressBookUI { } } -#endif // !__TVOS__ && !__WATCHOS__ +#endif // HAS_ADDRESSBOOKUI diff --git a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs index fbdde24516..444d84be52 100644 --- a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs +++ b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs @@ -7,8 +7,10 @@ using System.Threading; using CoreFoundation; using MapKit; -#if !__TVOS__ && !__WATCHOS__ && !MONOMAC +#if HAS_ADDRESSBOOK using AddressBook; +#endif +#if HAS_ADDRESSBOOKUI using AddressBookUI; #endif using Foundation; @@ -2202,7 +2204,7 @@ namespace MonoTouchFixtures.ObjCRuntime { } #endif // !__WATCHOS__ -#if !__TVOS__ && !__WATCHOS__ && !MONOMAC// No ABPeoplePickerNavigationControllerDelegate +#if HAS_ADDRESSBOOK && HAS_ADDRESSBOOKUI [Test] public void VoidPtrToINativeObjectArgument () { @@ -2225,7 +2227,7 @@ namespace MonoTouchFixtures.ObjCRuntime { personHandle = selectedPerson.Handle; } } -#endif // !__TVOS__ +#endif // HAS_ADDRESSBOOKUI #if !__TVOS__ // No Contacts framework in TVOS [Test] diff --git a/tests/xtro-sharpie/MacCatalyst-AddressBookUI.todo b/tests/xtro-sharpie/MacCatalyst-AddressBookUI.todo deleted file mode 100644 index cefeffa156..0000000000 --- a/tests/xtro-sharpie/MacCatalyst-AddressBookUI.todo +++ /dev/null @@ -1,33 +0,0 @@ -!missing-release-attribute-on-return-value! Foundation.NSObject AddressBookUI.ABNewPersonViewController::get_WeakDelegate()'s selector's ('newPersonViewDelegate') Objective-C method family ('new') indicates that the native method returns a retained object, and as such a '[return: Release]' attribute is required. -!unknown-field! ABPersonBirthdayProperty bound -!unknown-field! ABPersonDatesProperty bound -!unknown-field! ABPersonDepartmentNameProperty bound -!unknown-field! ABPersonEmailAddressesProperty bound -!unknown-field! ABPersonFamilyNameProperty bound -!unknown-field! ABPersonGivenNameProperty bound -!unknown-field! ABPersonInstantMessageAddressesProperty bound -!unknown-field! ABPersonJobTitleProperty bound -!unknown-field! ABPersonMiddleNameProperty bound -!unknown-field! ABPersonNamePrefixProperty bound -!unknown-field! ABPersonNameSuffixProperty bound -!unknown-field! ABPersonNicknameProperty bound -!unknown-field! ABPersonNoteProperty bound -!unknown-field! ABPersonOrganizationNameProperty bound -!unknown-field! ABPersonPhoneNumbersProperty bound -!unknown-field! ABPersonPhoneticFamilyNameProperty bound -!unknown-field! ABPersonPhoneticGivenNameProperty bound -!unknown-field! ABPersonPhoneticMiddleNameProperty bound -!unknown-field! ABPersonPostalAddressesProperty bound -!unknown-field! ABPersonPreviousFamilyNameProperty bound -!unknown-field! ABPersonRelatedNamesProperty bound -!unknown-field! ABPersonSocialProfilesProperty bound -!unknown-field! ABPersonUrlAddressesProperty bound -!unknown-pinvoke! ABCreateStringWithAddressDictionary bound -!unknown-protocol! ABNewPersonViewControllerDelegate bound -!unknown-protocol! ABPeoplePickerNavigationControllerDelegate bound -!unknown-protocol! ABPersonViewControllerDelegate bound -!unknown-protocol! ABUnknownPersonViewControllerDelegate bound -!unknown-type! ABNewPersonViewController bound -!unknown-type! ABPeoplePickerNavigationController bound -!unknown-type! ABPersonViewController bound -!unknown-type! ABUnknownPersonViewController bound