-
Notifications
You must be signed in to change notification settings - Fork 565
Expand file tree
/
Copy pathAssemblyModifierStep.cs
More file actions
63 lines (49 loc) · 1.26 KB
/
AssemblyModifierStep.cs
File metadata and controls
63 lines (49 loc) · 1.26 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.Linq;
using Mono.Cecil;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Tuner;
using Xamarin.Bundler;
using Xamarin.Linker;
#nullable enable
namespace Xamarin.Linker.Steps;
public abstract class AssemblyModifierStep : ConfigurationAwareStep {
private protected AppBundleRewriter abr => Configuration.AppBundleRewriter;
protected override void TryProcessAssembly (AssemblyDefinition assembly)
{
var modified = false;
abr.SetCurrentAssembly (assembly);
foreach (var type in assembly.MainModule.Types)
modified |= ProcessTypeImpl (type);
if (modified)
abr.SaveCurrentAssembly ();
abr.ClearCurrentAssembly ();
}
protected virtual bool ProcessType (TypeDefinition type)
{
return false;
}
protected virtual bool ProcessMethod (MethodDefinition method)
{
return false;
}
bool ProcessTypeImpl (TypeDefinition type)
{
var modified = ProcessType (type);
if (type.HasNestedTypes) {
foreach (var nested in type.NestedTypes)
modified |= ProcessTypeImpl (nested);
}
return modified;
}
protected bool ProcessMethods (TypeDefinition type)
{
if (!type.HasMethods)
return false;
var modified = false;
foreach (var method in type.Methods)
modified |= ProcessMethod (method);
return modified;
}
}