Is is possible to intercept a constructor on a class you do not own?

Posted by code poet on Stack Overflow See other posts from Stack Overflow or by code poet
Published on 2010-05-26T11:07:09Z Indexed on 2010/05/26 13:11 UTC
Read the original article Hit count: 217

Filed under:
|
|
|

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.

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about proxy