简体   繁体   English

如何将这些方法从C#转换为VB.net(Windows Phone 7)

[英]How to convert these method from C# to VB.net (Windows Phone 7)

Hi I am looking at a tutorial which uses the camera and I came accross some methods that I need. 嗨,我正在看一个使用相机的教程,我遇到了一些我需要的方法。 Only problem is that they are in C# and I need them to be in VB. 唯一的问题是它们在C#中,我需要它们在VB中。 I have used a converter but it doesnt convert it properly. 我使用过转换器,但它没有正确转换它。

private void VideoCamera_Initialized(object sender, object eventArgs)
{
    if (Initialized != null)
    {
        Initialized.Invoke(this, new EventArgs());
    }
}

public bool LampEnabled
{
    get { return (bool)_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, new object[0]); }
    set { _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, new object[] { value }); }
}

Here is the converted code and the errors: 这是转换后的代码和错误:

Private Sub VideoCamera_Initialized(sender As Object, eventArgs As Object)
    If Initialized IsNot Nothing Then
        Initialized.Invoke(Me, New EventArgs())
    End If
End Sub

Public Property LampEnabled() As Boolean
    Get
        Return CBool(_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, New Object(-1) {}))
    End Get
    Set(value As Boolean)
        _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, New Object() {value})
    End Set
End Property

Errors: 错误:

Error 2 'Public Event Initialized(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. 错误2'公共事件已初始化(sender As Object,e As System.EventArgs)'是一个事件,无法直接调用。 Use a 'RaiseEvent' statement to raise an event. 使用'RaiseEvent'语句来引发事件。

In terms of the second method. 就第二种方法而言。 It doesnt look like its been converted properly even though there isnt any errors 即使没有任何错误,它看起来也没有被正确转换

As the error states, you need to use RaiseEvent ; 正如错误所述,您需要使用RaiseEvent ; code converters don't know if it is, in fact, an event, or if it's a delegate. 代码转换器不知道它实际上是一个事件,还是它是一个委托。 And, of course, since VB.NET is an amazing language, you don't need the Is Nothing check or the New Object(-1) {} , or the New Object() part before {value} . 当然,由于VB.NET是一种了不起的语言,因此在{value}之前不需要Is Nothing检查或New Object(-1) {}New Object()部分。

Private Sub VideoCamera_Initialized(sender As Object, eventArgs As Object)
    RaiseEvent Initialized(Me, EventArgs.Empty)
End Sub

Public Property LampEnabled() As Boolean
    Get
        Return CBool(_videoCameraLampEnabledPropertyInfo.GetGetMethod().Invoke(_videoCamera, {}))
    End Get
    Set(value As Boolean)
        _videoCameraLampEnabledPropertyInfo.GetSetMethod().Invoke(_videoCamera, {value})
    End Set
End Property

将其更改为

RaiseEvent Initialized(Me, EventArgs.Empty)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM