I have a code snipped I converted from c# to vb.net. However, the vb.net code does not allow me to query if an Event is instantiated. Here's the c# code:
public event EventHandler<TreeModelEventArgs> NodesInserted;
internal void OnNodeInserted(Node parent, int index, Node node)
{
if (NodesInserted != null)
{
TreeModelEventArgs args = new TreeModelEventArgs(GetPath(parent), new int[] { index }, new object[] { node });
NodesInserted(this, args);
}
}
The specific line it 'acks' on is:
if (NodesInserted!= null)
Here's the vb.net code:
Public Event NodesInserted As EventHandler(Of TreeModelEventArgs) Implements ITreeModel.NodesInserted
Friend Sub OnNodeInserted(parent As Node, index As Integer, node As Node)
If NodesInserted IsNot Nothing Then
Dim args As New TreeModelEventArgs(GetPath(parent), New Integer() {index}, New Object() {node})
RaiseEvent NodesInserted(Me, args)
End If
End Sub
Specifically:
If NodesInserted IsNot Nothing Then
Returns an error, saying that I should use RaiseEvent, which of course I am using already.
My question is, do I even need to check for null? How could an event in c# ever be called if it didn't exist? I'm thinking I should just remove the 'If' statement, but this is a complicated project, and I might be missing something. Can an expert help me?