473,594 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5460
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 PropertyDescrip tors 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@_nospa m.comwrote in message
news:OB******** ********@TK2MSF TNGP02.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 PropertyDescrip tors 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 "BrowsableAttri bute" 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
"UserContro l" 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 TreeNodeConvert er override
GetPropertiesSu pported 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
PropertyDescrip tors for the type properties. The you create a new
PropertyDescrip torCollection 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
PropertyDescrip tor based on the original PropertyDescrip tor, but change the
set of attributes.

--
HTH
Stoitcho Goutsev (100)

"Michael Chambers" <no_spam@_nospa m.comwrote in message
news:eq******** ******@TK2MSFTN GP06.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
TypeConverte r one can return collection of PropertyDescrip tors 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 "BrowsableAttri bute" 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 "UserContro l" 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
3315
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 instance!
8
1648
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 question is, is it possible to create a WriteColour function in the Shape class, but when I call the sub class writes (i.e. Circle.Write(...)), it will call the Shape's WriteColour function?? Or is there a way to refer to the base class in a...
2
5032
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 error. Sample code is below: If I put the attribute on the static method DoSomething() in the main class, a warning/error is generated by the compiler. If I put the attribute on the virtual instance method DoSomething() of
1
2061
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 dynamically. Now in a derived class (similar table in the DB), the name of the column a other one. what i have
3
1289
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 class Test abstract {
9
1791
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 figure out what attribute to put on the base class method to prevent this. TIA, Larry Woods
2
2631
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 class BaseClass {
2
697
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 UserControl are like that). When serializing, how could I ignore all the properties coming from the UserControl class? I know there is XmlIgnoreAttribute, but how could I set it to every property of UserControl, as it is not my class? Thank you...
0
1424
by: anileshlakhtakia | last post by:
Hi I have a class let say , Class A { public IList animal { get{}set{} } } Class B:A
0
7874
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8368
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8231
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5738
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5404
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3854
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1476
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.