PostSharp OnMethodBoundaryAspect没有触发某些asbtract方法(PostSharp OnMethodBoundaryAspect not firing on some

编程入门 行业动态 更新时间:2024-10-09 07:22:52
PostSharp OnMethodBoundaryAspect没有触发某些asbtract方法(PostSharp OnMethodBoundaryAspect not firing on some asbtract method)

我可以覆盖一些方法,如GetHashCode或我自己的抽象类,但方面没有触发SqlConnection.Open和关闭

SqlConnection a = new SqlConnection("Password=qwsa;Persist Security Info=True;User ID=sa2;Initial Catalog=mydb;Data Source=."); a.Open(); // not firing var zzzz = a.GetHashCode(); //firing a.Close(); //not firing Class1 class1 = new Class1(); //firing var zzzzzzz=class1.testttt(); //not firing

这是我的代码

[Serializable] public class TestOverrideAspect : OnMethodBoundaryAspect { public override void OnExit(MethodExecutionArgs args) { //DoWORK } } #if DEBUG [assembly: PostsharpAspects.TestOverrideAspect (AttributeTargetAssemblies = "*", AttributeTargetTypes = "*", AttributeInheritance=MulticastInheritance.Multicast )]

I can override some method like GetHashCode or my own abstract class but aspect not firing on SqlConnection.Open and Close

SqlConnection a = new SqlConnection("Password=qwsa;Persist Security Info=True;User ID=sa2;Initial Catalog=mydb;Data Source=."); a.Open(); // not firing var zzzz = a.GetHashCode(); //firing a.Close(); //not firing Class1 class1 = new Class1(); //firing var zzzzzzz=class1.testttt(); //not firing

Here is my code

[Serializable] public class TestOverrideAspect : OnMethodBoundaryAspect { public override void OnExit(MethodExecutionArgs args) { //DoWORK } } #if DEBUG [assembly: PostsharpAspects.TestOverrideAspect (AttributeTargetAssemblies = "*", AttributeTargetTypes = "*", AttributeInheritance=MulticastInheritance.Multicast )]

最满意答案

通常,在外部组件上应用方面是不好用的标志,即使有可能并且在某些情况下是必要的。 对于OnMethodBoundaryAspect和抽象方法,尤其如此,您希望方面实际更改所有重载(如果指定继承)。

您应该使用具有不同理论背景的MethodInterceptionAspect ,并在您需要时更好地工作。 如果你在System.Data.SqlClient.SqlConnection.Open上应用这样的方面它应该正常工作,应该拦截抽象方法。 您只是没有通常的建议,所以您需要自己实现类似的代码。

另请注意,我们在属性多播中遇到了一个相关的错误,最近修复了,所以请检查您是否有最新版本。

Generally, applying aspects on external assemblies is a sign of bad use, even though it is possible and in some cases necessary. This is especially true in case of OnMethodBoundaryAspect and abstract method where you want the aspect to actually change all overloads (if you specify the inheritance).

You should use MethodInterceptionAspect which has different theoretical background and works better in case you need. If you apply such aspect on System.Data.SqlClient.SqlConnection.Open it should work properly and should intercept the abstract method. You just don't have usual advices so you need to implement similar code yourself.

Please also note that we had a related bug in attribute multicasting, which was recently fixed, so please check that you have the latest version.

更多推荐

class,firing,GetHashCode,SqlConnection,电脑培训,计算机培训,IT培训"/> <meta n

本文发布于:2023-07-30 15:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338813.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   OnMethodBoundaryAspect   PostSharp   asbtract   method

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!