Class Cs.UnsafeStatement

java.lang.Object
org.openrewrite.csharp.tree.Cs.UnsafeStatement
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.UnsafeStatement extends Object implements Cs, org.openrewrite.java.tree.Statement
Represents a C# unsafe statement block which allows direct memory manipulation and pointer operations. Code within an unsafe block can perform operations like pointer arithmetic, fixed-size buffers, and direct memory access.

For example:

     // Basic unsafe block
     unsafe {
         int* ptr = &value;
     }

     // Unsafe with pointer operations
     unsafe {
         int* p1 = &x;
         int* p2 = p1 + 1;
         *p2 = 100;
     }

     // Unsafe with fixed buffers
     unsafe {
         fixed (byte* ptr = bytes) {
             // Direct memory access
         }
     }

     // Unsafe with sizeof operations
     unsafe {
         int size = sizeof(CustomStruct);
         byte* buffer = stackalloc byte[size];
     }
 
  • Constructor Details

    • UnsafeStatement

      public UnsafeStatement()
  • 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