The project I have currently has code analysis rules turned on that check to make sure the format provider is set for every String.Format statement.  For the most part, I will pass CultureInfo.InvariantCulture as the first argument to String.Format.  CodeRush allows me to do a String.Format by typing in s.f as a template in a code block.

Currently s.f expands to:

  1. String.Format(“”, )

What I would like to see is:

  1. Syntax:  String.Format(CultureInfo.InvariantCulture, “”, )
  2. The using statement for System.Globalization to be added if it doesn’t exist

This is extremely easy given an alternate expansion.  I must thank Mark Miller and Rory Becker at DevExpress for the insight that they have given.

Steps to create an alternate expansion

Locate the expansion for fmt (s.f calls this alias)  in DevExpress – Options –Editor–Templates.  You can search for fmt or find it under the Text commands folder


Right-click on the template and select create duplicate.  It will ask for a name, keep the default text.


When you have done this the fmt node should look like this:


Note:  Order matters.  If you change the second fmt, it will only get called if the first fmt context conditions are not met.  You can move expansions up and down by selecting the expansion and using the buttons below:


Change the text of the first expansion from:




Lastly, add a dependent Namespace


Choose Ok and Test it out!

Kudos to DevExpress

It is nice when a company opens themselves up to questions from their customers.  Mark and Rory are awesome at providing top notch customer service.  Be sure to check out their videos at the DevExpress Channel.