HOW-TO: "Hide" a property of a base class

  • Thread starter Thread starter Marc Scheuner [MVP ADSI]
  • Start date Start date
M

Marc Scheuner [MVP ADSI]

Folks,

I've created a descendant of ListView, and I would like to be able to
tell it to "hide" two of the base class's properties - how can I
accomplish this?

I know I can add a [Browsable(false)] attribute to the properties to
remove them from the object inspector window - that's not all, though
- I'd like to make them unavailable from code, too.

How do I accomplish this?? If it's possible, that is.....

Thanks!
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Marc Scheuner said:
I've created a descendant of ListView, and I would like to be able to
tell it to "hide" two of the base class's properties - how can I
accomplish this?

I know I can add a [Browsable(false)] attribute to the properties to
remove them from the object inspector window - that's not all, though
- I'd like to make them unavailable from code, too.

How do I accomplish this?? If it's possible, that is.....

You can't - and for good reason. It completely violates Liskov's
Substitutability Principle. Further more, it would be trivial to get
round - the caller could just declare his reference variable to be of
the base class type, and then how would the compiler know to stop it?

What you *can* do of course is override the properties (assuming
they're virtual) and throw exceptions in them. That's a pretty nasty
thing to do though.
 
Back
Top