PostSharp:方法 *** 应该使用选择器自定义属性进行注释,因为它是主处理程序
PostSharp: Method *** should be annotated with a selector custom attribute because it is a master handler
此代码抛出错误:Method ...OnEntry(...) should be annotated with a selector custom attribute because it is a master handler
。
[PSerializable]
public class LogRequestAttribute : MethodLevelAspect, IAspectProvider {
public IEnumerable<AspectInstance> ProvideAspects(object target) {
yield return new AspectInstance( target, new LogPlainRequest() );
}
}
[PSerializable]
public class LogPlainRequest : IMethodLevelAspect {
public void RuntimeInitialize(MethodBase method) {
}
[OnMethodEntryAdvice]
public void OnEntry(MethodExecutionArgs args) {
}
}
错误是什么意思?怎么了?
您可以将几个相关的建议合并为一组(例如 OnEntry
、OnExit
)。这是 OnMethodBoundaryAspect 自动为您做的。在对建议进行分组后,您需要将其中之一指定为 "master advice"。 group的属性和pointcut必须在master advice上设置
分配给主建议的切入点充当建议目标元素的选择器。例如,SelfPointcut 只是简单地选择方面的目标作为建议的目标。您可以在文档中找到更多信息和不同的切入点类型:
https://doc.postsharp.net/advices
在上面的示例中,您可以将 [SelfPointcut]
属性应用于 OnEntry
方法以消除错误消息。
[PSerializable]
public class LogPlainRequest : IMethodLevelAspect {
public void RuntimeInitialize(MethodBase method) {
}
[OnMethodEntryAdvice]
[SelfPointcut]
public void OnEntry(MethodExecutionArgs args) {
}
}
此代码抛出错误:Method ...OnEntry(...) should be annotated with a selector custom attribute because it is a master handler
。
[PSerializable]
public class LogRequestAttribute : MethodLevelAspect, IAspectProvider {
public IEnumerable<AspectInstance> ProvideAspects(object target) {
yield return new AspectInstance( target, new LogPlainRequest() );
}
}
[PSerializable]
public class LogPlainRequest : IMethodLevelAspect {
public void RuntimeInitialize(MethodBase method) {
}
[OnMethodEntryAdvice]
public void OnEntry(MethodExecutionArgs args) {
}
}
错误是什么意思?怎么了?
您可以将几个相关的建议合并为一组(例如 OnEntry
、OnExit
)。这是 OnMethodBoundaryAspect 自动为您做的。在对建议进行分组后,您需要将其中之一指定为 "master advice"。 group的属性和pointcut必须在master advice上设置
分配给主建议的切入点充当建议目标元素的选择器。例如,SelfPointcut 只是简单地选择方面的目标作为建议的目标。您可以在文档中找到更多信息和不同的切入点类型: https://doc.postsharp.net/advices
在上面的示例中,您可以将 [SelfPointcut]
属性应用于 OnEntry
方法以消除错误消息。
[PSerializable]
public class LogPlainRequest : IMethodLevelAspect {
public void RuntimeInitialize(MethodBase method) {
}
[OnMethodEntryAdvice]
[SelfPointcut]
public void OnEntry(MethodExecutionArgs args) {
}
}