This repository was archived by the owner on Feb 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinder.cs
More file actions
53 lines (47 loc) · 1.52 KB
/
Copy pathBinder.cs
File metadata and controls
53 lines (47 loc) · 1.52 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
global using System;
global using SoupExt;
using System.Linq;
using System.Reflection;
using BepInEx.Configuration;
using cfile = BepInEx.Configuration.ConfigFile;
using cdefi = BepInEx.Configuration.ConfigDefinition;
using cdesc = BepInEx.Configuration.ConfigDescription;
namespace HFF_BoxedConfigHelper;
public static class Binder {
private static readonly Lazy<MethodInfo> _binder = new(() =>
typeof(cfile)
.GetMethods(BindingFlags.Public | BindingFlags.Instance)
.ToList()
.Where(m => m.Name == "Bind")
.FirstOrDefault(m =>
m.GetParameters()
.Select(p => p.ParameterType)
.ToArray()
.IsWhen(a => a.Length == 3, out Type[] a) &&
a[0] == typeof(cdefi) &&
a[2] == typeof(cdesc)
)
);
public static ConfigEntryBase TBind(
this cfile file,
cdefi def,
object val,
cdesc desc = null
) => _binder.Value?
.MakeGenericMethod(val.GetType())
.Invoke(file, new[] { def, val, desc }) as ConfigEntryBase;
public static ConfigEntryBase TBind(
this cfile file,
string sec,
string key,
object val,
cdesc desc = null
) => file.TBind(new(sec, key), val, desc);
public static ConfigEntryBase TBind(
this cfile file,
string sec,
string key,
object val,
string desc
) => file.TBind(new(sec, key), val, new(desc, null));
}