/
Patches.cs
62 lines (55 loc) · 1.95 KB
/
Patches.cs
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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
namespace HarmonyLib
{
/// <summary>A group of patches</summary>
///
public class Patches
{
/// <summary>A collection of prefix <see cref="Patch"/></summary>
///
public readonly ReadOnlyCollection<Patch> Prefixes;
/// <summary>A collection of postfix <see cref="Patch"/></summary>
///
public readonly ReadOnlyCollection<Patch> Postfixes;
/// <summary>A collection of transpiler <see cref="Patch"/></summary>
///
public readonly ReadOnlyCollection<Patch> Transpilers;
/// <summary>A collection of finalizer <see cref="Patch"/></summary>
///
public readonly ReadOnlyCollection<Patch> Finalizers;
/// <summary>Gets all owners (Harmony IDs) or all known patches</summary>
/// <value>The patch owners</value>
///
public ReadOnlyCollection<string> Owners
{
get
{
var result = new HashSet<string>();
result.UnionWith(Prefixes.Select(p => p.owner));
result.UnionWith(Postfixes.Select(p => p.owner));
result.UnionWith(Transpilers.Select(p => p.owner));
result.UnionWith(Finalizers.Select(p => p.owner));
return result.ToList().AsReadOnly();
}
}
/// <summary>Creates a group of patches</summary>
/// <param name="prefixes">An array of prefixes as <see cref="Patch"/></param>
/// <param name="postfixes">An array of postfixes as <see cref="Patch"/></param>
/// <param name="transpilers">An array of transpileres as <see cref="Patch"/></param>
/// <param name="finalizers">An array of finalizeres as <see cref="Patch"/></param>
///
public Patches(Patch[] prefixes, Patch[] postfixes, Patch[] transpilers, Patch[] finalizers)
{
prefixes ??= [];
postfixes ??= [];
transpilers ??= [];
finalizers ??= [];
Prefixes = prefixes.ToList().AsReadOnly();
Postfixes = postfixes.ToList().AsReadOnly();
Transpilers = transpilers.ToList().AsReadOnly();
Finalizers = finalizers.ToList().AsReadOnly();
}
}
}