[CoreFoundation] Add Clone method for CFArray. (#7403)

When working on https://github.com/xamarin/maccore/issues/940 we noticed
that clone the array would be a better approach.

The CFArrayCreateCopy add some nice things:

* The pointer values from theArray are copied into the new array.
* The values are also retained by the new array.
* The count of the new array is the same as theArray
* The new array uses the same callbacks as theArray. [IMPORTANT]

Whith this in, we can have a better fix for https://github.com/xamarin/maccore/issues/940
This commit is contained in:
Manuel de la Pena 2019-11-13 06:06:23 -05:00 коммит произвёл GitHub
Родитель 8a63932245
Коммит f613021a3f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 7 добавлений и 1 удалений

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

@ -35,6 +35,8 @@ using Foundation;
using ObjCRuntime; using ObjCRuntime;
using CFIndex = System.nint; using CFIndex = System.nint;
using CFArrayRef = System.IntPtr;
using CFAllocatorRef = System.IntPtr;
namespace CoreFoundation { namespace CoreFoundation {
@ -149,6 +151,11 @@ namespace CoreFoundation {
{ {
return CFArrayGetCount (array); return CFArrayGetCount (array);
} }
[DllImport (Constants.CoreFoundationLibrary)]
extern static CFArrayRef CFArrayCreateCopy (CFAllocatorRef allocator, CFArrayRef theArray);
public CFArray Clone () => new CFArray (CFArrayCreateCopy (IntPtr.Zero, this.Handle), true);
} }
} }

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

@ -334,7 +334,6 @@
!missing-pinvoke! CFArrayApplyFunction is not bound !missing-pinvoke! CFArrayApplyFunction is not bound
!missing-pinvoke! CFArrayBSearchValues is not bound !missing-pinvoke! CFArrayBSearchValues is not bound
!missing-pinvoke! CFArrayContainsValue is not bound !missing-pinvoke! CFArrayContainsValue is not bound
!missing-pinvoke! CFArrayCreateCopy is not bound
!missing-pinvoke! CFArrayCreateMutable is not bound !missing-pinvoke! CFArrayCreateMutable is not bound
!missing-pinvoke! CFArrayCreateMutableCopy is not bound !missing-pinvoke! CFArrayCreateMutableCopy is not bound
!missing-pinvoke! CFArrayExchangeValuesAtIndices is not bound !missing-pinvoke! CFArrayExchangeValuesAtIndices is not bound