是否可能拦截一个静态方法对象你不拥有,没有创建? [英] Is is possible to intercept a static method on an object you don't own and did not create?

查看:201
本文介绍了是否可能拦截一个静态方法对象你不拥有,没有创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指我可以回答这个问题:的 http://stackoverflow.com/questions/2907535/how-would-you-audit-asp-net-membership-tables-while-recording-what-user-made-在/ 2911616#2911616

Referring to my possible answer to this question: http://stackoverflow.com/questions/2907535/how-would-you-audit-asp-net-membership-tables-while-recording-what-user-made-the/2911616#2911616

是否有可能截获一个电话,从代码来你不拥有,在构造函数在一个密封的内部类,你?不与返回之前操纵对象的意图拥有

Is it possible to intercept a call, coming from code you do not own, to a ctor on a sealed internal class that you do not own with the intention of manipulating the object before returning?

具体的例子:

SqlMembershipProvider的,因为它的所有的数据访问,实例化一个连接辅助类, System.Web.DataAccess.SqlConnectionHolder

SqlMembershipProvider, for all of it's data access, instantiates a connection helper class, System.Web.DataAccess.SqlConnectionHolder.

期望的结果是拦截这个实例并在 System.Web.DataAccess的构造函数打开公共连接上执行操作。 SqlConnectionHolder 之前让执行继续

The desired result is to intercept this instantiation and perform an operation on the public connection that is opened in the ctor of System.Web.DataAccess.SqlConnectionHolder before letting execution continue.

更新:
所以,leppie关于我的例子指出,我说,我想是不是我想要的。

UPDATE: So, as leppie observed regarding my example, what I say I want isn't what I want at all.

现在的目标是 System.Web.DataAccess.SqlConnectionHelper.GetConnection()

因此,我们可以拦截调用此方法?

So, can we intercept the call to this method?

internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation)

这是可能的。如果是这样,一个简单的例子,将不胜感激。

Is this possible. If so, an brief example would be appreciated.

推荐答案

从技术上讲,这是可能与IL重写,类似于Postsharp呢。然而,鉴于这是你在谈论一个.NET程序集具有强名称,存储在GAC和NGEN-ED,这是不太可能曾经越过技术上可行的阶段。

Technically this is possible with an IL rewriter, similar to what Postsharp does. However, given that this is a .NET assembly you're talking about that has a strong name, is stored in the GAC and ngen-ed, that isn't likely to ever get past the "technically possible" stage.

这篇关于是否可能拦截一个静态方法对象你不拥有,没有创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆