-
Notifications
You must be signed in to change notification settings - Fork 42
/
BlockLiteral.xml
295 lines (290 loc) · 13.3 KB
/
BlockLiteral.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<Type Name="BlockLiteral" FullName="ObjCRuntime.BlockLiteral">
<TypeSignature Language="C#" Value="public struct BlockLiteral" />
<TypeSignature Language="ILAsm" Value=".class public sequential ansi sealed beforefieldinit BlockLiteral extends System.ValueType" />
<TypeSignature Language="DocId" Value="T:ObjCRuntime.BlockLiteral" />
<TypeSignature Language="F#" Value="type BlockLiteral = struct" />
<AssemblyInfo>
<AssemblyName>Xamarin.iOS</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Base>
<BaseTypeName>System.ValueType</BaseTypeName>
</Base>
<Interfaces />
<Docs>
<summary>Wraps a ECMA CLI delegate (C# lambdas, anonymous methods or delegates) as an Objective-C block.</summary>
<remarks>
<para>
This is a low-level class that is automatically used by the Xamarin.iOS bindings when using Objective-C block APIs.
</para>
<para>
In the C#/ECMA CLI world delegates are automatically turned into blocks that can be consumed by Objective-C blocks-aware APIs.
</para>
<para>
If you need to P/Invoke a native C method that takes a block
parameter, you would need to manually setup the BlockLiteral
object and declare a proxy method that is invoked by the block
handler and will invoke your managed code.
</para>
<example>
<code lang="csharp lang-csharp"><![CDATA[
// Imagine that you want to invoke the following method:
// void SetupHandler (void (^block)(double offset, int count));
// Declare the signature of the method that users would have to provide
public delegate void SetupHandlerCallback (double offset, int count);
// Declare the signature of the method that the block will call
delegate void SetupHandlerCallbackProxy (IntPtr blockLiteral, double offset, int count);
// Static variable that points to our trampoline method
static readonly SetupHandlerCallback static_handler = TrampolineHandler;
// Our trampoline method must be registered for reverse-callback with Mono
// it takes one extra parameter than the signature, which is the pointer
// to the block that was originally passed.
[MonoPInvokeCallback (typeof (SetupHandlerCallbackProxy))]
static void TrampolineHandler (IntPtr block, double offset, int count)
{
// Find the delegate for the block and call it
var callback = BlockLiteral.GetTarget<SetupHandlerCallback> (block);
if (callback != null)
callback (offset, count);
}
[DllImport ("YourLibrary")]
static extern void SetupHandler (ref BlockLiteral block);
public void SetupHandler (SetupHandlerCallback callback)
{
if (callback == null)
throw new ArgumentNullException (nameof (callback));
BlockLiteral block = new BlockLiteral ();
block.SetupBlock (static_handler, callback);
try {
SetupHandler (ref block);
} finally {
block.CleanupBlock ();
}
}
]]></code>
</example>
</remarks>
</Docs>
<Members>
<Member MemberName="CleanupBlock">
<MemberSignature Language="C#" Value="public void CleanupBlock ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void CleanupBlock() cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.CleanupBlock" />
<MemberSignature Language="F#" Value="member this.CleanupBlock : unit -> unit" Usage="blockLiteral.CleanupBlock " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Releases the resources associated with this block.</summary>
<remarks>
<para>This releases the GCHandle that points to the user delegate.</para>
</remarks>
</Docs>
</Member>
<Member MemberName="GetDelegateForBlock<T>">
<MemberSignature Language="C#" Value="public T GetDelegateForBlock<T> () where T : class;" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance !!T GetDelegateForBlock<class T>() cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.GetDelegateForBlock``1" />
<MemberSignature Language="F#" Value="member this.GetDelegateForBlock : unit -> 'T (requires 'T : null)" Usage="blockLiteral.GetDelegateForBlock " />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<ParameterAttribute>ReferenceTypeConstraint</ParameterAttribute>
</Constraints>
</TypeParameter>
</TypeParameters>
<Parameters />
<Docs>
<typeparam name="T">Desired type to get, the delegate must be compatible with this type.</typeparam>
<summary>This method supports the Xamarin.iOS runtime and is not intended for use by application developers.</summary>
<returns>Returns a delegate of the given type that can be used to invoke the Objective-C block in the provided handle.</returns>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="GetTarget<T>">
<MemberSignature Language="C#" Value="public static T GetTarget<T> (IntPtr block) where T : class;" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig !!T GetTarget<class T>(native int block) cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.GetTarget``1(System.IntPtr)" />
<MemberSignature Language="F#" Value="static member GetTarget : nativeint -> 'T (requires 'T : null)" Usage="ObjCRuntime.BlockLiteral.GetTarget block" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyName>Xamarin.iOS</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>T</ReturnType>
</ReturnValue>
<TypeParameters>
<TypeParameter Name="T">
<Constraints>
<ParameterAttribute>ReferenceTypeConstraint</ParameterAttribute>
</Constraints>
</TypeParameter>
</TypeParameters>
<Parameters>
<Parameter Name="block" Type="System.IntPtr" />
</Parameters>
<Docs>
<typeparam name="T">The type of the managed delegate to return.</typeparam>
<param name="block">The pointer to the native block.</param>
<summary>If this block represents a managed delegate, this method will return that managed delegate.</summary>
<returns>The managed delegate for this block.</returns>
<remarks>
<para>Behavior is undefined if this block does not represent a managed delegate.</para>
</remarks>
</Docs>
</Member>
<Member MemberName="IsManagedBlock">
<MemberSignature Language="C#" Value="public static bool IsManagedBlock (IntPtr block);" />
<MemberSignature Language="ILAsm" Value=".method public static hidebysig bool IsManagedBlock(native int block) cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.IsManagedBlock(System.IntPtr)" />
<MemberSignature Language="F#" Value="static member IsManagedBlock : nativeint -> bool" Usage="ObjCRuntime.BlockLiteral.IsManagedBlock block" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="block" Type="System.IntPtr" />
</Parameters>
<Docs>
<param name="block">The pointer to the native block.</param>
<summary>This method determines whether a block is wrapping a managed delegate or if it's an Objective-C block.</summary>
<returns>Returns true if the specified block contains a managed delegate.</returns>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="SetupBlock">
<MemberSignature Language="C#" Value="public void SetupBlock (Delegate trampoline, Delegate userDelegate);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void SetupBlock(class System.Delegate trampoline, class System.Delegate userDelegate) cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.SetupBlock(System.Delegate,System.Delegate)" />
<MemberSignature Language="F#" Value="member this.SetupBlock : Delegate * Delegate -> unit" Usage="blockLiteral.SetupBlock (trampoline, userDelegate)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="trampoline" Type="System.Delegate" />
<Parameter Name="userDelegate" Type="System.Delegate" />
</Parameters>
<Docs>
<param name="trampoline">The trampoline must be a static delegate. Xamarin.iOS will automatically keep a reference to this delegate.</param>
<param name="userDelegate">The user code to invoke.</param>
<summary>Sets up a block using a trampoline and a user delegate.</summary>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="SetupBlockUnsafe">
<MemberSignature Language="C#" Value="public void SetupBlockUnsafe (Delegate trampoline, Delegate userDelegate);" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig instance void SetupBlockUnsafe(class System.Delegate trampoline, class System.Delegate userDelegate) cil managed" />
<MemberSignature Language="DocId" Value="M:ObjCRuntime.BlockLiteral.SetupBlockUnsafe(System.Delegate,System.Delegate)" />
<MemberSignature Language="F#" Value="member this.SetupBlockUnsafe : Delegate * Delegate -> unit" Usage="blockLiteral.SetupBlockUnsafe (trampoline, userDelegate)" />
<MemberType>Method</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute>
<AttributeName>System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters>
<Parameter Name="trampoline" Type="System.Delegate" />
<Parameter Name="userDelegate" Type="System.Delegate" />
</Parameters>
<Docs>
<param name="trampoline">The trampoline must be a static delegate. The developer's code must keep a reference to it.</param>
<param name="userDelegate">The user code to invoke.</param>
<summary>Sets up a block using a trampoline and a user delegate.</summary>
<remarks>
</remarks>
</Docs>
</Member>
<Member MemberName="Target">
<MemberSignature Language="C#" Value="public object Target { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance object Target" />
<MemberSignature Language="DocId" Value="P:ObjCRuntime.BlockLiteral.Target" />
<MemberSignature Language="F#" Value="member this.Target : obj" Usage="ObjCRuntime.BlockLiteral.Target" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
<AssemblyName>Xamarin.iOS</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>Xamarin.Mac</AssemblyName>
<AssemblyVersion>0.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Docs>
<summary>Returns the target object for the block.</summary>
<value>
</value>
<remarks>
</remarks>
</Docs>
</Member>
</Members>
</Type>