11[ TestFixture ] 
22public  class  ConstantExpectedTests 
33{ 
4-     public  static void  MyBool1 ( [ ConstantExpected ]  bool  b )  {  } 
5-     public  static void  MyLong1 ( [ ConstantExpected ]  long  b )  {  } 
6-     public  static void  MyLong2 ( [ ConstantExpected ( Min  =  - 5 ,  Max  =  10 ) ]  long  b )  {  } 
7-     public  static void  MyFloat1 ( [ ConstantExpected ]  float  b )  {  } 
8-     public  static void  MyFloat2 ( [ ConstantExpected ( Min  =  - 5.3f ,  Max  =  10.1f ) ]  float  b )  {  } 
4+     public  static void  Method ( [ ConstantExpected ]  int  b )  {  } 
5+     public  static void  MethodWithMinMax ( [ ConstantExpected ( Min  =  - 5 ,  Max  =  10 ) ]  int  b )  {  } 
96
10-     // Might want to warn for the negative values and out of range values 
11-     // public static void MyInvalidUshort([ConstantExpected(Min = -5, Max = -1)] ushort b) { } 
12-     // public static void MyInvalidRange([ConstantExpected(Min = 5, Max = -5)] int b) { } 
13-     // flag any ref type usage as not applicable 
14-     public  static void  MyString ( [ ConstantExpected ]  ref  string  b )  {  } 
7+     // Invalid declaration 
8+     // public static void InvalidRange([ConstantExpected(Min = 5, Max = -5)] int b) { } 
159
16-     // Diagnostics examples 
17-     public  static void  Test ( long  b ,  ushort  u ) 
10+     public  static void  Test ( int  variableNum ) 
1811    { 
19-         // OK 
20-         const  long  a  =  10 ; 
21-         MyLong1 ( a ) ; 
22-         MyLong2 ( a ) ; 
23-         MyLong1 ( 1L ) ; 
24-         MyLong2 ( 2L ) ; 
25-         //MyInvalidUshort(1); 
26-         //const ushort us = 0; 
27-         //MyInvalidUshort(us); // Flag 
12+         // Valid calls 
13+         const  int  constNum  =  10 ; 
14+         Method ( constNum ) ; 
15+         MethodWithMinMax ( constNum ) ; 
16+         Method ( 1 ) ; 
17+         MethodWithMinMax ( 2 ) ; 
2818
29-         //MyLong1(b); // Flag 
30-         //MyLong2(b); // Flag 
31-         //MyLong2(20); // Flag, out of range 
32-         //MyInvalidUshort(u); // Flag 
33-         //MyInvalidUshort(10); // Flag, out of the range 
19+         // Invalid calls 
20+ 
21+         // CA1857: The argument should be a constant for optimal performance 
22+         // https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1857 
23+         // Method(variableNum); 
24+ 
25+         // CA1857: The constant does not fit within the value bounds of '-5' to '10' 
26+         // https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1857 
27+         // MethodWithMinMax(15); 
3428    } 
3529} 
0 commit comments