This repository was archived by the owner on Jul 22, 2023. It is now read-only.
forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibPythonPInvoke_.tt
More file actions
41 lines (35 loc) · 1.43 KB
/
LibPythonPInvoke_.tt
File metadata and controls
41 lines (35 loc) · 1.43 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
<#@ template hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Linq" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
using Python.Runtime.Interfaces;
namespace Python.Runtime.Native {
public partial class LibPythonPInvoke {
<#
string FormatType(Type type) {
if (type == typeof(void))
return "void";
if (type.IsByRef)
return $"ref {type.GetElementType().ToString()}";
return type.ToString();
}
var path = $"{Directory.GetCurrentDirectory()}/Python.Runtime.Interfaces/bin/Debug/netstandard2.0/Python.Runtime.Interfaces.dll";
var assembly = Assembly.LoadFile(path);
var type = assembly.GetType("Python.Runtime.Interfaces.ILibPython");
const BindingFlags flags = BindingFlags.Public | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
var methods = type.GetMethods(flags);
foreach (var method in methods) {
#>
<#= FormatType(method.ReturnParameter.ParameterType) #> ILibPython.<#= method.Name #>(<#=
string.Join(", ", method.GetParameters().Select(x => $"{FormatType(x.ParameterType)} {x.Name}"))
#>) => LibPythonPInvoke.<#= method.Name #>(<#=
string.Join(", ", method.GetParameters().Select(x => (x.ParameterType.IsByRef ? "ref " : "") + x.Name))
#>);
<#
}
#>
}
}