C# String.format extension method
- by Paul Roe
With the addtion of Extension methods to C# we've seen a lot of them crop up in our group. One debate revolves around extension methods like this one:
public static class StringExt
{
/// <summary>
/// Shortcut for string.Format.
/// </summary>
/// <param name="str"></param>
/// <param name="args"></param>
/// <returns></returns>
public static string Format(this string str, params object[] args)
{
if (str == null) return null;
return string.Format(str, args);
}
}
Does this extension method break any programming best practices that you can name? Would you use it anyway, if not why? If I renamed the function to "F" but left the xml comments would that be epic fail or just a wonderful savings of keystrokes?