我可以覆盖一些方法,如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 firingHere 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
发布评论