为了对提供给我们的 dll 进行更改,我使用了 IAspectProvider 接口并满足其所需的 ProvideAspects 方法。作为
public class TraceAspectProvider : IAspectProvider {
readonly SomeTracingAspect aspectToApply = new SomeTracingAspect();
public IEnumerable ProvideAspects(object targetElement) {
Assembly assembly = (Assembly)targetElement;
List instances = new List();
foreach (Type type in assembly.GetTypes()) {
ProcessType(type, instances);
}
return instances;
}
void ProcessType(Type type, List instances) {
foreach (MethodInfo targetMethod in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) {
instances.Add(new AspectInstance(targetMethod, aspectToApply));
}
foreach (Type nestedType in type.GetNestedTypes()) {
ProcessType(nestedType, instances);
}
}
}
运行此程序时,我收到这些错误
等待您的宝贵意见