views:

94

answers:

1

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?

Concrete example:

SqlMembershipProvider, for all of it's data access, instantiates a connection helper class, 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.

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

The target is now 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.

+2  A: 

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.

Hans Passant
Hans - the question has changed a bit, thanks to leppie, but I suspect the answer is the same. So, although in this instance it is not possible, I would like to know more in general. Could you add a few good links? Or even better, add an expressly solicited search term that would point to the appropriate resources. Heres your chance to LMGTFY someone and not get dinged for it. ;-)
Sky Sanders
Not sure, most of it is closed source. Perhaps AspectSharp: http://sourceforge.net/projects/aspectsharp/files/
Hans Passant
Thanks for that. Have a + on me. Am going to bump this a few times to see what shakes out before accepting.
Sky Sanders