DIVEX

Static methods as Functions

You can treat static methods as functions. DIVEX supports this in two ways. The first way is through surrogate classes created inside your composition classes (e.g. Program class). Consider the following:

In the above figure, there is a static class called Module1 with a static method called Add. In the Main method, after I type “Module1.”, IntelliSense has an option for me that says GenerateSurrogateClass. If I use it, the following happens:

The dot was removed, and then some code was added at line 9. The code says:

Surrogate for global::SampleApp.Module1 named Module1.

which means that Module1 is now a surrogate for the real SampleApp.Module1 class. Now if I press dot again to ask IntelliSense for completions, I get the following:

IntelliSense shows Add as a member of Module1. And Add is a function that takes two integers and returns an integer. Now, I can use Add as a function:

The surrogate class doesn’t have to have the same name as the real class. You can rename it using Visual Studio rename feature.

The second, more intrusive way, is to annotate static classes with the DivexModule attribute and have the surrogate class be created automatically in the same namespace of the original static class. Consider this:

The Module1 class is renamed to Module1Def class. And the DivexModule attribute is applied on this class. Using this attribute, we can control the name of the new class to generate. This is useful when you are creating a class library and you want to have the surrogate classes compiled with your class library.