-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathModuleScriptMethodIndexer.cs
More file actions
34 lines (32 loc) · 1.3 KB
/
ModuleScriptMethodIndexer.cs
File metadata and controls
34 lines (32 loc) · 1.3 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
using System;
using System.Collections.Generic;
using System.Reflection;
namespace AltV.Net.FunctionParser
{
public static class ModuleScriptMethodIndexer
{
public static void Index(object target, Type[] customAttributes, Action<object, MethodInfo, Delegate> found)
{
var eventMethods = target.GetType().GetMethods();
var attributeMethods = new LinkedList<(MethodInfo, object[])>();
for (int i = 0, length = eventMethods.Length; i < length; i++)
{
var m = eventMethods[i];
for (int j = 0, attributesLength = customAttributes.Length; j < attributesLength; j++)
{
var customAttribute = customAttributes[j];
var methodCustomAttributes = m.GetCustomAttributes(customAttribute, false);
if (methodCustomAttributes.Length <= 0) continue;
attributeMethods.AddFirst((m, methodCustomAttributes));
}
}
foreach (var (eventMethod, eventAttributes) in attributeMethods)
{
foreach (var eventAttribute in eventAttributes)
{
found(eventAttribute, eventMethod, eventMethod.CreateDelegate(target));
}
}
}
}
}