-
Notifications
You must be signed in to change notification settings - Fork 528
/
ResourceIdManager.cs
46 lines (43 loc) · 1.23 KB
/
ResourceIdManager.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
using System;
using System.Reflection;
namespace Android.Runtime
{
public static class ResourceIdManager
{
static bool id_initialized;
public static void UpdateIdValues ()
{
if (id_initialized)
return;
id_initialized = true;
var executingAssembly = Assembly.GetExecutingAssembly ();
var type = executingAssembly != null ? GetResourceTypeFromAssembly (executingAssembly) : null;
if (type == null) {
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies ()) {
type = GetResourceTypeFromAssembly (assembly);
if (type != null) {
break;
}
}
}
if (type != null) {
var method = type.GetMethod ("UpdateIdValues");
if (method != null) {
var action = (Action) method.CreateDelegate (typeof (Action));
action ();
}
}
}
static Type? GetResourceTypeFromAssembly (Assembly assembly)
{
foreach (var customAttribute in assembly.GetCustomAttributes (typeof (ResourceDesignerAttribute), true)) {
if (customAttribute is ResourceDesignerAttribute resourceDesignerAttribute && resourceDesignerAttribute.IsApplication) {
var type = assembly.GetType (resourceDesignerAttribute.FullName);
if (type != null)
return type;
}
}
return null;
}
}
}