-
Notifications
You must be signed in to change notification settings - Fork 66
Open
Labels
LDM Reviewed: No plansLDM has reviewed and this feature is unlikely to move forward in the foreseeable futureLDM has reviewed and this feature is unlikely to move forward in the foreseeable futureProposal
Description
Generally, the word In make sense for these situations:
- Dictionary has the Key?
- Collection contains the element?
- Number in a specific range?
- File exists in a directory?
- Resource exists in a specific source?
So that by introduce the existed In keyword As a new operator, then we can makes the vb code more simple and human natural Language:
Public Class TableType
Dim table As New Dictionary(Of String, Integer)
Public Shared Operator In(key$, table As TableType) As Boolean
Return table.table.ContainsKey(key)
End Operator
End Class
Dim c As New TableType
Dim x$
If x In c Then
End IfPublic Class CollectionType
Dim list As New List(Of Integer)
Public Shared Operator In(x%, list As CollectionType) As Boolean
Return list.list.IndexOf(x) > -1
End Operator
End Class
Dim c As New CollectionType
Dim x%
If x In c Then
End IfPublic Class IntRange
Dim range%()
Public Shared Widenning Operator CType(l%()) As IntRange
Return New IntRange With {
.range = l
}
End Operator
Public Shared Operator In(x%, r As IntRange) As Boolean
Return Array.IndexOf(r.Range, x) > -1
End Operator
End Class
' If [1: 10] means integer range 1 to 10, then we can
Dim x%
If x In [1:10] Then
End If And combine this new In keyword with the Linux bash file search API syntax in VisualBasic language:
to makes the VB style in more Natural Language
Public Class Directory
Dim DIR$
Public Shared Widening Operator CType(DIR$) As Directory
Return New Directory With {
.DIR =DIR
}
End Operator
Public Shared Operator In(file$, DIR As Directory) As Boolean
Return (ls -r <= DIR).IndexOf(file.BaseName) > -1
End Operator
End Class
' In another style
Public Class Directory
Dim files As CollectionType(Of String)
Public Shared Widening Operator CType(DIR$) As Directory
Return New Directory With {
.files = (ls -l -r -"*.*" <= DIR)
}
End Operator
Public Shared Operator In(file$, DIR As Directory) As Boolean
Return file$ In DIR.files
End Operator
End Class
Dim file$
Dim DIR As Directory = "C:\test"
If file In DIR Then
End If
If file$ In (ls -l -r -"*.xml" <= "D:\data\") Then
End If
' or even more simple
Public Class File
Dim file$
Public Shared Operator In (file As File, DIR$) As Boolean
With file
Return (ls -l -r - .File.ExtensionName <= DIR).IndexOf(.File) > -1
End With
End Operator
End Class
Dim file As File
If file In "C:\test\" Then
End IfCompared with the List.IndexOf, Dictionary.ContainsKey, In keyword operator just using 2 character in our code, simple and make sense.
reduckted and zspitz
Metadata
Metadata
Assignees
Labels
LDM Reviewed: No plansLDM has reviewed and this feature is unlikely to move forward in the foreseeable futureLDM has reviewed and this feature is unlikely to move forward in the foreseeable futureProposal