Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#到VB的转换问题_C#_Vb.net - Fatal编程技术网

C#到VB的转换问题

C#到VB的转换问题,c#,vb.net,C#,Vb.net,有人能帮我把它转换成vb.net吗?我用的转换器工作不正常,真的不知道如何转换 public Person CurrentPersonCancellable { get { Debug.WriteLine("Getting CurrentPersonCancellable."); return _CurrentPersonCancellable; } set {

有人能帮我把它转换成vb.net吗?我用的转换器工作不正常,真的不知道如何转换

public Person CurrentPersonCancellable
    {
        get
        {
            Debug.WriteLine("Getting CurrentPersonCancellable.");
            return _CurrentPersonCancellable;
        }
        set
        {
            // Store the current value so that we can 
            // change it back if needed.
            var origValue = _CurrentPersonCancellable;

            // If the value hasn't changed, don't do anything.
            if (value == _CurrentPersonCancellable)
                return;

            // Note that we actually change the value for now.
            // This is necessary because WPF seems to query the 
            //  value after the change. The combo box
            // likes to know that the value did change.
            _CurrentPersonCancellable = value;

            if (
                MessageBox.Show(
                    "Allow change of selected item?", 
                    "Continue", 
                    MessageBoxButton.YesNo
                ) != MessageBoxResult.Yes
            )
            {
                Debug.WriteLine("Selection Cancelled.");

                // change the value back, but do so after the 
                // UI has finished it's current context operation.
                Application.Current.Dispatcher.BeginInvoke(
                        new Action(() =>
                        {
                            Debug.WriteLine(
                                "Dispatcher BeginInvoke " + 
                                "Setting CurrentPersonCancellable."
                            );

                            // Do this against the underlying value so 
                            //  that we don't invoke the cancellation question again.
                            _CurrentPersonCancellable = origValue;
                            OnPropertyChanged("CurrentPersonCancellable");
                        }),
                        DispatcherPriority.ContextIdle,
                        null
                    );

                // Exit early. 
                return;
            }

            // Normal path. Selection applied. 
            // Raise PropertyChanged on the field.
            Debug.WriteLine("Selection applied.");
            OnPropertyChanged("CurrentPersonCancellable");
        }
    }

转换器给了我这个,我遇到的问题是它在哪里调用application.Current.Dispather.BeginInvoke

Public Property CurrentPersonCancellable() As Person
Get
    Debug.WriteLine("Getting CurrentPersonCancellable.")
    Return _CurrentPersonCancellable
End Get
Set
    ' Store the current value so that we can 
    ' change it back if needed.
    Dim origValue = _CurrentPersonCancellable

    ' If the value hasn't changed, don't do anything.
    If value = _CurrentPersonCancellable Then
        Return
    End If

    ' Note that we actually change the value for now.
    ' This is necessary because WPF seems to query the 
    '  value after the change. The combo box
    ' likes to know that the value did change.
    _CurrentPersonCancellable = value

    If MessageBox.Show("Allow change of selected item?", "Continue", MessageBoxButton.YesNo) <> MessageBoxResult.Yes Then
        Debug.WriteLine("Selection Cancelled.")

        ' change the value back, but do so after the 
        ' UI has finished it's current context operation.
        Application.Current.Dispatcher.BeginInvoke(New Action(Function() Do
            Debug.WriteLine("Dispatcher BeginInvoke " + "Setting CurrentPersonCancellable.")

            ' Do this against the underlying value so 
            '  that we don't invoke the cancellation question again.
            _CurrentPersonCancellable = origValue
            OnPropertyChanged("CurrentPersonCancellable")
        End Function), DispatcherPriority.ContextIdle, Nothing)

        ' Exit early. 
        Return
    End If

    ' Normal path. Selection applied. 
    ' Raise PropertyChanged on the field.
    Debug.WriteLine("Selection applied.")
    OnPropertyChanged("CurrentPersonCancellable")
End Set
End Property
公共属性CurrentPersonCancellable()作为个人
得到
Debug.WriteLine(“Getting CurrentPersonCancellable.”)
返回\u currentPersonCellable
结束
设置
'存储当前值,以便
'如果需要,请将其更改回。
Dim origValue=\u CurrentPersonCancelable
'如果值没有更改,请不要执行任何操作。
如果值=\u CurrentPersonCancellable,则
返回
如果结束
'请注意,我们现在实际上更改了该值。
“这是必要的,因为WPF似乎在查询
'更改后的值。组合框
“我想知道价值确实发生了变化。
_CurrentPersonCancelTable=值
如果MessageBox.Show(“允许更改所选项目?”,“继续”,MessageBoxButton.YesNo)MessageBoxResult.Yes,则为
Debug.WriteLine(“选择已取消”)
'将值更改回,但在
'用户界面已完成其当前上下文操作。
Application.Current.Dispatcher.BeginInvoke(新操作(函数()Do
Debug.WriteLine(“Dispatcher BeginInvoke”+“设置CurrentPersonCellable.”)
'针对基础值执行此操作,以便
“我们不再提出取消问题。
_CurrentPersonCancelTable=原始值
OnPropertyChanged(“CurrentPersonCancelable”)
结束函数),DispatcherPriority.ContextIdle,无)
“早点离开。
返回
如果结束
“正常路径。选择适用。
'在该字段上提升属性更改。
Debug.WriteLine(“已应用选择”)
OnPropertyChanged(“CurrentPersonCancelable”)
端集
端属性

函数
BeginInvoke
中使用,不能包含多个语句。
您需要将其移动到一个单独的函数中,并根据需要调用/获取其地址

在C#中可以做很多在VB.Net中做不到的事情(特别是与lamdas和匿名方法有关)


有许多语言元素是不可互换的。

函数
BeginInvoke
中使用,不能包含多个语句。
您需要将其移动到一个单独的函数中,并根据需要调用/获取其地址

在C#中可以做很多在VB.Net中做不到的事情(特别是与lamdas和匿名方法有关)

有许多语言元素是不能互换的。

试试这个

Public Property CurrentPersonCancellable() As Person
    Get
        Debug.WriteLine("Getting CurrentPersonCancellable.")
        Return _CurrentPersonCancellable
    End Get
    Set
        ' Store the current value so that we can '
        ' change it back if needed.'
        Dim origValue = _CurrentPersonCancellable

        ' If the value hasnt changed, dont do anything.'
        If value = _CurrentPersonCancellable Then
            Return
        End If

        ' Note that we actually change the value for now.'
        ' This is necessary because WPF seems to query the '
        '  value after the change. The combo box'
        ' likes to know that the value did change.'
        _CurrentPersonCancellable = value

        If MessageBox.Show("Allow change of selected item?", "Continue", MessageBoxButton.YesNo) <> MessageBoxResult.Yes Then
            Debug.WriteLine("Selection Cancelled.")

            ' change the value back, but do so after the '
            ' UI has finished its current context operation.'
            Application.Current.Dispatcher.BeginInvoke(New Action(of Person)(addressof dispatcherCallerHelper), _
                                                       DispatcherPriority.ContextIdle, _
                                                       new Object() {origValue})

            ' Exit early. '
            Return
        End If

        ' Normal path. Selection applied. '
        ' Raise PropertyChanged on the field.'
        Debug.WriteLine("Selection applied.")
        OnPropertyChanged("CurrentPersonCancellable")
    End Set
End Property

private sub dispatcherCallerHelper(origValue as Person)
    Debug.WriteLine("Dispatcher BeginInvoke " & "Setting CurrentPersonCancellable.")

    ' Do this against the underlying value so '
    '  that we dont invoke the cancellation question again.'
    _CurrentPersonCancellable = origValue
    OnPropertyChanged("CurrentPersonCancellable")
end sub
公共属性CurrentPersonCancellable()作为个人
得到
Debug.WriteLine(“Getting CurrentPersonCancellable.”)
返回\u currentPersonCellable
结束
设置
'存储当前值,以便
“如果需要,可以换回来。”
Dim origValue=\u CurrentPersonCancelable
'如果值没有更改,请不要执行任何操作。'
如果值=\u CurrentPersonCancellable,则
返回
如果结束
“请注意,我们现在实际上更改了该值。”
'这是必要的,因为WPF似乎在查询'
'更改后的值。组合框'
“我想知道价值确实发生了变化。”
_CurrentPersonCancelTable=值
如果MessageBox.Show(“允许更改所选项目?”,“继续”,MessageBoxButton.YesNo)MessageBoxResult.Yes,则为
Debug.WriteLine(“选择已取消”)
'更改回值,但在
“UI已完成其当前上下文操作。”
Application.Current.Dispatcher.BeginInvoke(新操作(人员)(dispatcherCallerHelper的地址)_
DispatcherPriority.ContextIdle_
新对象(){origValue})
“早点离开。”
返回
如果结束
“正常路径。选择适用。”
“在场地上提升属性更改。”
Debug.WriteLine(“已应用选择”)
OnPropertyChanged(“CurrentPersonCancelable”)
端集
端属性
私人分调度员呼叫器(或个人价值)
Debug.WriteLine(“Dispatcher BeginInvoke”和“Setting CurrentPersonCellable.”)
'针对基础值执行此操作,因此'
“我们不再提出取消问题。”
_CurrentPersonCancelTable=原始值
OnPropertyChanged(“CurrentPersonCancelable”)
端接头

在一个旁注中,对于OnPurryType更改的函数,应该考虑使用静态反射:

干杯

试试这个

Public Property CurrentPersonCancellable() As Person
    Get
        Debug.WriteLine("Getting CurrentPersonCancellable.")
        Return _CurrentPersonCancellable
    End Get
    Set
        ' Store the current value so that we can '
        ' change it back if needed.'
        Dim origValue = _CurrentPersonCancellable

        ' If the value hasnt changed, dont do anything.'
        If value = _CurrentPersonCancellable Then
            Return
        End If

        ' Note that we actually change the value for now.'
        ' This is necessary because WPF seems to query the '
        '  value after the change. The combo box'
        ' likes to know that the value did change.'
        _CurrentPersonCancellable = value

        If MessageBox.Show("Allow change of selected item?", "Continue", MessageBoxButton.YesNo) <> MessageBoxResult.Yes Then
            Debug.WriteLine("Selection Cancelled.")

            ' change the value back, but do so after the '
            ' UI has finished its current context operation.'
            Application.Current.Dispatcher.BeginInvoke(New Action(of Person)(addressof dispatcherCallerHelper), _
                                                       DispatcherPriority.ContextIdle, _
                                                       new Object() {origValue})

            ' Exit early. '
            Return
        End If

        ' Normal path. Selection applied. '
        ' Raise PropertyChanged on the field.'
        Debug.WriteLine("Selection applied.")
        OnPropertyChanged("CurrentPersonCancellable")
    End Set
End Property

private sub dispatcherCallerHelper(origValue as Person)
    Debug.WriteLine("Dispatcher BeginInvoke " & "Setting CurrentPersonCancellable.")

    ' Do this against the underlying value so '
    '  that we dont invoke the cancellation question again.'
    _CurrentPersonCancellable = origValue
    OnPropertyChanged("CurrentPersonCancellable")
end sub
公共属性CurrentPersonCancellable()作为个人
得到
Debug.WriteLine(“Getting CurrentPersonCancellable.”)
返回\u currentPersonCellable
结束
设置
'存储当前值,以便
“如果需要,可以换回来。”
Dim origValue=\u CurrentPersonCancelable
'如果值没有更改,请不要执行任何操作。'
如果值=\u CurrentPersonCancellable,则
返回
如果结束
“请注意,我们现在实际上更改了该值。”
'这是必要的,因为WPF似乎在查询'
'更改后的值。组合框'
“我想知道价值确实发生了变化。”
_CurrentPersonCancelTable=值
如果MessageBox.Show(“允许更改所选项目?”,“继续”,MessageBoxButton.YesNo)MessageBoxResult.Yes,则为
Debug.WriteLine(“选择已取消”)
'更改回值,但在
“UI已完成其当前上下文操作。”
Application.Current.Dispatcher.BeginInvoke(新Ac