473,394 Members | 4,037 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,394 software developers and data experts.

set a property of inherited class from base class

TS
I am trying to get set a property of a control on the inherited class from
base class. I imagine i have to use reflection, so could someone give me the
code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


Nov 16 '05 #1
8 3032
Try this;
this.GetType().GetProperty("panel1").SetValue(this , 44, null);

Where the property name is "panel1", and the value is 44.

Anyways, I don't think this is good. What you are trying to do aggressively
violates encapsulation. In100% of cases there are better ways to do things
like this using OOP paradigms.
For example, you can have that property virtual/abstract on the base class,
so that the inherters implement it, and you can directly modify it without
the reflection overhead.

"TS" <ma*********@311.com> wrote in message
news:##**************@TK2MSFTNGP11.phx.gbl...
I am trying to get set a property of a control on the inherited class from
base class. I imagine i have to use reflection, so could someone give me the code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;

Nov 16 '05 #2
TS wrote:
I am trying to get set a property of a control on the inherited class from
base class. I imagine i have to use reflection, so could someone give me the
code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


Is panel1 a member of the base class or of the inherited class? Could you
give a basic layout of hte two classes (you don't have to paste 400 lines,
just the idea) so we can suggest the proper solution? Reflection is almost
never the solution with these kind of problems :)

FB

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP
Nov 16 '05 #3

"TS" <ma*********@311.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
I am trying to get set a property of a control on the inherited class from
base class. I imagine i have to use reflection, so could someone give me the code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


There has to be a better way to do whatever it is you want to achieve.

Firstly do you mean an instance of the class? If you want to set a property
of an instance of a inherited class from an instance of the base class then
you simply send it (the inherited instance) a message from the base class
instance.

If no suitable method exists that allows you to do this then you write one.
Nov 16 '05 #4
TS
member of inherited class

I have a panel in the inherited class that i want to center in the form. I
have this panel in all the classes that inherit from base class. I wanted to
do the centering in the base class instead of on every inherited class.

i thought about making the panel on the base class, but i didn't want to
mess up my existing layout on the form becuase i was adding this panel after
the form was built and i had to add each control to the panel separately in
design mode to keep their same positions.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@msnews.microsoft.com...
TS wrote:
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give me the code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;
Is panel1 a member of the base class or of the inherited class? Could

you give a basic layout of hte two classes (you don't have to paste 400 lines,
just the idea) so we can suggest the proper solution? Reflection is almost
never the solution with these kind of problems :)

FB

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP

Nov 16 '05 #5
TS
so what if i have a method on an inherited class that is only used in this
class and not in all inherited classes?

"hOSAM" <hosam.shahin$$gmail.com> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
Try this;
this.GetType().GetProperty("panel1").SetValue(this , 44, null);

Where the property name is "panel1", and the value is 44.

Anyways, I don't think this is good. What you are trying to do aggressively violates encapsulation. In100% of cases there are better ways to do things
like this using OOP paradigms.
For example, you can have that property virtual/abstract on the base class, so that the inherters implement it, and you can directly modify it without
the reflection overhead.

"TS" <ma*********@311.com> wrote in message
news:##**************@TK2MSFTNGP11.phx.gbl...
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give me

the
code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


Nov 16 '05 #6
TS
you mean like a property accessor? can you give me an example?

"Kavvy" <bl*@debla.bla> wrote in message
news:bd*************@text.news.blueyonder.co.uk...

"TS" <ma*********@311.com> wrote in message
news:%2******************@TK2MSFTNGP11.phx.gbl...
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give me the
code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


There has to be a better way to do whatever it is you want to achieve.

Firstly do you mean an instance of the class? If you want to set a

property of an instance of a inherited class from an instance of the base class then you simply send it (the inherited instance) a message from the base class
instance.

If no suitable method exists that allows you to do this then you write one.

Nov 16 '05 #7
What triggers the centering action?

If it's done in the base class, sometimes you'll attempt to center a
panel which is not there.

If it starts in the derived class, then class a base class method,
passing a reference to the panel as a parameter.

Or, alternately, in the base class, search it's Controls collection for
the panel.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"TS" <ma*********@311.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
member of inherited class

I have a panel in the inherited class that i want to center in the form. I
have this panel in all the classes that inherit from base class. I wanted to do the centering in the base class instead of on every inherited class.

i thought about making the panel on the base class, but i didn't want to
mess up my existing layout on the form becuase i was adding this panel after the form was built and i had to add each control to the panel separately in design mode to keep their same positions.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@msnews.microsoft.com...
TS wrote:
I am trying to get set a property of a control on the inherited class from base class. I imagine i have to use reflection, so could someone give
me
the code to do it?

something like this?
this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;


Is panel1 a member of the base class or of the inherited class? Could

you
give a basic layout of hte two classes (you don't have to paste 400 lines, just the idea) so we can suggest the proper solution? Reflection is almost never the solution with these kind of problems :)

FB

--
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP


Nov 16 '05 #8
TS
thanks james

"James Curran" <Ja*********@mvps.org> wrote in message
news:ub**************@TK2MSFTNGP12.phx.gbl...
What triggers the centering action?

If it's done in the base class, sometimes you'll attempt to center a
panel which is not there.

If it starts in the derived class, then class a base class method,
passing a reference to the panel as a parameter.

Or, alternately, in the base class, search it's Controls collection for the panel.

--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)
"TS" <ma*********@311.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
member of inherited class

I have a panel in the inherited class that i want to center in the form. I
have this panel in all the classes that inherit from base class. I wanted
to
do the centering in the base class instead of on every inherited class.

i thought about making the panel on the base class, but i didn't want to
mess up my existing layout on the form becuase i was adding this panel after
the form was built and i had to add each control to the panel separately

in
design mode to keep their same positions.
"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@msnews.microsoft.com...
TS wrote:

> I am trying to get set a property of a control on the inherited class from
> base class. I imagine i have to use reflection, so could someone
give me
the
> code to do it?
>
> something like this?
> this.GetType().GetMember("panel1").SetValue(xx).Le ft = 44;

Is panel1 a member of the base class or of the inherited class?

Could you
give a basic layout of hte two classes (you don't have to paste 400

lines, just the idea) so we can suggest the proper solution? Reflection is almost never the solution with these kind of problems :)

FB

--
Get LLBLGen Pro, productive O/R mapping for .NET:

http://www.llblgen.com My .NET Blog: http://weblogs.asp.net/fbouma
Microsoft C# MVP



Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joăo Santa Bárbara | last post by:
hi all perhaps can someone help me. i have a form ( base ) where a i change the opacity from 100 to 60 % now i have a form inherited from the previous. and the opacity is correctly at 60%. ...
10
by: Jacob | last post by:
Is there a way to make a property of an inherited class invisible to the programmer? I know that using the keyword "new" allows you to create another property in the place of the existing one, but...
1
by: Jack Addington | last post by:
I have create a base class for a user control as well as a related base class for its logic (nonvisual). As part of the non-visual class I have a variable that references the base user object and...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
3
by: Wayne Brantley | last post by:
VS2005 RTM Create a web user control to use as a base class for other web user controls. Now, create a new web user control, change the class it inherits from to your base class and compile....
14
by: Dom | last post by:
Hi all I'm developing a control, and I need to hide some properties to the user. For example, suppose I need Text property to be completely inacessible (from a Form/Code that is into another...
19
by: jan.loucka | last post by:
Hi, We're building a mapping application and inside we're using open source dll called MapServer. This dll uses object model that has quite a few classes. In our app we however need to little bit...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
5
by: Rafe | last post by:
Hi, I've been thinking in circles about these aspects of Pythonic design and I'm curious what everyone else is doing and thinks. There are 3 issues here: 1) 'Declaring' attributes - I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...

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.