Documentation

Documentation
V5 Documentation

RDI Inline Directives

The behaviour of NCrunch RDI can be controlled for blocks of code using inline comments, in a similar manner to code coverage suppression comments.

This allows RDI data collection to be tuned to specific regions that benefit from higher data limits, or perhaps need to have RDI disabled for performance or compatability reasons.

Inline directives follow a specific pattern in the code. They start with a comment indicating the setting change required, then usually end with another comment restoring the setting to its default value.

public class InlineDirectiveExample
{
    //ncrunch: rdi off
    public void ThisMethodHasRdiDisabled()
    {
        Console.WriteLine("No RDI data collection");
    }
    //ncrunch: rdi default
    
    //ncrunch: method data limit unlimited
    public string ThisMethodHasNoDataLimit()
    {
        StringBuilder result = new StringBuilder();
        
        for (int i = 0; i < 100000; i++)
            result.Append("All of this data is collected and will be available in the RDI overlay");
            
        return result.ToString()
    }
    //ncrunch: method data limit default
    
    //ncrunch: string length limit 30
    public string ThisMethodHasACustomStringLengthLimit()
    {
        StringBuilder result = new StringBuilder();        
        result.Append("The length of this string will be limited to 30 characters when captured and reported by RDI");
        return result.ToString()
    }
    //ncrunch: string length limit default
}

When no closing comment is used to restore the setting to default, the setting change remains in place for the rest of the source file.

Available Directives

The following RDI inline directives are available:

  • rdi off: Disables RDI for the code region
  • rdi on: Enables RDI for the code region. Note that this will not enable RDI if it has been switched off using the Enable RDI config setting.
  • rdi default: Restores RDI enable/disable to the default setting
  • method data limit unlimited: Disables the RDI method data limit for the code region
  • method data limit (size): Sets the RDI method data limit to the specified size (in bytes) for the code region
  • method data limit default: Restores the default RDI method data limit
  • string length limit unlimited: Disables the RDI string length limit for the code region
  • string length limit (size): Sets the RDI string length limit to the specified size (in chars) for the code region
  • string length limit default: Restores the default RDI string length limit
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download