c# - Can I create a wrapper that intercept all calls to objects implementing certain interface? -


let's have interface ifoo

interface ifoo {   int bar();   int bar2();   void vbar();   //etc, } 

can create wrapper takes ifoo object , before/after actual call?

e.g. when this

ifoo wrappedfoo = new wrapper<ifoo>(actualfooobject).object; wrappedfoo.bar(); 

then wrapper.bar() method execute this

precall(); //some code can define in wrapper actualfooobject.bar(); postcall(); 

is there simple , clean way this?

you can use code contracts approach. take on section 2.8 interface contracts of user manual (pdf).


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -