2016-08-22 93 views
-1

我不能将此代码转换为vb.net。请帮帮我。谢谢。将此代码转换成Vb.net

using System; 
using System.ComponentModel; 
using System.Runtime.CompilerServices; 

namespace RssReader.Common 
{ 
/// <summary> 
/// Provides a standard change-notification implementation. 
/// </summary> 
public abstract class BindableBase : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    public void OnPropertyChanged([CallerMemberName] string propertyName = null) => 
     PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 

    protected bool SetProperty<T>(ref T storage, T value, 
     [CallerMemberName] String propertyName = null) 
    { 
     if (object.Equals(storage, value)) return false; 
     storage = value; 
     OnPropertyChanged(propertyName); 
     return true; 
    } 
} 
} 

我不能将此代码转换为vb.net。非常感谢你

回答

0

没有你需要这个类的上下文(它只是一个片段,我试图为你执行一个可编译的转换,这意味着编译器说的语法是正确的。基于我对VB.NET的丰富知识以及不断增长的C#技能,我认为这可能是您需要的解决方案。

大多数代码转换器在此错过的实际问题是,当您在VB中为参数指定默认值.NET,你必须在它前面使用关键字“Optional”,为了减少它们的损害,大多数转换器也会将Attribute定义放在Byval之前,并且在Optional这个单词之后是不正确的。将该关键字直接放在Byval之前,因此是唯一的为属性定义去的地方在word可选之前。

警告。 现在,编译器喜欢我写的内容,但我不知道它是否会在您的上下文中无法访问您调用它的更广泛的代码库。

希望这会有所帮助,代码如下。

Imports System 
Imports System.ComponentModel 
Imports System.Runtime.CompilerServices 

Namespace RssReader.Common 
    ''' <summary> 
    ''' Provides a standard change-notification implementation. 
    ''' </summary> 
    Public MustInherit Class BindableBase 
     Implements INotifyPropertyChanged 

     Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged 

     Public Sub OnPropertyChanged(<CallerMemberName> Optional ByVal propertyName As String = Nothing) 
      PropertyChangedEvent?.Invoke(Me, New PropertyChangedEventArgs(propertyName)) 
     End Sub 

     Protected Function SetProperty(Of T)(ByRef storage As T, ByVal value As T, <CallerMemberName> Optional ByVal propertyName As String = Nothing) As Boolean 
      If Object.Equals(storage, value) Then 
       Return False 
      End If 
      storage = value 
      OnPropertyChanged(propertyName) 
      Return True 
     End Function 
    End Class 
End Namespace