tags:

views:

168

answers:

4

Hi, I'm wondering how this can be converted to VB.NET.

private void RaiseStreamVolumeNotification()
    {
        if (StreamVolume != null)
        {
            StreamVolume(this, new StreamVolumeEventArgs() { MaxSampleValues = (float[])maxSamples.Clone() });
        }

    }

public class StreamVolumeEventArgs : EventArgs
{
    public float[] MaxSampleValues { get; set; }
}

I'm trying to convert it using an online converter, but either it fails, or it converts it incorrectly. One converter, which I think is the best one, converts it to this:

Public Class StreamVolumeEventArgs
    Inherits EventArgs
Private _MaxSampleValues As Single()
    Public Property MaxSampleValues() As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(ByVal value As Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class
A: 

Have you tried converting them separately? You have a function which appears to be outside of any class, followed by a class, all in the same codespace.

Your function should convert to

Private Sub RaiseStreamVolumeNotification()

    RaiseEvent StreamVolume(Me, New StreamVolumeEventArgs(){ .MaxSampleValues = maxSamples.Clone() })
End Sub

Your class should convert to

Public Class StreamVolumeEventArgs
    Inherits EventArgs
Private _MaxSampleValues As Single()
    Public Property MaxSampleValues() As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(ByVal value As Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class
Jason Irwin
A: 

Try this (assuming VS2008 / VB9)

Public Sub RaiseStreamVolumeNotification() 
  Raise StreamVolume(Me, New StreamVolume() { .MaxSampleValues = maxSamples.Clone() })
End Sub

Public Class StreamVolumeEventArgs
  Inherits EventArgs

  Private _maxSampleValues As Float()
  Public Property MaxSampleValues As Float()
    Get
      Return _maxSampleValues
    End Get
    Set (value As Float())
      _maxSampleValues = value
    End Set
  End Property

End Class
JaredPar
+1  A: 

There might be some slight issues.

Private Sub RaiseStreamVolumeNotification()
        Dim SVEA As New StreamVolumeEventArgs()
        SVEA.MaxSampleValues = CType(maxSamples.Clone(), Single())
        If Not StreamVolume Is Nothing Then
            StreamVolume(this, SVEA)
        End If
End Sub

Public Class StreamVolumeEventArgs Inheirits EventArgs
    Private _MaxSampleValues As Single()
    Public Property MaxSampleValues As Single()
        Get
            Return _MaxSampleValues
        End Get
        Set(value as Single())
            _MaxSampleValues = value
        End Set
    End Property
End Class
Spencer Ruport
It's much more idiomatic to use Raise in VB.Net as opposed to the Is nothing check on the event
JaredPar
A: 

SharpDevelop (aka #Develop) has an excellent code converter. It can be used for converting single files or whole projects.

Unfortunately in this case our converter doesn't work so well - in the C# -> VB direction, most new C# 3.0 constructs are not yet supported.
Daniel