Rant about EnvDTE.CodeTypeRef.Rank

When you have a variable (EnvDTE.CodeVariable) or function (EnvDTE.CodeFunction), their Type property returns an EnvDTE.CodeTypeRef with information about the type. If the type is an array then CodeTypeRef.Rank returns the dimensions (1, 2…). The problem is that if it is not an array, it throwns an exception, which can hurt the performance if you do that with lots of functions or variables (think an operation that processes the whole code of a solution). It would be much more better if the automation model returns 0 for the Rank if the type is not an array, but chances of MS changing that at this point are minimal, so as a workaround, you should try to call the Rank property only if you know in advance that it is an array (and therefore it is not going to throw an exception). You can know using the CodeTypeRef.AsString property: if the result contains “(” for VB.NET or “[” for C#, you know it is an array.

MZ-Tools Articles Series: HOWTO: Get Microsoft Office bitmaps for Visual Studio add-ins

I have been struggling during the last weeks to get 32×32 icons from Office 2007 and yesterday I found the 2007 Office System Add-In: Icons Gallery. Also, a question that appears from time to time in the forums is how to get the numerical indexes of the Office bitmaps to use when calling the AddNamedCommand method, and incredible as it is, I think that Microsoft never documented this for that method in MSDN, and there used to be years ago an Excel spreadsheet (quite difficult to find then, and impossible nowadays, likely removed from MSDN) to help in the task with VB5/VB6/Office add-ins. Fortunately I put a copy in the Files section of the Yahoo forum for VS.NET add-ins that I used to visit until a couple of years ago before moving to the MSDN forum, and I had a copy of the Excel file in my own hard disk. I have documented all this in my latest article:

HOWTO: Get Microsoft Office bitmaps for Visual Studio add-ins