0

Resharper has great feature of adding null check code for arguments. For strings it can add string.IsNullOrWhiteSpace check with ArgumentException. Everything's fine, but I need to have Resharper generate another message, and not Value cannot be null or whitespace as it does by default. Instead of this, I want to have Value cannot be null, empty, or consist only of white-space characters message. In the Null checking configuration tab I didn't find anything related to string checks. Is there some other place to configure the message?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108

1 Answers1

1

This seems to be not possible with current ReSharper version (2019.1.2).

I checked JetBrains.ReSharper.Intentions.CSharp.dll with ildasm and it seems that the strings "Value cannot be null or whitespace." and "Value cannot be null or empty." are hardcoded and not customizable.

JetBrains.ReSharper.Intentions.CSharp.ContextActions.CheckParameters.StringParameterIsNotNullOrEmptyCheckAction's get_ExceptionMessage method:

.method /*06001927*/ family hidebysig specialname virtual 
        instance string  get_ExceptionMessage() cil managed
// SIG: 20 00 0E
{
  // Method begins at RVA 0x82f24
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  /* 72   | (70)017EBE       */ ldstr      "Value cannot be null or empty." /* 70017EBE */
  IL_0005:  /* 2A   |                  */ ret
} // end of method StringParameterIsNotNullOrEmptyCheckAction::get_ExceptionMessage

JetBrains.ReSharper.Intentions.CSharp.ContextActions.CheckParameters.StringParameterIsNotNullOrWhitespaceCheckAction's get_ExceptionMessage method:

.method /*0600192D*/ family hidebysig specialname virtual 
        instance string  get_ExceptionMessage() cil managed
// SIG: 20 00 0E
{
  // Method begins at RVA 0x82f5f
  // Code size       6 (0x6)
  .maxstack  8
  IL_0000:  /* 72   | (70)017F4C       */ ldstr      "Value cannot be null or whitespace." /* 70017F4C */
  IL_0005:  /* 2A   |                  */ ret
} // end of method StringParameterIsNotNullOrWhitespaceCheckAction::get_ExceptionMessage

If this feature is important for you, then you can try and request it by filing a ticket in JetBrains' bug tracker: https://youtrack.jetbrains.com

Szabolcs Dézsi
  • 8,743
  • 21
  • 29