forked from VictorPhilipp/RedirectionFramework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssemblyRedirector.cs
38 lines (31 loc) · 1.02 KB
/
AssemblyRedirector.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
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using CSUtil.Commons;
using TrafficManager.RedirectionFramework.Attributes;
using TrafficManager.RedirectionFramework.Extensions;
namespace TrafficManager.RedirectionFramework {
public class AssemblyRedirector {
private static Type[] _types;
public static IDictionary<MethodInfo, RedirectCallsState> Deploy() {
IDictionary<MethodInfo, RedirectCallsState> ret = new Dictionary<MethodInfo, RedirectCallsState>();
_types = Assembly.GetExecutingAssembly().GetTypes().Where(t => t.GetCustomAttributes(typeof(TargetTypeAttribute), false).Length > 0).ToArray();
Log.Info($"Found {_types.Count()} types for redirection.");
foreach (var type in _types) {
Log.Info($"Processing redirectes in type {type.FullName}.");
ret.AddRange(type.Redirect());
}
return ret;
}
public static void Revert() {
if (_types == null) {
return;
}
foreach (var type in _types) {
type.Revert();
}
_types = null;
}
}
}