|
| 1 | +#nullable enable |
1 | 2 | using System.Reflection;
|
2 | 3 | using HarmonyLib;
|
3 | 4 | using Il2CppInterop.Runtime.Injection;
|
4 | 5 |
|
5 |
| -namespace NextShip.Api.Utilities.Attributes; |
| 6 | +namespace NextShip.Api.Attributes; |
6 | 7 |
|
7 | 8 | [AttributeUsage(AttributeTargets.Class)]
|
8 |
| -public sealed class Il2CppRegisterAttribute : Attribute |
| 9 | +public sealed class Il2CppRegisterAttribute(params Type[] interfaces) : Attribute |
9 | 10 | {
|
10 |
| - public Il2CppRegisterAttribute(params Type[] interfaces) |
| 11 | + public Il2CppRegisterAttribute() : this(Type.EmptyTypes) |
11 | 12 | {
|
12 |
| - Interfaces = interfaces; |
13 | 13 | }
|
14 | 14 |
|
15 |
| - public Il2CppRegisterAttribute() |
16 |
| - { |
17 |
| - Interfaces = Type.EmptyTypes; |
18 |
| - } |
19 | 15 |
|
20 |
| - public Type[] Interfaces { get; } |
| 16 | + public Type[] Interfaces { get; } = interfaces; |
21 | 17 |
|
22 |
| - public static void Registration(Type type) |
| 18 | + public static void Registration(Type? type) |
23 | 19 | {
|
24 | 20 | Info("Start Registration", "Il2CppRegister");
|
25 | 21 |
|
26 | 22 | var attribute =
|
27 |
| - type.GetCustomAttribute<Il2CppRegisterAttribute>(); |
| 23 | + type?.GetCustomAttribute<Il2CppRegisterAttribute>(); |
| 24 | + |
28 | 25 | if (attribute != null) registrationForTarget(type, attribute.Interfaces);
|
29 | 26 |
|
30 | 27 | Info("Complete Registration", "Il2CppRegister");
|
31 | 28 | }
|
32 | 29 |
|
33 |
| - private static void registrationForTarget(Type targetType, Type[] interfaces) |
| 30 | + private static void registrationForTarget(Type? targetType, Type[] interfaces) |
34 | 31 | {
|
35 |
| - var targetBase = targetType.BaseType; |
| 32 | + var targetBase = targetType?.BaseType; |
36 | 33 |
|
37 |
| - Il2CppRegisterAttribute baseAttribute = null; |
| 34 | + Il2CppRegisterAttribute? baseAttribute = null; |
38 | 35 |
|
39 |
| - if (targetBase != null) baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>(); |
| 36 | + if (targetBase != null) |
| 37 | + baseAttribute = targetBase.GetCustomAttribute<Il2CppRegisterAttribute>(); |
40 | 38 |
|
41 |
| - if (baseAttribute != null) registrationForTarget(targetBase, baseAttribute.Interfaces); |
| 39 | + if (baseAttribute != null) |
| 40 | + registrationForTarget(targetBase, baseAttribute.Interfaces); |
42 | 41 |
|
43 | 42 | Debug($"Registration {targetType}", "Register");
|
44 | 43 |
|
|
0 commit comments