forked from MasterScott/DevTree
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExtensions.cs
More file actions
63 lines (55 loc) · 1.8 KB
/
Extensions.cs
File metadata and controls
63 lines (55 loc) · 1.8 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using ExileCore.PoEMemory;
namespace DevTree;
public static class Extensions
{
public static IEnumerable<PropertyInfo> GetAllProperties(this Type type)
{
return type
.GetTypeChain()
.SelectMany(x => x.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
.DistinctBy(x => (x.Name, x.DeclaringType));
}
public static IEnumerable<MethodInfo> GetAllMethods(this Type type)
{
return type
.GetTypeChain()
.SelectMany(x => x.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
.DistinctBy(x => (x.Name, string.Join(";", x.GetParameters().Select(t => t.ParameterType.AssemblyQualifiedName)), x.DeclaringType));
}
public static IEnumerable<Type> GetTypeChain(this Type type)
{
while (type != null)
{
yield return type;
type = type.BaseType;
}
}
public static string ToHexString(this int value)
{
return $"0x{value:X}";
}
public static void Resize<T>(this List<T> list, int newSize, T defaultElement = default)
{
var oldSize = list.Count;
if (newSize < oldSize)
{
list.RemoveRange(newSize, oldSize - newSize);
}
else if (newSize > oldSize)
{
if (newSize > list.Capacity)
{
list.Capacity = newSize;
}
list.AddRange(Enumerable.Repeat(defaultElement, newSize - oldSize));
}
}
public static long GetAddress(this RemoteMemoryObject rmo, bool hide)
{
return hide ? 0xDEADBEEF : rmo.Address;
}
}