<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bertan's Blog : Tips</title><link>http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx</link><description>Tags: Tips</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>VSIP: Adding a command filter to any text editor</title><link>http://blogs.msdn.com/bertan/archive/2007/10/26/vsip-adding-a-command-filter-to-any-text-editor.aspx</link><pubDate>Sat, 27 Oct 2007 00:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5696022</guid><dc:creator>bertaygu</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bertan/comments/5696022.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=5696022</wfw:commentRss><description>&lt;P&gt;I have been trying to add a command filter to all text editors in Visual Studio for a project, since I had to collect information from several number of sources I wanted to collect them in one place in the hope that somebody else might find it useful.&lt;/P&gt;
&lt;P&gt;In order to get notification when a text view is registered in Visual Studio, we first have to register an implementation of &lt;EM&gt;IVsTextManagerEvents&lt;/EM&gt; as an event sink. In order to do this you can use the following code block which uses IVsTextManager service.&lt;/P&gt;&lt;FONT color=#2b91af size=2&gt;
&lt;P&gt;IVsTextManager&lt;/FONT&gt;&lt;FONT size=2&gt; textManager = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;.GetService(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;typeof&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;SVsTextManager&lt;/FONT&gt;&lt;FONT size=2&gt;)) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IVsTextManager&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IConnectionPointContainer&lt;/FONT&gt;&lt;FONT size=2&gt; container = textManager &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;as&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IConnectionPointContainer&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IConnectionPoint&lt;/FONT&gt;&lt;FONT size=2&gt; textManagerEventsConnection = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;null&lt;/FONT&gt;&lt;FONT size=2&gt;;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Guid&lt;/FONT&gt;&lt;FONT size=2&gt; eventGuid = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;typeof&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;IVsTextManagerEvents&lt;/FONT&gt;&lt;FONT size=2&gt;).GUID;&lt;BR&gt;container.FindConnectionPoint(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ref&lt;/FONT&gt;&lt;FONT size=2&gt; eventGuid, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;out&lt;/FONT&gt;&lt;FONT size=2&gt; textManagerEventsConnection);&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;uint&lt;/FONT&gt;&lt;FONT size=2&gt; cookie = 0; &lt;BR&gt;textManagerEventsConnection.Advise(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;this&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;out&lt;/FONT&gt;&lt;FONT size=2&gt; cookie);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Now &lt;EM&gt;IVsTextManagerEvents.OnRegisterView &lt;/EM&gt;method is going to be called for each new view created. In that method you can use passed &lt;EM&gt;IVsTextView.AddCommandFilter&amp;nbsp;&lt;/EM&gt;method to add a command filter. However, when the event is raised the window is actually not initialized fully so any command filter you add will be below the language service filters thus you won't see all of the commands. My solution to this problem was to check the text buffer each time &lt;EM&gt;Exec&lt;/EM&gt; method was called on the filter and remove/add the filter once the buffer wasn't empty anymore. I am still trying to find a better solution and I will update this entry if I find anything better than relying on the buffer. One apparent problem with this solution is that as long as the text view remains empty, the filter will not be re-registered thus causing you to lose some events on empty files.&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5696022" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category><category domain="http://blogs.msdn.com/bertan/archive/tags/VisualStudio/default.aspx">VisualStudio</category><category domain="http://blogs.msdn.com/bertan/archive/tags/VSIP/default.aspx">VSIP</category></item><item><title>Unit testing legacy code and reflection</title><link>http://blogs.msdn.com/bertan/archive/2007/06/13/unit-testing-legacy-code-and-reflection.aspx</link><pubDate>Wed, 13 Jun 2007 22:18:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3273106</guid><dc:creator>bertaygu</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bertan/comments/3273106.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=3273106</wfw:commentRss><description>&lt;P&gt;I was recently in a training about test driven development and in an exercise about testing legacy code, a very nice idea came up to inject mock objects to legacy code. The usual problem is that if a legacy code is not written taking testability in to account, there might a lot of hard coded dependencies to external sources such as databases which makes unit testing really difficult. In order to quickly unit test the legacy components, those dependencies should be replaced by mock objects so that unit tests won't require a deployed environment. There are several ways to do this, one way is to decide which object to use (mock or the actual component) based on the a global flag. This can be dangerous if the flag is not set to false when deploying to production environment. However by using reflection, you can avoid modifying the existing code and replacing the reference to the mock component in the unit test itself. Below is a quick code snippet in how you can achieve this:&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;CustomerReader reader;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Type&lt;/FONT&gt;&lt;FONT size=2&gt; objectType = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;typeof&lt;/FONT&gt;&lt;FONT size=2&gt;(reader);&lt;BR&gt;System.Reflection.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;FieldInfo&lt;/FONT&gt;&lt;FONT size=2&gt; field = objectType.GetField(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"DataLayer"&lt;/FONT&gt;&lt;FONT size=2&gt;,&lt;BR&gt;&amp;nbsp; System.Reflection.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;BindingFlags&lt;/FONT&gt;&lt;FONT size=2&gt;.Instance |&lt;BR&gt;&amp;nbsp; System.Reflection.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;BindingFlags&lt;/FONT&gt;&lt;FONT size=2&gt;.NonPublic |&lt;BR&gt;&amp;nbsp; System.Reflection.&lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;BindingFlags&lt;/FONT&gt;&lt;FONT size=2&gt;.GetField);&lt;BR&gt;field.SetValue(reader, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;new&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Object&lt;/FONT&gt;&lt;FONT size=2&gt;());&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;This code snippet will change the value of reader.DataLayer which is&amp;nbsp;a private field in the object.&amp;nbsp;However there is one drawback to this method. The&amp;nbsp;wrapper object that you are replacing must be&amp;nbsp;inheritable otherwise you won't be able to create a&amp;nbsp;mock object to replace the original instance.&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3273106" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category></item><item><title>ResEx: an editor for translating resource files</title><link>http://blogs.msdn.com/bertan/archive/2007/03/07/resex-an-editor-for-translating-resource-files.aspx</link><pubDate>Wed, 07 Mar 2007 20:13:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1829406</guid><dc:creator>bertaygu</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bertan/comments/1829406.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=1829406</wfw:commentRss><description>&lt;P&gt;Jeremy found a good companion to Resource Refactoring tool to make working with localized resource files much easier. Once you created resource files using Resource Refactoring Tool, you can use ResEx to translate resource files in to different cultures. ResEx will automatically create the resource files for the new languages as you add entries. ResEx project seems to be at an early stage of development, but I had no problems with it when I tried it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;You can download ResEx at this link: &lt;A href="http://www.papadi.gr/Default.aspx?TabId=290"&gt;http://www.papadi.gr/Default.aspx?TabId=290&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1829406" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/Power+Toys/default.aspx">Power Toys</category><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category><category domain="http://blogs.msdn.com/bertan/archive/tags/ResourceRefactoring/default.aspx">ResourceRefactoring</category></item><item><title>Debugging Visual Studio Add-Ins</title><link>http://blogs.msdn.com/bertan/archive/2006/12/06/debugging-visual-studio-add-ins.aspx</link><pubDate>Wed, 06 Dec 2006 22:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1224878</guid><dc:creator>bertaygu</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bertan/comments/1224878.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=1224878</wfw:commentRss><description>&lt;P&gt;Although developing Visual Studio Add-Ins has become much easier with Visual Studio 2005, debugging the add-in you are developing can still be difficult. This is because your add-in is loaded each time you open Visual Studio so in order to be able to build the add-in, you have to disable the add-in first making it a fairly difficult and tedious process. Fortunately, we can take a hint from how you would debug VSIP packages if you were developing one. &lt;/P&gt;
&lt;P&gt;If you are developing a VSIP package, VSIP project adds relevant package information to a separate experimental hive in the registry thus the instance of Visual Studio you are developing your VSIP package never runs your libraries and you can always build them. We can do the same thing for add-ins as well, first of all you need a separate experimental hive. You can easily do this by installing &lt;A class="" href="http://www.microsoft.com/downloads/details.aspx?familyid=7E0FDD66-698A-4E6A-B373-BD0642847AB7&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?familyid=7E0FDD66-698A-4E6A-B373-BD0642847AB7&amp;amp;displaylang=en"&gt;Visual Studio SDK&lt;/A&gt; or copying all of &lt;STRONG&gt;HKLM\Software\Microsoft\VisualStudio\8.0&lt;/STRONG&gt; registry branch to &lt;STRONG&gt;HKLM\Software\Microsoft\VisualStudio\8.0Exp&lt;/STRONG&gt;. &lt;/P&gt;
&lt;P&gt;Once you have the experimental hive (8.0Exp), go to &lt;STRONG&gt;Automation Options\LookInFolders&lt;/STRONG&gt; under that hive and add a new directory. For example I added &lt;STRONG&gt;"%VSMYDOCUMENTS%\TestAddins&lt;/STRONG&gt;". This will be directory where you put add-in descriptor files for the add-ins you are developing. Now open your add-in project and go to Debug properties to modify start action. If you have not modified the project before, start action should be set to "Start external program" and devenv.exe should be the program selected. If this is the case, add "/rootSuffix Exp" to command line arguments which will cause Visual Studio instance to use the experimental hive we just created thus loading your add-in. Since your add-in is not loaded with other instances of Visual Studio, you can now build it without worrying about add-in files being in use.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1224878" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category><category domain="http://blogs.msdn.com/bertan/archive/tags/VisualStudio/default.aspx">VisualStudio</category></item><item><title>Bookmark manager tool for Visual Studio</title><link>http://blogs.msdn.com/bertan/archive/2006/11/29/bookmark-manager-tool-for-visual-studio.aspx</link><pubDate>Thu, 30 Nov 2006 02:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1173991</guid><dc:creator>bertaygu</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bertan/comments/1173991.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=1173991</wfw:commentRss><description>&lt;P&gt;One of the ideas submitted to our team for possible power toys was to implement a document bookmark manager where users can group bookmarks by groups and access them with keyboard shortcuts. While browsing the web a while ago to find out if a similar power toy was developed, I have come across &lt;A class="" href="http://www.usysware.com/dpack/Default.aspx" target=_blank mce_href="http://www.usysware.com/dpack/Default.aspx"&gt;DPack&lt;/A&gt; from &lt;A class="" href="http://www.usysware.com/Default.aspx" target=_blank mce_href="http://www.usysware.com/Default.aspx"&gt;USysWare Inc.&lt;/A&gt; which is a free collection of tools for Visual Studio. One of the tools in the collection is a bookmark manager allowing you to group bookmarks and recall them by group numbers, you can read more about the &lt;A class="" href="http://www.usysware.com/dpack/Bookmarks.aspx" target=_blank mce_href="http://www.usysware.com/dpack/Bookmarks.aspx"&gt;numbered bookmark feature&lt;/A&gt; at their product page or download DPack from the tool homepage.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1173991" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/IDE+Power+Toys/default.aspx">IDE Power Toys</category><category domain="http://blogs.msdn.com/bertan/archive/tags/Power+Toys/default.aspx">Power Toys</category><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category></item><item><title>Assigning shortcut keys to add-in commands in Visual Studio</title><link>http://blogs.msdn.com/bertan/archive/2006/11/27/assigning-shortcut-keys-to-add-in-commands-in-visual-studio.aspx</link><pubDate>Tue, 28 Nov 2006 02:27:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1162073</guid><dc:creator>bertaygu</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bertan/comments/1162073.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bertan/commentrss.aspx?PostID=1162073</wfw:commentRss><description>&lt;P&gt;If you are using a Visual Studio add-in you love but you wanted to have shortcuts for its menu entries, you are not completely out of luck. Using Visual Studio options, you can add shortcut keys to any Visual Studio command including the ones created by add-ins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;In order to add a shortcuy key, you should go to Tools -&amp;gt; Options and choose Environment -&amp;gt; Keyboard pane. This pane contains a list of commands available in Visual Studio, most of the time commands have a meaningful name so you can easily search them. Below is a list of commands for some add-ins we have developed:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Microsoft.VSPowerToys.ResourceRefactor.Connect.RefactorLiteral: Opens up "Extract to Resource" dialog&lt;/LI&gt;
&lt;LI&gt;Microsoft.VSPowerToys.VSCmdShell.Connect.VSCmdShellWindow: Opens up "VSCmdShell" dialog.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Once you select the command you want, you can assign it any shortcuy key you want. You can also choose the context where shortcuts will be enabled. For example for resource refactoring tool command, it will probably be best to choose "Text Editor" as the context since the command will not execute successfully in any other context. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1162073" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bertan/archive/tags/Power+Toys/default.aspx">Power Toys</category><category domain="http://blogs.msdn.com/bertan/archive/tags/Tips/default.aspx">Tips</category></item></channel></rss>