473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to change attribute in derived class

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
3 5440
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sridhar R | last post by:
Consider the code below, class Base(object): pass class Derived(object): def __new__(cls, *args, **kwds): # some_factory returns an instance of Base # and I have to derive from this...
8
by: Webster | last post by:
Hello, I have a class Shape and subclasses Circle, Rectangle etc. I also have a function to write them to a file given a filepointer. However, I store the colour info in the Shape class. My...
2
by: Steve James | last post by:
I am trying to mark an override method in a derived class as obsolete using the ObsoleteAttribute. The compiler, however is not picking up this attribute and is not generating a warning or an...
1
by: Hans Bampel | last post by:
Hello group, i want to overwrite or manipulate a attribute of a property in a derived class. I use a attribute DBInfo via reflection on my properties to set the parameters in a SQL-statement...
3
by: Marco Segurini | last post by:
Hi, Actually I am creating a hierarchy of MANAGED classes. I like to know if there is way to mark a virtual (abstract) function as "must be implemented on each derived class". example: ref...
9
by: Larry Woods | last post by:
I have a method in my base class that I want ALL derived classes to use. But, I find that I can create a "Shadow" method in my derived class that "overrides" the method in my base class. Can't...
2
by: Jessica | last post by:
I have a base class and a derived class, but I am getting errors when I try to access functions of the derived class. Simplified version of my code is as follows: //////////////// // test2.hh...
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
0
by: anileshlakhtakia | last post by:
Hi I have a class let say , Class A { public IList animal { get{}set{} } } Class B:A
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.