Author Archive

New Features in the Latest ReSharper 8 EAP

Tuesday, April 30th, 2013

Good news everyone — we’ve got another EAP build ready and it should come as no surprise that we’ve got a few new features to talk about. So without further ado, here’s what we’ve got in store for you today.

Extension Manager or how to provide xUnit.net support

We sometimes get requests to provide certain features out of the box, functionality that is currently provided via plugins. xUnit.net support is one of these.

While doing this certainly has its benefits, it also has disadvantages. As such, we decided instead to take the opportunity to address the core problem, which is to simplify the discovery, installation and updating of ReSharper plugins.

We’re very pleased to introduce our NuGet based Extension Manager. It’s now very easy to add extensions and plugins to ReSharper, all from a user interface you’re very familiar with from NuGet. Simply open the Extension Manager from the ReSharper menu, and you’ll be able to browse and search for extensions from the “Online” category - make sure you select “Include Prerelease” in the drop down first - these are still EAP packages!

So to get xUnit.net test support, simply find the xunitcontrib package and hit Install.

That’s all there is to it! ReSharper now has support for running xUnit.net tests, and includes Live Templates and External Annotations to make your test code writing experience better.

We’ll be taking a more in-depth look at this feature very soon, but one important point to make right now is that because NuGet is a .NET4 library, the Extension Manager is only available in Visual Studio 2012 and 2010.

ToString() Format Completion

ReSharper already has a few features related to String.Format() usage, such as for example inspections and fixes related to format arguments being used in the format string. However, in this EAP we’re taking it a bit further by adding code completion for types which have well-known format specifiers (such as DateTime, TimeSpan, Guid, enumerations and many others):

Multi-File Templates

By popular demand, ReSharper’s support for file templates has been expanded to incorporate the possibility of creating several files from a single template. You start, as always, by creating a single file template. But then, ReSharper gives you controls to add additional files: you can either add a new file or a file from an existing template:

Choosing one of these options adds another editor into the template editor window. In this editor, you can specify the placement of the file (either a relative location or an ASP.NET code-behind file), the name of the folder to place the file into, and of course the name of the file. Then, just edit this template as you would any other — you can reuse the parameters you declared for the first template.

You can add as many files as you want and once you come to fire the template, all the necessary files (and folders, if they do not exist) will be automatically created in the right places.

Go To Generic Subsitutions

When you have the usage of a generic type such as List<Foo>, it’s easy enough to find all usages of List<T>, but what if you want to know the exact types that List<T> is being specialized with. To help with this, one of the new navigation options is to look for Generic Substitutions:

Once you fire up this navigation item, ReSharper will search for all the types that are used to substitute the generic parameter T and will show you a summary tree grouped by the type used to substitute the generic parameter. You can drill down into the tree to find out the exact locations where a particular type is used:

Blue Theme Support

Visual Studio 2012 Update 2 has been released with support for a Blue Theme, and we’ve made adjustments to ensure that ReSharper plays nice with it too:

We’ve got a lot more in store, and we’ll be blogging in the coming weeks about new features as well as giving in-depth overviews of the ones we’ve already mentioned. Meanwhile, please feel free to check out the EAP and let us know what you think!

ReSharper’s Web Path Mapping Explained

Monday, April 15th, 2013

One of the many scenarios that ReSharper seeks to address in web projects is a situation where the locations of files during the design of the app are different from the locations where the app gets deployed. This makes life difficult for ReSharper, since it doesn’t know where to go looking for the relevant files. Luckily, the Path Mapping feature lets you configure the locations of those paths.

There are two mechanisms that can both be used to configure path mappings – context actions and explicitly opening the Path Mapping dialog.

When ReSharper sees a path that it doesn’t recognize, it will underline the path with a wavy line, complaining that it doesn’t know where the path is. At this point, pressing Alt+Enter will show you several options for how the situation can be handled:

The first option, Ignore path, simply tells ReSharper to not bother inspecting this particular path wherever it may appear. This is useful in situations where, for example, you are referencing a file that doesn’t yet exist, and might be created later.

The second option is to Set path mapping, i.e. define explicitly how the path is handled.

Once again, there are two options: Substitute replaces a path with a different path, whereas Ignore chooses to ignore the path and is functionally equivalent to the Ignore path context action.

The Path mapping dialog box doesn’t only show up when you use a context action: you can also open it up by selecting the Path mapping element of the properties of the web project you’re working with. Note that we’re talking about the property grid (F4) rather than the tabbed property pages. To bring up the dialog, just press the button next to Path mapping.

Incidentally, the text value next to the button can be one of two possible options – either Custom indicating that some mappings have already been created, or Not set when none have yet been defined. At any rate, just as with the context action, pressing the button brings up the Path mapping window where you can create, delete and change mappings:

We hope you find this feature of ReSharper useful and your experience of developing web applications becomes a little more enjoyable. Develop with pleasure!

ReSharper 8 EAP, Build 3: What’s New!

Monday, April 8th, 2013

You have probably already guessed that this post is about a new set of features that has appeared in the new build of the ReSharper EAP late last week, so, without further ado, here’s what we’ve got in store for you:

Bulb Menus in Margin

In an attempt to streamline the programmer’s interaction with gutter marks and bulb pop-ups, we have added an option to merge both of these constructs into a single construct that we call an action indicator. Here’s what it looks like:

As you can see, both the gutter mark options from unit tests and the context action on that element have been merged into a single menu. The use of action indicators is an optional feature that can be found in ReSharper’s Options under Environment|Editor|Editor Appearance:

Option #2 in the above list revers to the R#7.1-style mechanism of showing a bulb pop-up. The last option prevents any visual queues that a bulb item is available (save for the indicator itself), and only shows the menu when you explicitly open it with Alt+Enter.

Please note that this feature is available only for Visual Studio 2010 and later.

Decompiler Improvements

We’ve already talked a bit about decompilation (both in ReSharper and dotPeek), but this deserves a mention: we now know how to correctly decompile

  • async methods and await expressions, including async lambdas.

  • Expression trees — the decompiler will now help you when exporting Linq to SQL or Entity Framework code in query expressions. This means in ReSharper 7 you could only decompile an expression into this:

    whereas with ReSharper 8 you can decompile it into this:

  • Field-like events, taking into account the lock-free nature of C# 4’s add/remove accessors.

Fix in Scope

In-place fixes are great, but what’s even better is when you can apply that fix in a given scope. Take those pesky unused references, for example – now you can get rid of them not only in a file, but also on a project/solution level. All with a single quick-fix:

Now quite a few fixes can be applied to a larger scope than just the code under the cursor — including making a field read-only or removing a redundant cast.

Default Alignment Setting Adjustments

One common complaint about ReSharper’s default settings was that certain constructs we indented, shall we say, aggressively. The two particular cases of note are anonymous lambdas

And another case is indentation when a function call including parameters gets too big and is indented similar to

These and similar cases will now be treated more gently by ReSharper’s default settings.

Code Inspection Performance Improvements

Last, but certainly not least, after another round of performance improvements we’ve managed to once again speed up ReSharper’s code analysis. Specifically, the Find Code Issues command enjoys an over 2× performance improvement.

Now, you know what to do – grab the EAP and check out those features today!

Introducing the dotPeek 1.1 EAP

Tuesday, April 2nd, 2013

In our recent blog post on the ReSharper 8 EAP, we have mentioned certain improvements to the decompilation support. Today, we are happy to announce that the next version of dotPeek, our free decompiler, has also reached the EAP stage. Here are some of the features that you can try out today.

Export Assembly to Project

Many of you have asked us to add functionality for saving a decompiled assembly as a ready-to-build Visual Studio project. We have listened to your requests: now, if you right-click a decompiled assembly, you get the option to export it as a project:

All you need to do is provide the destination path and name of the project. You can also generate a solution (.sln) file if you need one.

The above generates a project (.csproj) file containing all the decompiled files. dotPeek is smart about creating projects – here are some of the optimizations it performs:

  • If PDB files are available, dotPeek restores the file and folder structure of the original project.

  • If the project has unsafe code, the project is configured to allow it.

  • The type of assembly is detected and the project is configured accordingly.

Incidentally, dotPeek also keeps track of your export history. If you try to export the project again, it will offer the following dialog:

Project File Support in Assembly Explorer

To make it easy to orient oneself in situations where parts of a solution exist only in compiled form and other parts exist as source code, dotPeek’s Assembly Explorer now supports Visual Studio projects (.csproj). You can automatically add the project to the Assembly Explorer after generating it from decompiled sources (see the Add project to Assembly Explorer checkbox in the above window):

Go to Everything

Just like ReSharper, dotPeek now uses Ctrl+T as the Go to Everything command, letting you navigate to either file, symbol or type within one menu:

Odds and Ends

Finally, here are a few more features that are available:

  • dotPeek now preserves window layout settings. It also keeps track of recently opened files.

  • Just like Visual Studio, dotPeek now lets you set bookmarks and navigate between them.

  • In addition to the MSI installer, dotPeek is now also available as a single executable file.

If you’re interested in seeing these features right now, download the dotPeek EAP and give it a go!

Another ReSharper 8 EAP Build. More Features

Wednesday, March 27th, 2013

Earlier this month we announced the first EAP of ReSharper 8 and a set of features that came with it. Now we have another EAP build out there, and a few more features available for you to try out. Here’s an overview.

Pull Parameter Refactoring

In previous versions of ReSharper, when you invoked the Change Signature refactoring to add a parameter to a method, ReSharper offered to simply insert default values into the method. Not anymore!

Now, after you add a parameter to a method, ReSharper asks you about the ways in which you want to handle the missing parameter in all the calls:

If you choose the Resolve with call tree option, ReSharper will show you a separate tool window which lets you ‘pull’ the parameter from all available sources:

As the above screenshot illustrates, it handles various complex scenarios (e.g., inheritance hierarchies) and offers different options depending on the situation.

We’ll dive deeper into this feature in a separate blog post.

Staged Completion

In ReSharper 8, when a type being used requires a using statement, we no longer show the blue pop-up window. Instead, we simply add the type to the completion list with a note of what namespace it comes from:

To ensure that performance during the addition of these menu items does not suffer, we implemented a staging mechanism: the ordinary completion items get added first, and then the completion items for the not-yet-imported types get added to the menu later.

Grab the new EAP build and play with it!

Introducing the ReSharper 8 EAP

Wednesday, March 6th, 2013

In the world of technology, no-one can afford to stand still. As new frameworks and languages come out, ReSharper does its best to keep up. This is why we are happy to announce the opening of the ReSharper 8 Early Access Program. With the forthcoming release, we are proud to announce the following features, which will be part of ReSharper 8.

Go To Everything

In preparation for ReSharper 8, we’ve put in extra effort on streamlining certain operations. One of the areas where we felt improvement was needed was the unnecessary divergence caused by the various Go To menus. In an effort to simplify things, we have altered the main Go To Type command (Ctrl+T) so that now it navigates to either types, symbols or file names, all contained within the same listing.

By default, the menu shows a listing of recently opened files:

Searches for identifiers now yield both files, types, and file members:

Don’t worry – all the previous commands (e.g., Go To File) continue to work, and dynamically switching from one context to another is supported. The functioning of selectors is, of course, left intact, so you can write things like ClassName.MemberName to locate a particular member of a class, use combo navigation, wildcards and camel-humps. In addition, we added some new selectors – for example, typing public or private helps you narrow members down by visibility. Performance of this menu has been optimized so searches should be very quick.

Code Completion Improvements

This release comes with a substantial number of improvements in the way ReSharper offers code completion suggestions.

New Items in Automatic Code Completion

The first thing to point out is that, from now on, various aspects of smart completion and import symbol completion are now integrated into ordinary code completion, once again striving for a more streamlined experience.

For example, if you take a class and indicate that it implements INotify, you will be presented with the following menu:

The completion options will now show you all the possible ways of getting at a particular interface that begins with INotify, and using it will cause the appropriate using statement to be added to the top of the file.

In addition to the above improvements, ReSharper now offers several generative completion options, specifically offering to generate code on partial and override statements:

And finally, we’ve added some minor improvements to existing completion mechanisms. For example, the completion list for a collection member now includes the keyword new by default:

Other Code Completion Improvements

In addition, we’re introducing a new concept called Double Completion. For example, when you use ordinary completion by pressing Ctrl+Space, and you don’t get the member you’re looking for, you can press this shortcut again to try locate the element in all referenced assemblies. Double Completion also works with Smart Completion, so pressing Ctrl+Alt+Space more than once will offer you various chains of calls that will get you to the right member (possibly via extension methods).

Double Completion mechanisms are supplemented by quick-fixes, so if you use it to get at a symbol that is private, a quick-fix will quickly let you alter the visibility of a member to make it accessible.

New Code Inspections

As always, we’ve added new inspections as well as improved existing ones. Here’s a small sampling of some of them:

  • You can now disable all ReSharper warnings with a single comment — instead of defining separate inspections to suppress, you can now mark code with // ReSharper disable all and ReSharper will not complain about anything until it meets a corresponding // ReSharper restore all .

  • You can now switch between array initialization expressions and array creation expressions; ReSharper offers the appropriate inspection and context actions:

  • An ability to convert recursive calls to iterative ones:

  • If a method has an overload that supports cancellation (i.e., takes a CancellationToken), ReSharper will offer to use that overload, provided that there is a CancellationToken available in scope:

  • ReSharper also supports the idea of fallback color in CSS:

This is just a sampling of some of the inspections improvements that we’ve added. We’ll publish a blog post with more in-depth information soon.

CSS Improvements

To help developers ensure correct operation of their code, ReSharper introduces configurable support for CSS3 and earlier versions, as well as compatibility checks against popular browsers:

As a consequence of these compatibility checks, ReSharper will now provide detailed information about the availability of a feature for a particular browser:

We’re working on making ReSharper progressively smarter in recognizing CSS declarations, whatever shape they take, be it in JSON:

In string literals:

And even in anonymous type declarations:

Searching for a CSS attribute has got a lot smarter, too. For example, searching for the color Red will yield all locations in CSS, JavaScript and C# where this color is used, however it may be defined:

Finally, ReSharper now supports refactorings such as the renaming of identifiers defined in CSS:

Assembly Explorer

Those of you who know dotPeek, our free decompiler, have already seen the Assembly Explorer – a window similar to the Solution Explorer that lets you explore decompiled assemblies. The great news is that now Assembly Explorer is part of ReSharper, too:

In addition to being able to load assemblies via its user interface, ReSharper also offers an option to Locate in Assembly Explorer, which will select the item currently being decompiled in the Assembly Explorer window:

The Assembly Explorer is a very powerful tool, capable of locating assemblies in various file formats (e.g., ZIP files). It’s also very extensible, a fact appreciated by dotPeek plugin writers. Its capabilities are now open for you to extend, right within ReSharper.

BAML Decompiler

While we’re on the subject of decompilation, ReSharper now supports BAML decompilation, so if you’ve got a compiled WPF app, you can easily look at its XAML UI definitions:

Note that the generated XAML above supports typical features such as navigation, Find Usages and other features one would expect from a XAML viewer.

Odds and Ends

Just a few more things that are worth mentioning.

We have made adjustments to the formatter and Code Cleanup in order to treat preprocessing directives such as #if and #region correctly. This means that constructs such as

will now correctly survive in case you execute the formatter or Code Cleanup on the file.

In addition to ReSharper as a plug-in, we are also providing a command-line tool that can be used to analyze an existing VS solution. This happens to be the tool that TeamCity uses to present ReSharper analyses. We are currently offering it as a separate, time-limited download and will be putting up new releases together with forthcoming EAP versions.

Finally, we are working hard on bringing you TypeScript support in ReSharper! It’s still too early to announce any features for it, but rest assured that it’s high in our priorities and we’ll let you know as soon as it’s ready.

Now that you’ve seen some of the features that ReSharper 8 will have, why not give them a go? Simply download the EAP and let us know what you think!

Using ReSharper with MonoTouch Applications

Friday, February 8th, 2013

There is no denying that, with the rising popularity of Apple-made devices, iOS development has seduced a large number of developers. If you look at the TIOBE index, you will easily note that Objective-C, the primary iOS development language, stands very close to the top. In fact, its popularity has inspired us to create a separate IDE called AppCode.

However, not everyone wants to learn a new language. C# developers, specifically, are very comfortable in their language and a proportion of them is reticent to abandon their knowledge and experience in favor of a language with different capabilities and features. It is specifically for that crowd that Xamarin has created the MonoTouch framework.

MonoTouch is a way for iOS developers to use the C# programming language to develop iOS apps. MonoTouch provides both a chunk of the familiar .NET Framework libraries (for example, you can use System.DateTime) as well as wrappers around the iOS APIs. MonoTouch uses MonoDevelop as its primary IDE, although UI design must still be done in Xcode.

But what does this all have to do with ReSharper?

VSMonoTouch

However great MonoDevelop is, many MonoTouch developers would still prefer to use the familiar VS+ReSharper pairing to do their coding in. Luckily, a project called VSMonoTouch allows this exact thing to happen. What it does is allow you to open MonoTouch projects in Visual Studio 2010 or 2012, do your work, and then save the files to be reopened in MonoDevelop.

To install MonoTouch, you need to:

  • If you’re using Visual Studio 2010, simply get the VSMonoTouch installer and run it. If you are using VS2012, you will need to build one of the forks of the VSMonoTouch project and compile it manually.
  • Copy files from /Developer/MonoTouch/usr/lib/mono/2.1/ on your mac to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v1.0 on your PC
  • Add a RedistList folder under your newly created v1.0-folder. Download the FrameworkList.xml file and add it to the RedistList folder.

MonoTouch Projects in VS

After installing VSMonoTouch, you can open a MonoTouch project in Visual Studio and it should load:

After opening the project, ReSharper kicks in straight away. You get full code completion for the libraries:

As well as navigation, refactorings and pretty much any feature you can think of.

This even includes decompilation, although since many of the API calls are simply forwarded calls to Objective-C messaging, this is of limited benefit.

Staying in Sync

The workflow for working with VSMonoTouch is therefore as follows:

  • Create a project in MonoDevelop (on a Mac)
  • Install VSMonoTouch (on Windows)
  • Open the project in Visual Studio
  • Get back to MonoDevelop when you need to compile or edit the UI (.xib)

This scheme naturally implies some sort of synchronization between the Mac and the PC. A shared drive will certainly do the trick, but so will DropBox or any synchronized file storage. Given that the file sizes are (typically) very small, file synchronization should be near-instant, allowing you to jump back and forth between OSX and Windows with ease.

Visual Studio 2012 note: projects saved in VS2012 will not open by default due to the fact that MonoDevelop uses VS2010-based project version numbers. Thus, to open the project in MonoDevelop once you’re done with it requires that you manually edit the .sln file and reduce the version number back to a value that MonoDevelop likes.

Conclusion

This approach to iOS application development may seem a bit cumbersome: the idea of installing special libraries and hopping between OSX and Windows will not appeal to everyone. However, the benefits of such an approach easily outweigh the efforts, allowing you to keep your investment in your C# skills and your .NET tooling, while at the same time allowing you to target one of the most popular mobile development platforms out there.

ReSharper SDK Adventures Part 9 — Update notifications

Wednesday, January 30th, 2013

Welcome to another part of the ReSharper SDK Adventures! One of the problems that many plugin developers face is in being able to update their plugins after they are released, so in this post we’ll take a look at how you can do that with simple update notifications.

Update Notifications

Update Notifications are already used by at least two ReSharper plugins – the NuGet plugin and ForTea.

The user gets informed about plugin updates in two ways. First, there is the Updates tab in ReSharper Options that shows a listing of all the plugins that have pending updates:

And then there’s a periodic check that ReSharper does. If a plugin has been updated, it will pop up a dialog box to let you know:

At the time of writing, the notification mechanisms are different, so we’re going to consider Nuget’s implementation here. Essentially, the mechanism for update notification is as follows:

  • Once every 24 hours, a special XSLT file is downloaded from a location of the plugin developer’s choosing.

  • This XSLT file is applied to certain data taken from the environment in order to determine if anything has changed.

  • If something has in fact changed, an update location is acquired and a corresponding update dialog is displayed.

Please note: update notifications are not the same as automatic updates. Even though the user is informed about the new version being available, it is their responsibility to download and install the updated plugin – you are simply providing the download link.

Let’s go through each of the files in turn and discuss what’s going on. I’m going to keep the links to the NuGet project here so that you can quickly see the whole file if you need to.

UpdateNotifier.cs

The update notification shell component (source) is the component responsible for providing the data from the updates. All of its operations happen in the constructor. At least two things need to be injected into the constructor — the Lifetime of whoever instantiated the component, and an UpdatesManager, which is the ReSharper component responsible for handling updates.

Inside the constructor, we first create a URI where our magic XSLT file is stored. We’ll discuss the contents of the XSLT file soon, but for now it’s just important to remember that this XSLT is appled to (an XML representation of) a set of variables to determine whether a change is required:

The above file must obviously be accessible on the web. Note the use of raw.github.com above – the path might be useful if you’re also hosting a project on GitHub.

Now that we have the URI, we ask the UpdatesManager that we injected to give us a category that’s related to our plugin:

With the category acquired, we can now proceed to customize the local environment settings for the duration of the lifetime of our component (which is equivalent to the lifetime of the shell). Specifically, what we want to do is customize the local environment information that the XSLT is applied to:

Let’s discuss the above code. Two things are happening:

  • First, we check that the type of argument that we are customizing is indeed of type UpdateLocalEnvironmentInfoVs.

  • Second, if it is, we overwrite it with our own definition, which incorporates both the original environment and information about our plugin.

The class PluginLocalEnvironmentInfo from above is also of our own making, and is simply an aggregation of environment info and our plugin info. The class is decorated with appropriate metadata so as to allow subsequent serialization and application of the XSLT file:

We store the plugin version in a special structure called VersionSubInfo, and it’s acquired in our case via the GetThisVersion() call which simply takes the version of our plugin assembly:

Finally, the constructor is finished off with the following call:

This requires a bit of an explanation. ReSharper typically downloads and evaluates the XSLT on a regular basis, but doesn’t re-evaluate it after an install. As a result, if there is a reminder out there to download this or older version of the plugin, we remove it:

And that’s it for the update notification component!

Updates.xslt

The second piece of the puzzle is the update XSLT file. Behind the scenes, the data that we provide ReSharper via PluginLocalEnvironmentInfo gets serialized into XML, and then this XSLT is applied to it. If the latest plugin version number has changed, the XSLT provides ReSharper with new data regarding where the updated version lives, who makes it, how much it costs, and so on.

Rather than show the whole thing, let’s discuss all the important bits. First of all, the XSLT contains version numbers for the latest version that’s available currently. You update this number when you release a new version of your plugin.

The XSLT is solely responsible for telling ReSharper that an update is needed. To determine this, it queries the current plugin versions:

It then does a simple if check to see if something has changed and, if it has, it needs to provide ReSharper with a new <UpdateInfo> structure that contains all the relevant information about the new version.

I won’t list the contents of the <UpdateInfo> structure here — if you’re interested, please take a look at the updates.xslt file of the NuGet plugin. The only thing I want to point out is that the icon specified in the <IconData> element is simply a base64 representation of a PNG file. Keep in mind that UpdateInfo is, in its original form, a .NET class located in the JetBrains.UI.Updates namespace — you can use this class to figure out which XML elements can be provided, and what they are used for (the class has extensive documentation).

Hint: to find out more about what the update manager is doing behind the scenes, you can peek at the %LOCALAPPDATA%\JetBrains\ReSharper\v7.1\UpdatesManager.xml file. This file contains information about all the plugins that ReSharper tries to update, and ReSharper itself, of course!

Conclusion

Implementing update notifications for ReSharper plugins is not that difficult — simply take the existing files, tweak them a little and you’ve got a mechanism for automatically letting your users know that an update is available. So go ahead, implement this in your plugin right now — your users will appreciate it! ■

Agent Mulder - supporting IoC in ReSharper

Thursday, January 24th, 2013

The almost pervasive use of IoC containers in modern-day enterprise apps presents a special challenge to ReSharper. After all, how can ReSharper possibly know that a type, which for all intents and purposes appears to be unused, is actually configured to be instantiated implicitly by using a dependency injection mechanism?

Some might say that this is impossible, since the wide variety of IoC containers coupled with various distinct initialization options make the detection of component initialization a real challenge. This challenge was met, however, by Igal Tabachnik (@hmemcpy), the creator of the Agent Mulder plugin.

At the time of writing, Agent Mulder supports the following containers:

  • Castle Windsor

  • NInject

  • Unity

  • Autofac

  • StructureMap

  • Catel IoC

Depending on the container in question, Agent Mulder supports two types of component registration:

  • Manual registration involves registering a single component type in the container. This is typically done by providing the component’s type, so for example with Unity one might invoke RegisterType<Foo>() or RegisterType(typeof(Foo),...) to add the component to the container.

  • Convention-based registration allows bulk registration of components in the container via a particular method. For example, Autofac’s InNamespaceOf<T>() method allows the user to register all types that can be found inside the namespace inhabited by type T.

While it is technically infeasible for Agent Mulder to support every variety of configuration in every container, it does manage to cover a very large percentage of configuration options in the aforementioned containers, as documented in its Wiki pages. But, apart from analyzing container registrations, what does the plugin actually do?

Ultimately, Agent Mulder does three things:

  • The main goal of Agent Mulder is to suppress unused ispections when a container-registered component does not appear to be instantiated.

  • In addition, Mulder also uses a gutter mark to indicate a container-registered component. One can click this gutter mark to navigate to the exact line where this component is registered:

  • Finally, one can also navigate to registered component right from the statement that performs the registration:

Mulder is an open-source plugin hosted on GitHub. It appears to have an active user base, so if you are interested in, say, a container it doesn’t support, feel free to open a request or implement it yourself and send a pull request. Meanwhile, have fun with IoC and stay tuned for more plugin reviews!

R2P: A General-Purpose ReSharper Plugin

Wednesday, January 16th, 2013

R2P (short for ‘Refactoring to Patterns’) is a plugin that embodies a collection of features of a fairly experimental nature. It does not have a single theme but, rather, tries to do different things in different areas of ReSharper. Let’s take a look at some of the things it does.

String Mutations

One of the key features of R2P is the ability to transform string literals. For example, the string splicing feature brings PHP-style string splicing to C#. Simply use the curly braces to delimit variables and R2P will offer a suitable context action:

Applying the action replaces the string with a string.Format() call, with the variables moved to the argument list:

R2P supports several transformations from strings to .NET types. For example, you can define time as a string and convert it to DateTime:

After invocation, the declaration is replaced with the following:

R2P supports transformations from string literals into the following types:

  • DateTime

  • TimeSpan

  • XElement

R2P also comes with a menu item called Paste Verbatim String that pastes strings from the clipboard with correct escapement. This facilitates transformations from strings into something else: for example, you can copy a block of XML from some app, paste it, then use the Convert to XElement context action to turn it into a fully object-oriented declaration.

In addition to the above, the plugin also supports a few string manipulations, such as:

  • HTML-encoding/decoding of a string.

  • String obfuscation using base64 encoding.

Code Generation

The plugin comes with several generators, which all embed themselves into the Generate menu:

  • Binary read/write members — for a given class, generates ReadFrom() and WriteTo() methods that use BinaryReader and BinaryWriter respectively and serialize chosen fields. Special care is taken when serializing known .NET types: for example, for a DateTime, only its Ticks property is serialized:

  • Copy constructor — for a given class creates a constructor that takes this class as a parameter and performs a copy of its properties/fields to the owner class.

  • Disposing members — in addition to being able to correctly identify all disposable fields and generate the appropriate Dispose() declaration, R2P’s implementation also offers to implement the full Dispose pattern.

  • Read-only interface — for a given class Foo, generates an interface IFoo where all properties are exposed as get-only, effectively creating a read-only interface contract for this class.

Code Inspections

R2P comes with several computation-related inspections, such as:

  • Inspections that detect inefficient Math.Pow() calls and refactor them to unline multiplication:

  • An inspection and corresponding context action that allows factoring out of common subexpressions:

  • Inspections and fixes relating to possible use of MAD (multiply-add) instruction when using GPU.NET:

In addition, R2P can help correct misspelt identifiers based on information about the available types:

Odds and Ends

R2P comes with a lot more functionality than we can list here. Some of its features include:

  • Refactorings such as Make Singleton (implements the Singleton pattern) and Enum to Class (turns an enumeration into a class with enum cases transformed to member variables).

  • Unit testing helpers such as being able to Assert on all public properties of an object instance, an ability to add a value as a Row in data-driven testing, and a Visual row editor.

  • General-purpose context actions such as code contract generators (generate code contract specifications for parameters), an action to make a method fluent (i.e., return this), and even a context action to treat the ^ operator as a power function.

  • A String format helper window that lets the user build a format string and preview the end result.

  • … and a lot more

R2P is distributed under a commercial license. For more information, head over to its product site and stay tuned for more plugin reviews!