Monday, November 11, 2013

dotPeek

I am in the beginning stages of a project where I need to create a class library that sort of acts as a proxy that will call a third party assembly.  The third party assembly is being called directly and I need to sort of duplicate some of the code.  Without going into too much detail, I will explain the issue and how I solved it.  Basically, this third party assembly was being called something similar to the following:

Dim resp As String = SubmitTransaction(req, ThirdPartyUtil.RequestId)

My first issue is that the code is in VB.Net, but that discussion is for a future post.  My next issue was that I needed to know what ThirdPartyUtil.RequestId is and how do I duplicate that in my code.  After doing some more research, I found another project that used the same third party assembly, but a little differently as you can see below:

string resp = SubmitTransaction(req, MainAssembly.GenerateRequestId());

As you can see, this code is much better because it is in C#, but it still has something that I don't know too much about and that is the call to MainAssembly.GenerateRequestId().  What I had to do was look through the VB.Net and C# code to try and figure out what this property and method call did.  Well, after getting lost and going nowhere, I asked a co-worker about it and they sent me some documentation on the assembly.  This didn't help much, so what could I do next?  After thinking about it for a few, I decided to see if dotPeek would provide any details about it.  If you are not familiar with dotPeek, it is a tool by JetBrains that can be used to decompile assemblies and I highly recommend at least installing it and learning what it can do.  This tool can be downloaded for free at http://www.jetbrains.com/decompiler/.  Now, without showing details on that exact assembly loaded in the tool, I was able to pull out the method and property and they ended up looking like the following:

MainAssembly:

public string GenerateRequestId()
{
   return ThirdPartyUtil.RequestId;
}







ThirdPartyUtil:

public static string RequestId
{
   get
   {
      return Guid.NewGuid().ToString("N");
   }
}





This was great news to me and will allow me to move forward without wasting too much time.  All I needed to do was to provide this same functionality which is to return the guid in the same way the code above did.  

For a quick demo on dotPeek, visit the main page of dotPeek and view the video which is only about five minutes long.  Also, if you don't use resharper download the trial version from JetBrains while you are there.  

peace yo!

No comments:

Post a Comment