Class Cs.ConversionOperatorDeclaration

java.lang.Object
org.openrewrite.csharp.tree.Cs.ConversionOperatorDeclaration
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.ConversionOperatorDeclaration extends Object implements Cs, org.openrewrite.java.tree.Statement
Represents a C# operator conversion declaration that defines custom type conversion behavior.
 // Implicit conversion
 public static implicit operator string(MyType t) => t.ToString();

 // Explicit conversion
 public static explicit operator int(MyType t) { return t.Value; }

 // With expression body
 public static explicit operator double(MyType t) => t.Value;

 // With block body
 public static implicit operator bool(MyType t) {
     return t.Value != 0;
 }