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

  • Thread starter Marc Scheuner [MVP ADSI]
  • 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
 
J

Jon Skeet

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top