-
Notifications
You must be signed in to change notification settings - Fork 564
Expand file tree
/
Copy pathDelegates.cs.t4
More file actions
107 lines (98 loc) · 2.93 KB
/
Delegates.cs.t4
File metadata and controls
107 lines (98 loc) · 2.93 KB
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
// vim: set filetype=c :
//
// Delegates.generated.cs:
//
// Authors:
// Rolf Bjarne Kvinge <rolf@xamarin.com>
//
// Copyright 2013-2014 Xamarin Inc.
//
/*
* This file was generated from Delegates.cs.t4, any modifications will be lost once this file is re-generated.
*/
<#@ include file="delegates.t4" #>
#if !COREBUILD
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using Foundation;
using Registrar;
namespace ObjCRuntime {
public unsafe partial class Runtime {
internal struct Delegates {
<# foreach (var d in delegates) { #>
public IntPtr <#= d.SimpleEntryPoint #>;
<# } #>
}
<# foreach (var d in delegates) { #>
[UnmanagedCallersOnly]
static unsafe <#= d.ReturnType.MType #> <#= d.SimpleEntryPoint #> (<#= d.MArgumentSignature #>)
<# if (d.ExceptionHandling) { #>
{
*exception_gchandle = IntPtr.Zero;
try {
<# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #>
throw new NotImplementedException ();
<# } else { #>
<# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>);
<# } #>
} catch (Exception ex) {
var handle = GCHandle.Alloc (ex, GCHandleType.Normal);
*exception_gchandle = GCHandle.ToIntPtr (handle);
<# if (d.SimpleEntryPoint == "get_nsobject_with_type") { #> *created = 0;
<# } #>
<# if (d.ReturnType.MType != "void") { #> return default (<#= d.ReturnType.MType #>);
<# } #>
}
}
<# } else { #>
{
<# if (string.IsNullOrEmpty (d.WrappedManagedFunction)) { #>
throw new NotImplementedException ();
<# } else { #>
<# if (d.ReturnType.MType != "void") { #>return <# } #><#=d.WrappedManagedFunction#> (<#=d.MArgumentNames#>);
<# } #>
}
<# } #>
<# } #>
[BindingImpl (BindingImplOptions.Optimizable)] // To inline the Runtime.DynamicRegistrationSupported code if possible.
unsafe static void RegisterDelegates (InitializationOptions* options)
{
<# foreach (var d in delegates.NotOnlyDynamic) { #>
<#
if (d.OnlyCoreCLR) {
Write ("\t\t\tif (IsCoreCLR) {\n\t");
}
if (d.SkipManagedStaticRegistrar) {
Write ("\t\t\tif (!Runtime.IsManagedStaticRegistrar && !Runtime.IsTrimmableStaticRegistrar) {\n\t");
}
#>
options->Delegates-><#= d.SimpleEntryPoint #> = (IntPtr) (void *) <#= d.UnmanagedDelegateCast #> &<#= d.SimpleEntryPoint #>;
<#
if (d.OnlyCoreCLR) {
WriteLine ("\t\t\t}");
}
if (d.SkipManagedStaticRegistrar) {
WriteLine ("\t\t\t}");
}
#>
<# } #>
// The linker will remove this condition (and the subsequent method call) if possible
if (DynamicRegistrationSupported)
RegisterDelegatesDynamic (options);
}
static void RegisterDelegatesDynamic (InitializationOptions* options)
{
<# foreach (var d in delegates.OnlyDynamic) { #>
<#
if (d.OnlyCoreCLR) {
Write ("\t\t\tif (IsCoreCLR)\n\t");
}
#>
options->Delegates-><#= d.SimpleEntryPoint #> = (IntPtr) (void *) <#= d.UnmanagedDelegateCast #> &<#= d.SimpleEntryPoint #>;
<# } #>
}
}
}
#endif