Subscribe to The Madman Scribblings        RSS Feed
-----

Playing with VBnext (Roslyn) features.

Icon Leave Comment
Playing with VBnext (Roslyn) features.

Select Case Type Of

This make the already powerful Select Case statement, even more powerful.

Now you can us like in more of match exp with expression of Nemerle and F#.

  Public Function Nod(n As SyntaxNode) As SyntaxNode
    Select Case n
      Case op As OperatorNode
        Select Case op
          Case op1 As UnaryOperator When TypeOf op1 Is ILHS ' Postfix Operator
          Case op1 As UnaryOperator When TypeOf op1 Is IRHS ' Prefix Operator 
          Case op2 As BinaryOperator
          Case op3 As TrianyOperator
          Case Else
        End Select
      Case Else
    End Select
  End Function


Interface ILHS
  ReadOnly Property LHS As SyntaxNode
End Interface
Interface IRHS
  ReadOnly Property RHS As SyntaxNode
End Interface

MustInherit Class SyntaxNode

End Class
MustInherit Class OperatorNode
  Inherits SyntaxNode
End Class
MustInherit Class UnaryOperator
  Inherits OperatorNode
End Class
MustInherit Class BinaryOperator
  Inherits OperatorNode
End Class

MustInherit Class TrianyOperator
  Inherits OperatorNode
End Class



Nemerle-esque code
match n with
{ | op : Operator =>
  { match op with
    { | op1 : UniaryOperator When op1 : ILHS => /* Postfix */
      | op1 : UniaryOperator When op1 : IRHS => /* Prefix  */
      | op2 : BinaryOperator =>
      | op3 : TrianyOperator =>
      | _ => throw UnknownKindOfOperator
    }
  }
  | _ => throw UnknownNodeType 
}

0 Comments On This Entry

 

Search My Blog

Recent Entries

Recent Comments