Survivalcraft API 1.8.2.3
v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
Utilities.cs
浏览该文件的文档.
1
using
System.Runtime.InteropServices;
2
3
namespace
Engine
{
4
public
static
class
Utilities
{
5
public
static
void
Swap<T>
(ref T a, ref T b) {
6
(b, a) = (a, b);
7
}
8
9
public
static
int
SizeOf<T>
() where T : unmanaged => Marshal.SizeOf<T>();
10
11
public static
unsafe
T PtrToStructure<T>(
void
* ptr) where T : unmanaged => *(T*)ptr;
12
13
public static
unsafe
T ArrayToStructure<T>(Array array) where T : unmanaged {
14
GCHandle gCHandle = GCHandle.Alloc(array, GCHandleType.Pinned);
15
try
{
16
return PtrToStructure<T>(gCHandle.AddrOfPinnedObject().ToPointer());
17
}
18
finally
{
19
gCHandle.Free();
20
}
21
}
22
23
public
static
byte
[]
StructureToArray<T>
(T structure) where T : unmanaged {
24
byte
[] array =
new
byte
[
SizeOf<T>
()];
25
GCHandle gCHandle = GCHandle.Alloc(structure, GCHandleType.Pinned);
26
try
{
27
Marshal.Copy(gCHandle.AddrOfPinnedObject(), array, 0, array.Length);
28
return
array;
29
}
30
finally
{
31
gCHandle.Free();
32
}
33
}
34
35
public
static
void
Dispose<T>
(ref T disposable) where T : IDisposable {
36
if
(disposable !=
null
) {
37
disposable.Dispose();
38
disposable =
default
;
39
}
40
}
41
42
public
static
void
DisposeCollection<T>
(ICollection<T> disposableCollection) where T : IDisposable {
43
if
(disposableCollection !=
null
) {
44
foreach
(T item
in
disposableCollection) {
45
item?.Dispose();
46
}
47
if
(!disposableCollection.IsReadOnly) {
48
disposableCollection.Clear();
49
}
50
}
51
}
52
}
53
}
unsafe
unsafe
定义
Main.cs:15
Engine.Utilities
定义
Utilities.cs:4
Engine.Utilities.Swap< T >
static void Swap< T >(ref T a, ref T b)
定义
Utilities.cs:5
Engine.Utilities.SizeOf< T >
static int SizeOf< T >()
定义
Utilities.cs:9
Engine.Utilities.DisposeCollection< T >
static void DisposeCollection< T >(ICollection< T > disposableCollection)
定义
Utilities.cs:42
Engine.Utilities.StructureToArray< T >
static byte[] StructureToArray< T >(T structure)
定义
Utilities.cs:23
Engine.Utilities.Dispose< T >
static void Dispose< T >(ref T disposable)
定义
Utilities.cs:35
Engine
定义
BaseSound.cs:10
SurvivalcraftApi 1.8.2.3
Engine
Engine
Utilities.cs
制作者
1.16.1