By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,942 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

How to change attribute in derived class

P: n/a
Hi there,

Is there a clean way to change a property or method's attribute in a derived
class without redefining the property/method itself. That is, redefining the
property/method in the derived class simply to change its attribute is ugly
IMO. I assume you can do this and then simply defer to the base class
version but it's unwieldy so I'm wondering if there's a better way. Thanks
in advance.
Sep 28 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Michael,

I agree with you, but there is no other way. There are some (mostly related
to the design time behavior and property grid) where using TypeConverter one
can return collection of PropertyDescriptors with changed set of attributes.
Again this works only in some special situations and only for properties.

What attributes do you want to change?

Whatever the case I believe overriding the base class methods is going to be
much easier.
--
HTH
Stoitcho Goutsev (100)

"Michael Chambers" <no_spam@_nospam.comwrote in message
news:OB****************@TK2MSFTNGP02.phx.gbl...
Hi there,

Is there a clean way to change a property or method's attribute in a
derived class without redefining the property/method itself. That is,
redefining the property/method in the derived class simply to change its
attribute is ugly IMO. I assume you can do this and then simply defer to
the base class version but it's unwieldy so I'm wondering if there's a
better way. Thanks in advance.

Sep 28 '06 #2

P: n/a
Michael,
>
I agree with you, but there is no other way. There are some (mostly
related to the design time behavior and property grid) where using
TypeConverter one can return collection of PropertyDescriptors with
changed set of attributes. Again this works only in some special
situations and only for properties.

What attributes do you want to change?

Whatever the case I believe overriding the base class methods is going to
be much easier.
Thanks for the feedback. I've since changed my approach to eliminate this
need however (read on) but what I originally wanted to do was derive a new
class from "TreeView" (or any other control for that matter) where one or
more base class properties would then become constant (fixed for that
particular derivative). Since I wanted to add my inherited control to the
form designer "Toolbox" however (so I could drag it onto my forms), I would
have to set the "BrowsableAttribute" to "false" for these properties so they
would no longer appear in a form's properties window (since they're now
constant). I changed my mind however and decided to just create a
"UserControl" derivative instead so I'm now wrapping the original control
instead of inheriting from it. This eliminates the original problem as I can
now simply expose the wrapped control's functionality on an as-needed basis
(deferring to the underlying control when needed). Anyway, thanks again.
Sep 28 '06 #3

P: n/a
Michael,

If this is what you want to do you can use TypeConverter for that.
Create new TypeConverter by inheriting the TreeNodeConverter override
GetPropertiesSupported and return *true* then override GetProperties.
GetProperties is the method where you are going to change the attributes for
some of the proeprties. Using TypeDescriptor you can get collection of
PropertyDescriptors for the type properties. The you create a new
PropertyDescriptorCollection and transfer all the proeprties from the
original one to the new one. If you need to change the browsable attribute
for some property use TypeDescriptor.CreateProperty to create a new
PropertyDescriptor based on the original PropertyDescriptor, but change the
set of attributes.

--
HTH
Stoitcho Goutsev (100)

"Michael Chambers" <no_spam@_nospam.comwrote in message
news:eq**************@TK2MSFTNGP06.phx.gbl...
>Michael,

I agree with you, but there is no other way. There are some (mostly
related to the design time behavior and property grid) where using
TypeConverter one can return collection of PropertyDescriptors with
changed set of attributes. Again this works only in some special
situations and only for properties.

What attributes do you want to change?

Whatever the case I believe overriding the base class methods is going to
be much easier.

Thanks for the feedback. I've since changed my approach to eliminate this
need however (read on) but what I originally wanted to do was derive a new
class from "TreeView" (or any other control for that matter) where one or
more base class properties would then become constant (fixed for that
particular derivative). Since I wanted to add my inherited control to the
form designer "Toolbox" however (so I could drag it onto my forms), I
would have to set the "BrowsableAttribute" to "false" for these properties
so they would no longer appear in a form's properties window (since
they're now constant). I changed my mind however and decided to just
create a "UserControl" derivative instead so I'm now wrapping the original
control instead of inheriting from it. This eliminates the original
problem as I can now simply expose the wrapped control's functionality on
an as-needed basis (deferring to the underlying control when needed).
Anyway, thanks again.

Sep 29 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.