2016-08-22 90 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