My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 13, 2008 by resharperagentjohnson
ConfigureValueAnalysis  

Value Analysis and Assertions are configured in Resharpers Options dialog in the Assertions and Value Analysis page.

Options are configure per type - that is, you can configure a set of options for System.Object and a different set for System.String.

The * and System.Object rules are default rules that are used, if no other rules are found.

In the Options start by adding a new rule. In the Rule options box, specify the type for which this rule should apply. Next specify which Value Analysis attribute should be applied by default. Then specify assertion statements for parameters, assignments and return values.

The assertions are formatted using string.Format, so use {0} to substitute the name of the variable.


Comment by silmaril.acc, Jul 09, 2009

I spent some time in order to make this feature work properly. If you have problems like message "Type members should be annotated with Value Analysis attributes." when you already annotate all args then you will need to do this:

  1. Go to Resharper options -> code annotations. Click on "Copy default implementation to clipboard" button
  2. Paste code to empty .cs file and attach it to you project
  3. !IMPORTANT! change namespace from "Jetbrains.Annotations" to any custom, for example "Sitecore.Annotation"
  4. In resharper annotation settings in "Namespaces with code annotation attributes" check "Sitecore.Annotation" and choose "Sitecore.Annotation" in "Default annotation namespace"
  5. You will need to create some assertion methods, for example: Sitecore.Diagnostics.Assert.ArgumentNotNull(T obj, string argumentName);
  6. !IMPORTANT! You will need annotate this assertion methods with Resharper annotation attributes, for example:
  7.         [AssertionMethod]
            public static void ArgumentNotNull<T>([AssertionCondition(AssertionConditionType.IS_NOT_NULL)]T obj, string argumentName) where T : class        
    		{            
    			//you assertion logic here        
    		}

Hope this helps


Sign in to add a comment
Hosted by Google Code