I have a couple of small classes to represent parts in a search filter. If the searched value equals NonValue
the filter is supposed to do nothing. This is defined in a Base Class:
Private Class BaseFilter
Protected NonValue As Object
Protected sQueryStringBase As String = "AND {0} {1} {2} "
Public Sub CheckNonValue(ByVal QueryItem As Object)
'No Query if Item not valid
If Me.NonValue.Equals(Me.QueryItem) Then
Me.sQueryStringBase = String.Empty
End If
End Sub
End Class
BaseFilter
is then extended for different types of fields:
Private Class StringFilter
Inherits BaseFilter
Protected Shadows NonValue As String = String.Empty
End Class
When I then create a StringFilter and check for allowed value:
Dim stf As New StringFilter()
stf.CheckNonValue(MyString)
I get a NullReferenceException (NonValue = Nothing)
, when I expected the NonValue object to be String.Empty. Is this a bug in my code, or am I trying to achieve polymorphism in a wrong way? Thanks.