473,520 Members | 2,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query for ancestor

Hi,

Is it possible to query an object for an ancestor. I.e.
determine if an object is derived from a certain type of
class.

thanx.

Jespr.
Nov 15 '05 #1
2 1505
MyBaseObject mbo = new MyBaseObject();
MyInheritedObject mio = new MyInheritedObject();

bool isDescendant = mbo.GetType().IsInstanceTypeOf(mio);

If you know the ancestor type in advance, it'll work for
you. I can't think of the other method off of the top of
my head, but I'm pretty sure I remember a post by Rockford
Lhotka in the wrox groups about figuring out the ancestor
of an object...I'll see if I can find it.

Good Luck,

Bill

W.G. Ryan
do********@comcast.nospam.net
www.knowdotnet.com
-----Original Message-----
Hi,

Is it possible to query an object for an ancestor. I.e.
determine if an object is derived from a certain type of
class.

thanx.

Jespr.
.

Nov 15 '05 #2
if you know the type you wish to check, for example
System.ComponentModel.Component, you can simiply do:
object o = <getobject>;
if (o is System.ComponentModel.Compnent) {
//do whatever,
}

otherwise
object o = <getobject>;
object c = <getdifferntObject>;
if (o.GetType().IsSubClassOf(c.GetType())) {
//do whatever
}

note, that in C#, the typeof() keyword can be used instead of the .GetType()
method.
"Jesper" <je****@hotmail.com> wrote in message
news:04****************************@phx.gbl...
Hi,

Is it possible to query an object for an ancestor. I.e.
determine if an object is derived from a certain type of
class.

thanx.

Jespr.

Nov 15 '05 #3

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

Similar topics

3
1727
by: Mike Partridge | last post by:
Is it possible to access your caller's (not parent) context while inside a <xsl:template match...> or <xsl:for-each...>? Here is the xml I'm using: <report-set> ...<report> .....<detail-data> .......<detail-column position="1" dsc="col1" sum_fg="0"/> .......<detail-column position="2" dsc="col2" sum_fg="1"/> .......<detail-column...
0
1590
by: Robert Wille | last post by:
I have a number of very common queries that the optimizer plans a very inefficient plan for. I am using postgres 7.2.3. I vacuum hourly. I'm wonderingwhat I can do to make the queries faster. Here are the relevant tables: create table image( imageid integer not null, /* The image's ID */ containerid integer not null, /* The...
1
2756
by: Robert Wille | last post by:
I have a number of very common queries that the optimizer plans a very inefficient plan for. I am using postgres 7.2.3. I vacuum hourly. I'm wonderingwhat I can do to make the queries faster. Here are the relevant tables: create table image( imageid integer not null, /* The image's ID */ containerid integer not null, /* The...
11
2505
by: John Bailo | last post by:
Is anyone familar with the correct syntax for using ancestor:: ? I am trying to use it in a c# application, and I am also testing it in a parser application called Cooktop ( http://www.xmlcooktop.com ) I cannot get it or my c# code to return a node list when using ancestor. Is ancestor:: something that .NET does or does not support? ...
3
1630
by: Luis P. Mendes | last post by:
Hi, I have the following problem: I instantiate class Sistema from another class. The result is the same if I import it to interactive shell. s = Sistema("par") class Sistema:
3
1467
by: Valvalis | last post by:
Hello, I am trying to set a class attribute of a text.item element to the value of its nearest ancestor. I want to do this in the case that the class of the text.item is currently a blank string. <text class="read-only"> ... <text.item class=""/> //this element should inherit the class attribute "read-only" from text <foo...
5
2425
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons> <Button>Activity <RestrictedClientType> <ClientType>02</ClientType> </RestrictedClientType>
30
2307
by: Vadim Tropashko | last post by:
Reposting with more clarification (as Jan asked). Suppose I have a BNFgrammar and a source text parsed into a tree. How would I query an identifier declaration? All the XQuery tutorials (where I went to gather some ideas) start with simpleminded examples like browsing all the descendants of / bookstore/book (and the bookstore XML design...
7
6288
by: Ebenezer | last post by:
Hello! Let's suppose we have an XML with some nested NODE nodes: <root attr="first"> <node id="1" attr="mike"> <node id="2" /> <node id="3" attr="dave" /> </node> <node id="4">
0
7299
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7559
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...
1
5125
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...
0
3279
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1646
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
836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
506
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...

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.