2016-08-22 4 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の場合は、その前にキーワード「オプション」を使用する必要があります。ほとんどのコンバータでは、Byvalの前と、オプションの単語の後にAttribute定義を置きます。そのキーワードをByvalの直前に置きます。属性定義が配置される場所は、オプションの前になります。

注意してください。 コンパイラは私が書いたものが好きですが、それがあなたのコンテキストで動作するかどうかはわかりませんが、より広いコードベースへのアクセスはありません。

希望するコードは以下のとおりです。

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 
関連する問題