浏览代码

More modern native aot interface (#9994)

Co-authored-by: “llt” <“[email protected]”>
LLT21 1 周之前
父节点
当前提交
9816b9c949
共有 1 个文件被更改,包括 33 次插入49 次删除
  1. 33 49
      frameworks/CSharp/appmpower/src/appMpower/NativeMethods.cs

+ 33 - 49
frameworks/CSharp/appmpower/src/appMpower/NativeMethods.cs

@@ -1,62 +1,46 @@
 using System;
+using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
-public unsafe partial class NativeMethods
+public static partial class NativeMethods
 {
 #if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
+    private const string LibName = "appMpower.Orm.dylib";
 #else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern void Dbms(int dbms); 
+    private const string LibName = "appMpower.Orm.so";
+#endif
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern void DbProvider(int dbProvider); 
+    [LibraryImport(LibName, EntryPoint = "Dbms", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial void Dbms(int dbms);
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl)]
-#endif
-    public static extern void FreeHandlePointer(IntPtr handlePointer);
+    [LibraryImport(LibName, EntryPoint = "DbProvider", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial void DbProvider(int dbProvider);
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    //public static extern byte* Db(out int length); 
-    public static extern IntPtr Db(out int length, out IntPtr handlePointer); 
+    [LibraryImport(LibName, EntryPoint = "FreeHandlePointer")]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial void FreeHandlePointer(IntPtr handlePointer);
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern IntPtr Fortunes(out int length, out IntPtr handlePointer); 
+    [LibraryImport(LibName, EntryPoint = "Db", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial IntPtr Db(out int length, out IntPtr handlePointer);
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern IntPtr Query(int queries, out int length, out IntPtr handlePointer); 
+    [LibraryImport(LibName, EntryPoint = "Fortunes", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern IntPtr Updates(int queries, out int length, out IntPtr handlePointer); 
+    public static partial IntPtr Fortunes(out int length, out IntPtr handlePointer);
 
-#if DEBUG
-    [DllImport("appMpower.Orm.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#else
-    [DllImport("appMpower.Orm.so", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
-#endif   
-    public static extern IntPtr DbById(int id, out int length, out IntPtr handlePointer); 
-}
+    [LibraryImport(LibName, EntryPoint = "Query", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial IntPtr Query(int queries, out int length, out IntPtr handlePointer);
+
+    [LibraryImport(LibName, EntryPoint = "Updates", StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial IntPtr Updates(int queries, out int length, out IntPtr handlePointer);
+
+    [LibraryImport(LibName, StringMarshalling = StringMarshalling.Utf16)]
+    [UnmanagedCallConv(CallConvs = new[] { typeof(CallConvCdecl) })]
+    public static partial IntPtr DbById(int id, out int length, out IntPtr handlePointer);
+
+}