Any files placed into the app_code folder are automatically available from any page in your web application, so you can write:
myNamespace.myClass.myFunction(someVariable)and the magic will happen. Alternatively, you can add
Imports myNamespace.myClassin the top of your page and call
myFunctionwithout all the prefixing.
Though I'm still not a big fan of ASP.NET, this app_code thing is pretty slick and it's inspired me to write more reusable code. I had previously written a collection of functions for temperature conversion, which I've since grown unhappy with after reading Code Complete 2.0 by Steve McConnell because I named my functions like this:
CelsiusToFahrenheit, instead of like this:
I had been planning to write more conversion functions for various units of measurement, but was never satisfied enough with how it was turning out to make it publically available. Besides learning to appreciate ASP.NET, I'm also learning to appreciate object-oriented programming. This whole namespace/class combination with app_code seems to be appropriately suited for doing unit of measurement conversion.
So here's my plan. I've defined a namespace called UOM, which is the manufacturing industry standard abbreviation for unit of measure. Each type of measurement will be a class: temperature, distance, volume, mass, etc. Each class will accept string input so that you can specify both the numeric quantity and the unit of measure simultaneously. The class will use the specified unit of measure to convert values to a common unit of measure, and be able to return values in any equivalent unit of measure.
Dim inside as Temperature
inside = New Temperature("10 C")
Response.Write(inside.getFahrenheit) ' Displays "50"
Download the VB.NET source code for UOM.Temperature from Snipplr.com