Yup! Me and my wife are coming to the VS 2008 Kickoff event in Los Angeles today. Wohoo! This is the first time we’ll see Bill Gates live in person and we are excited about it. Wohoo! I’ll post some pictures here tommorow to show you guys what transpired at the Nokia Theatre and Los […]
Month: February 2008
February 26, 2008
keithrull
I’ve gotten this question 3 times in different flavors since last week and I’ve decided that it’s time to post the solution in my blog. I’ve added comments on the code to explain what every line is doing. The code below will demonstrate how you can read the assembly information in both C# and VB.NET. [—————— C# ——————]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
<SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><PRE><SPAN style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"><SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</SPAN> System; <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</SPAN> System.Collections.Generic; <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</SPAN> System.Text; <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</SPAN> System.Reflection; <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">using</SPAN> System.IO; <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">namespace</SPAN> KeithRull.ReadingAssemblyInformation { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// <summary></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// A sample program that demonstrates how to get the</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// Assembly information. This is useful when you want</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// to see the version of your class library.</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// </summary></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">class</SPAN> Program { <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">void</SPAN> Main(<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>[] args) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//create a new assembly object that would signify</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//the current running assembly</SPAN> Assembly currentAssembly <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> Assembly.GetExecutingAssembly(); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//create the dictionary object that would contain</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//all the information about our assembly</SPAN> Dictionary<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>, <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>> dictionaryOfProperties <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> GetAssemblyInfoDictionary(currentAssembly); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//iterate thru each key in the dictionary</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">foreach</SPAN> (<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN> key <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">in</SPAN> dictionaryOfProperties.Keys) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//print the key and its value</SPAN> Console.WriteLine(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"{0}: {1}"</SPAN>, key, dictionaryOfProperties[key]); } <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//pause</SPAN> Console.ReadLine(); } <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// <summary></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// A method that returns a Dictionary of Assembly properties</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// </summary></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// <param name="selectedAssembly">The assembly to inspect</param></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">/// <returns>The dictrionary containing the assembly information</returns></SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">static</SPAN> Dictionary<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>, <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>> GetAssemblyInfoDictionary(Assembly selectedAssembly) { <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//Create the dictionary</SPAN> Dictionary<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>, <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>> dictionaryOfProperties <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">new</SPAN> Dictionary<<SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>, <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN>>(); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//get the location of the assembly</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">string</SPAN> assemblyPath <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> selectedAssembly.Location; <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add the assembly location to out dictionary</SPAN> dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"AssemblyLocation"</SPAN>, assemblyPath); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//create the AssemblyName object based on our Assembly</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//this will enable us to get the version information</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//and other properties related to our assembly</SPAN> AssemblyName assemblyName <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> selectedAssembly.GetName(); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add the FullName of out assembly</SPAN> dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"AssemblyFullName"</SPAN>, assemblyName.FullName); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"AssemblyName"</SPAN>, assemblyName.FullName); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add the assembly version information</SPAN> dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Version"</SPAN>, assemblyName.Version.ToString()); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Version.Major"</SPAN>, assemblyName.Version.Major.ToString()); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Version.Minor"</SPAN>, assemblyName.Version.Minor.ToString()); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Version.Build"</SPAN>, assemblyName.Version.Build.ToString()); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"Version.Revision"</SPAN>, assemblyName.Version.Revision.ToString()); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add the creation time</SPAN> DateTime creationTime <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> File.GetCreationTime(assemblyPath); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"CreationTime"</SPAN>, creationTime.ToString()); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//add the last write time</SPAN> DateTime lastWriteTime <SPAN style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">=</SPAN> File.GetLastWriteTime(assemblyPath); dictionaryOfProperties.Add(<SPAN style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4">"LastWriteTime"</SPAN>, creationTime.ToString()); <SPAN style="FONT-SIZE: 11px; COLOR: green; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">//return our dictionary obeject</SPAN> <SPAN style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">return</SPAN> dictionaryOfProperties; } } } </SPAN> |
[—————— […]
February 25, 2008
keithrull
I’ve been working on ASP.NET AJAX eversince it’s beta days and the UpdateProgress and UpdatePanel has been my bestfriend since day one. I’ve learned a few tricks while using ASP.NET and today I’d like to share with you several ways to customize the look and feel of you UpdateProgress control with this sample solution. I […]
February 23, 2008
keithrull
Never use your computer when you are sleepy. Period. I woke up this morning and I immediately saw my pc with some Internet Explorer windows open so I immediately sat down and tried to delete the cookies and form data from machine but instead of deleting the cache I accidentally deleted the IE icon in […]
February 22, 2008
keithrull
I know. I know. I know. I wasn’t able to post anything this past few weeks. It’s been really busy and the amount of task that i would be dealing in the next few days is going to get crazier because of my current project. I’m currently working on a KPI project that involves building […]
February 7, 2008
keithrull
Hey you! Yes you! Yup you! You who is reading this blog right now! Are you one of the 75 people subscribed to my blog? Or are you just a passer by? I’m wondering if it would be ok if you could put a comment on this post and let me know why you subscribed to […]
February 7, 2008
keithrull
Here’s a small trick i use alot. Question: What’s the easiest way to get the distict rows of data in a DataTable and DataView in .NET 2.0? Answer: The easiest way to get distinct DataRows in a DataTable or DataView is by using the DataView.ToTable() method. Now lets demonstrate. Assuming that I have this table of data in a […]
February 4, 2008
keithrull
It’s funny, just after posting this post in response to an article that N@rds posted that I realized that I have been preaching about extension methods and his problem was a great example on when to make use of this excellent feature. Let’s start doing some extension methods. N@rds made a wish in his last post […]
February 2, 2008
keithrull
I was browsing at DevPinoy.org today when I saw this interesting post by n@rds about searching for files in a directory using multiple search patterns and it made me realize that there are alot of ways you can accomplish this task. Here are some examples on how you can search files in a directory using […]
February 1, 2008
keithrull
I wrote an article about this topic a few months ago but I wanted to explain it a little further in this article by showing real-world scenarios on when and how to use this feature. So what does Extension Method mean? According to MSDN: “Extension methods enable you to “add” methods to existing types without […]