Reputation: 131
In Microsoft documentation, the declaration for the read-only property Controls of the Control class is as so:
[BrowsableAttribute(false)]
public Control.ControlCollection Controls { get; }
I am inheriting this property. And hiding it:
[EditorBrowsable(EditorBrowsableState.Never)]
[BrowsableAttribute(false)]
[ComVisible(false)]
public new Control.ControlCollection Controls { get; }
but this doesn't compile? Error: ‘UserControl1.Controls.get’ must declare a body because it is not marked abstract or extern. Automatically implemented properties must define both get and set accessors.
So I change it:
[EditorBrowsable(EditorBrowsableState.Never)]
[BrowsableAttribute(false)]
[ComVisible(false)]
public new Control.ControlCollection Controls {
get { return null; } }
Which does compile. But I need a bit of the properties functionality, and not to completely nullify it. (I must apologize to the early respondents to this post for my considerable edit here.) (Within 30 seconds!!)
I must change my script... so I try:
[EditorBrowsable(EditorBrowsableState.Never)]
[BrowsableAttribute(false)]
[ComVisible(false)]
public new Control.ControlCollection Controls { get; private set; }
This too won't compile: Error: The accessibility modifier of the 'UserControl1.Controls.set' accessor must be more restrictive than the property or indexer 'UserControl1.Controls'
What's to be done about this?
Upvotes: 0
Views: 92
Reputation: 7447
This is what I suggest.
[EditorBrowsable(EditorBrowsableState.Never)]
[BrowsableAttribute(false)]
[ComVisible(false)]
public new Control.ControlCollection Controls {
get { return base.Controls; } }
Upvotes: 1