In C#, the how interface thing works is a bit different. I still have some bruises on my forehead healing from figuring the differences out.
In VB, you use the whole Implements keyword thing. This allows you to rename a property/method from that in the interface.
In C#, you either implement an interface implicitly or explicitly. When doing it implicitly, you just create a property/method/event that matches the one in the interface and you're done. An interesting note is that the property/method/event just had to be implemented somewhere in the inheritance chain. I.e one property can be implemented in current class and another in a base class.
If you do it explicitly, then you use the interface within the name of the property or method, as you are dong here:
public ControlUpdateMode IBusinessBindable.ControlSourceUpdateMode
However, when you do this explicitly, the property is
only available when the object is cast as the interface object. I.e. if the above is defined as a property in a class called MyTextbox and you have an instance of this control a form and it's called txtTest then:
-- This will not work, as ControlSourceUpdateMode is NOT a property of MyTextbox
ControlUpdateMode mode = this.txtTest.ControlSourceUpdateMode;
-- You have to cast...
ControlUpdateMode mode = ((IBusinessBindable)this.txtTest).ControlSourceUpdateMode;
And as you've also discovered, when you explicitly define an interface, you can't use modifiers. They are assumed public, because they are only available when the object is cast as an interface object. If this is confusing to anyone, you're understanding where the bruises on my forehead came from...
What you actually need to do to get what you likely want (a public property on the control that implements the ControlSourceUpdateMode that is accessable directly from the control without casting) is to:
- explicitly define that you want to implement IBusinessBindable on the subclassed control:
public class MyTextBox : sf.Textbox, IBusinessBindable)
- Get rid of the IBusinessBindable reference in the property definition.
- Add the public modifier back on it.
As mentioned earlier, C# can handle some of the interface being implemented in the current class and some of it in bases classes. It also seems to handle just fine the fact that you are re-implementing IBusinessBindable on your new class, even though the base class is already implementing it.
Does that make sense?