views:

61

answers:

2

Hello!

Has anyone ever tried to implement ICommandSource with VB? The examples provided by Microsoft are in C#, and since VB doesn't allow implicit implementation this interface is like inachievable in VB!!

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

A: 

Check this SO Link. So you might need to do this in c# after all.

Joshua Cauble
This is unbelievable how Microsoft are so sloppy.
Shimmy
But that's a different scenario, where the author need to get existing methods (from a base class) mapped to the interface. Here presumably Shimmy is creating his own class and can define his own Command, CommandParameter and CommandTarget properties.
itowlson
+1  A: 

It depends on what class you want to implement it on. If you're introducing the Command, CommandParameter and CommandTarget properties in your own class (where you're implementing the interface), you can just implement it like any other interface:

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

You can still use a DP for the implementation, by the way: the Implements directive is on the CLR property and does not interfere with the "do not touch" implementation of the getters and setters.

If the class you want to implement it on already has (inherited) Command, CommandParameter and CommandTarget properties, and you want the interface implementation to reuse those, you'll need to create new properties with new names, declare them as interface implementations and back them onto the existing properties

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
itowlson
That's what I did, except that I did the implemetor property private, cuz anyway it's exposed by the DP, correct me if I did a mistake.
Shimmy
Nope, I think making it private is fine: as you say, for binding purposes it will use the DP anyway, and if you don't need the CLR wrapper property outside the class, then there's no value in making it public.
itowlson
You rock, you got my vote as well!
Shimmy