c# Static Analysis for static methods that modify a provided reference object

39 Views Asked by At

Imagine I have a static class that has a collection of helper functions. I'm attempting to figure out if the contract of these helper functions are strictly input/output or if they have side effects. Is there a good way to do this analysis in an automated way?

For example if I had

//I would not expect to see this show up as causing a side effect        
public static decimal GetRetailValue(ExpressionContext context, object[] validationParameters)
{
     if (context == null)
     {
          return 0;
     }
     return 5;
}

//I would expect to see context.CarValue show up as a side effect of the method     
public static decimal GetRetailValueOfCarToday(ExpressionContext context, object[] validationParameters)
{
     if (context == null)
     {
          if(context.carValueToday != null)
          {
               context.CarValue = context.CarValueToday;
          }
          return context.CarValue;
     }
     return 5;
}
0

There are 0 best solutions below