[xcode13] Add Foundation from Xcode 13.0 · dotnet/macios@b945c2d (original) (raw)

`@@ -7,6 +7,8 @@

`

7

7

`// Copyright 2015, Xamarin Inc.

`

8

8

`//

`

9

9

``

``

10

`+

#nullable enable

`

``

11

+

10

12

`using System;

`

11

13

`using System.Collections.Generic;

`

12

14

`using System.Collections;

`

`@@ -20,6 +22,9 @@

`

20

22

`#endif

`

21

23

``

22

24

`namespace Foundation {

`

``

25

`+

public delegate bool NSOrderedCollectionDifferenceEquivalenceTest (TValue? first, TValue? second);

`

``

26

`+

internal delegate bool NSOrderedCollectionDifferenceEquivalenceTestProxy (IntPtr blockLiteral, /* NSObject / IntPtr first, / NSObject */ IntPtr second);

`

``

27

+

23

28

`#if NET

`

24

29

`[SupportedOSPlatform ("ios")]

`

25

30

`[SupportedOSPlatform ("maccatalyst")]

`

`@@ -42,15 +47,15 @@ internal NSArray (NativeHandle handle) : base (handle)

`

42

47

`{

`

43

48

`}

`

44

49

``

45

``

`-

static public NSArray FromNSObjects (params TKey [] items)

`

``

50

`+

static public NSArray? FromNSObjects (params TKey [] items)

`

46

51

`{

`

47

``

`-

if (items == null)

`

``

52

`+

if (items is null)

`

48

53

`throw new ArgumentNullException (nameof (items));

`

49

54

``

50

55

`return FromNSObjects (items.Length, items);

`

51

56

`}

`

52

57

``

53

``

`-

static public NSArray FromNSObjects (int count, params TKey [] items)

`

``

58

`+

static public NSArray? FromNSObjects (int count, params TKey [] items)

`

54

59

`{

`

55

60

`if (items == null)

`

56

61

`throw new ArgumentNullException (nameof (items));

`

`@@ -65,7 +70,7 @@ static public NSArray FromNSObjects (int count, params TKey [] items)

`

65

70

`Marshal.WriteIntPtr (buf, (int)(i * IntPtr.Size), h);

`

66

71

`}

`

67

72

`IntPtr ret = NSArray.FromObjects (buf, count);

`

68

``

`-

NSArray arr = Runtime.GetNSObject<NSArray> (ret);

`

``

73

`+

var arr = Runtime.GetNSObject<NSArray> (ret);

`

69

74

`Marshal.FreeHGlobal (buf);

`

70

75

`return arr;

`

71

76

`}

`

`@@ -89,5 +94,62 @@ public TKey this [nint idx] {

`

89

94

`return GetItem ((nuint)idx);

`

90

95

`}

`

91

96

`}

`

``

97

+

``

98

`+

#if !NET

`

``

99

`+

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]

`

``

100

`+

#else

`

``

101

`+

[SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos10.15")]

`

``

102

`+

#endif

`

``

103

`+

public NSOrderedCollectionDifference? GetDifference (TKey[] other, NSOrderedCollectionDifferenceCalculationOptions options)

`

``

104

`+

=> Runtime.GetNSObject <NSOrderedCollectionDifference> (_GetDifference (NSArray.FromNSObjects (other), options));

`

``

105

+

``

106

`+

#if !NET

`

``

107

`+

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]

`

``

108

`+

#else

`

``

109

`+

[SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos10.15")]

`

``

110

`+

#endif

`

``

111

`+

public NSOrderedCollectionDifference? GetDifference (TKey[] other)

`

``

112

`+

=> Runtime.GetNSObject <NSOrderedCollectionDifference> (_GetDifference (NSArray.FromNSObjects (other)));

`

``

113

+

``

114

`+

#if !NET

`

``

115

`+

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]

`

``

116

`+

#else

`

``

117

`+

[SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos10.15")]

`

``

118

`+

#endif

`

``

119

`+

public TKey[]? GetArrayByApplyingDifference (NSOrderedCollectionDifference difference)

`

``

120

`+

=> NSArray.ArrayFromHandle (_GetArrayByApplyingDifference (difference));

`

``

121

`+

static readonly NSOrderedCollectionDifferenceEquivalenceTestProxy static_DiffEqualityGeneric = DiffEqualityHandlerGeneric;

`

``

122

+

``

123

`+

[MonoPInvokeCallback (typeof (NSOrderedCollectionDifferenceEquivalenceTestProxy))]

`

``

124

`+

static bool DiffEqualityHandlerGeneric (IntPtr block, IntPtr first, IntPtr second)

`

``

125

`+

{

`

``

126

`+

var callback = BlockLiteral.GetTarget<NSOrderedCollectionDifferenceEquivalenceTest> (block);

`

``

127

`+

if (callback is not null) {

`

``

128

`+

var nsFirst = Runtime.GetINativeObject (first, false);

`

``

129

`+

var nsSecond = Runtime.GetINativeObject (second, false);

`

``

130

`+

return callback (nsFirst, nsSecond);

`

``

131

`+

}

`

``

132

`+

return false;

`

``

133

`+

}

`

``

134

+

``

135

`+

#if !NET

`

``

136

`+

[Watch (6,0), TV (13,0), Mac (10,15), iOS (13,0)]

`

``

137

`+

#else

`

``

138

`+

[SupportedOSPlatform ("ios13.0"), SupportedOSPlatform ("tvos13.0"), SupportedOSPlatform ("macos10.15")]

`

``

139

`+

#endif

`

``

140

`+

public NSOrderedCollectionDifference? GetDifferenceFromArray (NSArray other, NSOrderedCollectionDifferenceCalculationOptions options, NSOrderedCollectionDifferenceEquivalenceTest equivalenceTest)

`

``

141

`+

{

`

``

142

`+

if (equivalenceTest is null)

`

``

143

`+

throw new ArgumentNullException (nameof (equivalenceTest));

`

``

144

+

``

145

`+

var block = new BlockLiteral ();

`

``

146

`+

block.SetupBlock (static_DiffEqualityGeneric, equivalenceTest);

`

``

147

`+

try {

`

``

148

`+

return Runtime.GetNSObject<NSOrderedCollectionDifference> (_GetDifferenceFromArray (other, options, ref block));

`

``

149

`+

} finally {

`

``

150

`+

block.CleanupBlock ();

`

``

151

`+

}

`

``

152

`+

}

`

``

153

+

92

154

`}

`

93

155

`}

`