I am trying to write a function that returns a RegExStyle(), I am running into a problem with RegexItem, however. For styles, it looks as though it takes all of the available styles (Area, Text, Line, and Point) but only if they are explicitly designated.
I thought that Style was an interface for this and that I could insert interchangeably any of these styles into the RegExItem but this is not the case. If I specify layerStyle as Style, I get errors of "Overload resolution failed because no accessible 'New' can be found without a narrowing conversion".
I understand why this error is occuring but am wondering if this can be changed or worked around effectively. I do not really want to have to manually overload my function just for the same of addressing these four style types if nothing functionally even changes...
Is there an interface for all of the different 'Styles' or must I overload my function several times to address this? Is this intentional or inadvertant?
Public Shared Function CreateRegExStyleFromLID(ByVal LayerID As Integer, ByVal connString As String, ByVal layerStyle As AreaStyle) As RegexStyle
Dim strSQLForStyle As String = "EXEC sp_GetRegExFromLID " & LayerID
Dim conn As New SqlConnection(connString)
conn.Open()
Dim readerStyle As SqlDataReader
Dim cmdStyle As New SqlCommand(strSQLForStyle, conn)
readerStyle = cmdStyle.ExecuteReader()
Dim regexCustomStyle As New RegexStyle
Dim X As Integer
Try
If readerStyle.HasRows Then
While readerStyle.Read()
If X = 0 Then regexCustomStyle.ColumnName = readerStyle.Item("ColumnName")
'continue here
regexCustomStyle.RegexItems.Add(New RegexItem(readerStyle.Item("RegularExpression"), layerStyle))
X += 1
End While
CreateRegExStyleFromLID = regexCustomStyle
Else
CreateRegExStyleFromLID = Nothing
End If
Catch ex As SqlException
'MsgBox(ex.Message)
CreateRegExStyleFromLID = Nothing
Finally
If Not readerStyle Is Nothing Then readerStyle.Close()
If Not conn Is Nothing Then conn.Close()
End Try
End Function
Also, I noticed when adding multiple Items to the RegexItems, all of my expressions become ignored... If only one expression is entered, it is honored. The two items for example are [^(LYNN)] and [^(NAHANT)]
Why is this? I would ideally like to be able to stack expressions