Thursday, March 31, 2005
« Save IDL! | Main | Teaser »

Cross-pollination is one of the benefits of regular interaction with fellow speakers and authors. For instance, Juval Lowy was just showing me this cool and rather obscure feature where you can just make method calls “disappear”. Now I am not convinced that this is a good thing, as the effect is not at all explicit or obvious – but it is cool nonetheless.


The idea is that you can write a method:


Public Sub Foo()

End Sub


Then you can call this method elsewhere in your code. Perhaps even many places in your code:


Public Sub Client()


End Sub


So far so good. But now apply this attribute to the Foo method:


<Conditional("MyFlag")> _

Public Sub Foo()

End Sub


When you now compile your project, Foo is compiled, but the call to Foo in the Client method is not included in the result. Yes, that’s right – all calls to Foo everywhere in your code disappear without a trace. They aren’t in the CIL, and thus are just poof, gone.


To get those calls to Foo back, you need to define a compiler symbol:


#Const MyFlag = True


Now mystically, the calls to Foo will reappear in the compiled code.


This is a form of conditional compilation, similar to checking for a debug condition or something. But it is not explicit, and the caller will have no idea that they aren’t calling the method any more. Nor will the developer, since there’s no way for the caller to even know that the method is marked for disappearance.


Seems like a feature that should remain obscure, but from a purely geeky perspective it is pretty interesting.