Like many of the three of you who subscribe my blog, I download a bunch of tools & utilities that I read about online and seldom have an opportunity to use on a real project.
Today was my first bona fide use of the Snippet Compiler and it just plain rocked. Its a small client application that can take the place of many throw-away command line programs written just to test out a concept. The application launches fast and I can start writing and executing my code immediately. I don't need to select a project template, name it, or any other of the standard housekeeping items. It even has statement completion!
I was working on an existing ASP.Net v1.1 code base for a quick maintenance project. I gleaned a test order number from the system and quickly realized my specific test required an obfuscated order number from the following "simple" and "natural" function:
//=====================================================================
/// <summary>
/// This method performs exactly the opposite action as
/// EncodeOrderId(), and is meant as the natual companion to that
/// method. Performs a very simple wrapping bit shift (4 bits wide,
/// towards the most significant bit) on the input value (unsigned
/// 32 bit integer) and returns it as a signed 32 bit integer.
/// </summary>
/// <param name="orderId">Value to decode.</param>
/// <returns>Decoded value.</returns>
//=====================================================================
public static int DecodeOrderId( uint orderId )
{
int newOrderId = (int) (( orderId << 4 ) | ( orderId >> 28 ));
if ( newOrderId < 1 )
{
throw( new ArgumentException( "Invalid orderId: '" +
orderId.ToString() + "'.", "orderId" ));
}
return( newOrderId );
}
I was doing integration testing and further more, I was nearly done. I didn't feel like firing up VS.Net to figure out how to get my test order number obfuscated, so I thought about it and decided to have a spontaneous moment.
I (1) fired up the Snippet Compiler, (2) added a reference to the assembly and (3) wrote a single line of code that called the static method DecodeOrderId() which wrote the result to the console output. Booya!