Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VB] Patterns / Additional Case Clauses #13440

Closed
AdamSpeight2008 opened this issue Aug 29, 2016 · 3 comments
Closed

[VB] Patterns / Additional Case Clauses #13440

AdamSpeight2008 opened this issue Aug 29, 2016 · 3 comments

Comments

@AdamSpeight2008
Copy link
Contributor

Is VB going to support patterns?
What about guard clauses? eg Case ... .... When boolEpxr
What about type matching and value manifesting? eg TypeIs String As str
How will tuple clause be handled?

Select Case obj
  Case TypeIs String As str When str IsNot Nothing
    ' do stuff
  Case ( TypeIs Boolean As valid, TypeIs Int32 As i32 ) When ( valid AndAlso ( i32 > 0 ) )
   ' manifesting into Tuple(Of Boolean, Int32 ), which has named elements ( valid:= , i32:= ) 
End Select
@AdamSpeight2008 AdamSpeight2008 changed the title VB Patterns / Additional Case Clauses [VB] Patterns / Additional Case Clauses Aug 29, 2016
@markhurd
Copy link

BTW In VB would that When str IsNot Nothing clause be redundant like I believe it would be in C#'s scenario? Clearly, VB has different issues regarding Nothing when considering strings, but has this been confirmed (because it definitely makes some sense for other reference types to not match Nothing)?

@AdamSpeight2008
Copy link
Contributor Author

@markhurd not necessarily. It makes more sense to leave the when clause as a general boolean expression.

Select Case obj
  Case TypeIs String As str
   ' Manifests variable, or set value of. eg  str = DirectCast( obj, Sting )
   ' Note: str could be null ( eg default(String) )
    Select Case True

      Case Else When str IsNot Nothing
    ' Handle non null string case

      Case Else When str Is Nothing
    'Handle null string case

    End Select

End Select

'TypeIs obj As T` would be also applicable in if statements.

If TypeIs obj As str Then
  ' str = DirectCast( obj , String )
Else

End If

@AdamSpeight2008
Copy link
Contributor Author

(Ported to VBLang)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants