Class Cs.CheckedStatement

java.lang.Object
org.openrewrite.csharp.tree.Cs.CheckedStatement
All Implemented Interfaces:
Cs, org.openrewrite.java.tree.J, org.openrewrite.java.tree.Statement, org.openrewrite.Tree
Enclosing interface:
Cs

public static final class Cs.CheckedStatement extends Object implements Cs, org.openrewrite.java.tree.Statement
Represents a C# checked statement which enforces overflow checking for arithmetic operations and conversions. Operations within a checked block will throw OverflowException if arithmetic overflow occurs.

For example:

     // Basic checked block
     checked {
         int result = int.MaxValue + 1; // throws OverflowException
     }

     // Checked with multiple operations
     checked {
         int a = int.MaxValue;
         int b = a + 1;     // throws OverflowException
         short s = (short)a; // throws OverflowException if out of range
     }

     // Nested arithmetic operations
     checked {
         int result = Math.Abs(int.MinValue); // throws OverflowException
     }
 
  • Constructor Details

    • CheckedStatement

      public CheckedStatement()
  • Method Details

    • acceptCSharp

      public <P> org.openrewrite.java.tree.J acceptCSharp(CSharpVisitor<P> v, P p)
      Specified by:
      acceptCSharp in interface Cs
    • getCoordinates

      public org.openrewrite.java.tree.CoordinateBuilder.Statement getCoordinates()
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Statement