forked from loongly/PureScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectStore.cs
More file actions
35 lines (28 loc) · 823 Bytes
/
Copy pathObjectStore.cs
File metadata and controls
35 lines (28 loc) · 823 Bytes
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
//#define WRAPPER_SIDE
using AOT;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
internal static class ObjectStore
{
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern object GetObject(IntPtr ptr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IntPtr GetObjectPtr(object obj);
public static IntPtr Store(object obj)
{
if (obj == null)
return IntPtr.Zero;
return GetObjectPtr(obj);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Get<T>(IntPtr handle) where T : class
{
if (handle == IntPtr.Zero)
return null;
var obj = GetObject(handle);
return obj as T;
}
}