MCPcopy Create free account
hub / github.com/crazytuzi/UnrealCSharp / ArrayBridge

Class ArrayBridge

Script/Interop/Bridge/ArrayBridge.cs:6–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4namespace Interop;
5
6public static unsafe class ArrayBridge
7{
8 [UnmanagedCallersOnly]
9 public static nint NewArray(byte* InFullName, int InLength)
10 {
11 if (InFullName != null && InLength > 0)
12 {
13 var FullName = Marshal.PtrToStringUTF8((nint)InFullName)!;
14
15 var Type = TypeBridge.GetTypeImplementation(FullName);
16
17 if (Type != null)
18 {
19 var Handle = GCHandle.Alloc(Array.CreateInstance(Type, InLength), GCHandleType.Pinned);
20
21 return HandleData.AddEntity(Handle);
22 }
23 }
24
25 return 0;
26 }
27
28 [UnmanagedCallersOnly]
29 public static nint ArrayGet(nint InHandle, int InIndex)
30 {
31 var Handle = HandleData.GetHandle(InHandle);
32
33 if (Handle is { IsAllocated: true, Target: Array Array })
34 {
35 if (InIndex < Array.Length)
36 {
37 var Type = Array.GetType().GetElementType()!;
38
39 var Size = Type.IsValueType ? Marshal.SizeOf(Type) : sizeof(nint);
40
41 return Handle.AddrOfPinnedObject() + InIndex * Size;
42 }
43 }
44
45 return 0;
46 }
47
48 [UnmanagedCallersOnly]
49 public static nint ArrayGetRef(nint InHandle, int InIndex)
50 {
51 if (HandleData.GetHandle(InHandle) is { IsAllocated: true, Target: Array Array })
52 {
53 if (InIndex < Array.Length)
54 {
55 var Value = Array.GetValue(InIndex);
56
57 if (Value != null)
58 {
59 return HandleData.AllocImplementation(Value);
60 }
61 }
62 }
63

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected