Class Cs.DiscardPattern

java.lang.Object
org.openrewrite.csharp.tree.Cs.DiscardPattern
All Implemented Interfaces:
Cs, Cs.Pattern, org.openrewrite.java.tree.Expression, org.openrewrite.java.tree.J, org.openrewrite.Tree
Enclosing interface:
Cs

public static final class Cs.DiscardPattern extends Object implements Cs.Pattern
Represents a C# discard pattern (_), which matches any value and discards it.

For example:

     // Simple discard pattern in is expression
     if (obj is _)

     // In switch expressions
     return value switch {
         1 => "one",
         2 => "two",
         _ => "other"    // Discard pattern as default case
     };

     // With relational patterns
     if (value is > 0 and _)

     // In property patterns
     if (obj is { Id: _, Name: "test" })
 
  • Constructor Details

    • DiscardPattern

      public DiscardPattern()
  • 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.Expression getCoordinates()
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Expression