0

誰かがVBでICommandSourceを実装しようとしたことがありますか?Microsoftが提供する例はC#であり、VBでは暗黙的な実装が許可されていないため、このインターフェイスはVBでは実現できないようなものです。

http://msdn.microsoft.com/en-us/library/ms771361.aspx

4

1 に答える 1

1

実装するクラスによって異なります。Command、CommandParameter、および CommandTarget プロパティを独自のクラス (インターフェイスを実装する場所) に導入する場合は、他のインターフェイスと同じように実装できます。

Public ReadOnly Property Command() As ICommand
  Implements ICommandSource.Command
  Get
    ' implementation goes here
  End Get
End Property

ちなみに、実装には引き続き DP を使用できます。Implements ディレクティブは CLR プロパティにあり、getter と setter の "do not touch" 実装に干渉しません。

実装したいクラスがすでに (継承された) Command、CommandParameter、および CommandTarget プロパティを持っていて、インターフェイスの実装でそれらを再利用したい場合は、新しい名前で新しいプロパティを作成し、それらをインターフェイスの実装として宣言して戻す必要があります。それらを既存のプロパティに

Public ReadOnly Property ICommandSource_Command() As ICommand
  Implements ICommandSource.Command
  Get
    Return Me.Command  ' the existing implementation that can't be made implicit
  End Get
End Property
于 2010-01-07T23:00:35.443 に答える