473,400 Members | 2,145 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,400 software developers and data experts.

Need to check if the propery of an object exits.

Hi All,

Need to check if the propery of an object exits.

oMyObject.Message

In some cases the Message property may not exists. I know the GetType() can
do it.
How would you check it?

Thanks,

Joe
Dec 31 '07 #1
3 1153
System.Reflection and iterate through the PropertyInfo[].

The Type of the object has a .GetProperties method.

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx

"JoeP" <No****@Hotmail.comwrote in message
news:Of**************@TK2MSFTNGP03.phx.gbl...
Hi All,

Need to check if the propery of an object exits.

oMyObject.Message

In some cases the Message property may not exists. I know the GetType()
can do it.
How would you check it?

Thanks,

Joe
Jan 1 '08 #2
Hi Robbin,

Thanks for your reply.

Here is the situation I have 2 objects such as: Execption or SMTPExecption
The SMTPExecption has the property StatusCode while the other does not.

I pass the the object into an error handle method where I log the properties into a text file.
Looking at the Watch window it seems that the Execption does not have System.Reflection etc...

Regards,

Joe


"Robbe Morris - [MVP] C#" <in**@eggheadcafe.comwrote in message news:eE**************@TK2MSFTNGP03.phx.gbl...
System.Reflection and iterate through the PropertyInfo[].

The Type of the object has a .GetProperties method.

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx

"JoeP" <No****@Hotmail.comwrote in message
news:Of**************@TK2MSFTNGP03.phx.gbl...
>Hi All,

Need to check if the propery of an object exits.

oMyObject.Message

In some cases the Message property may not exists. I know the GetType()
can do it.
How would you check it?

Thanks,

Joe
Jan 1 '08 #3
And when you performed an

Type myType = myException.GetType();

PropertyInfo[] properties = myType.GetProperties();

what did you get?

--
Robbe Morris [Microsoft MVP - Visual C#]
AdvancedXL Server, Designer, and Data Analyzer
Convert cell ranges in Excel to rule driven web surveys
http://www.equalssolved.com/default.aspx


"JoeP" <No****@Hotmail.comwrote in message news:O8**************@TK2MSFTNGP03.phx.gbl...
Hi Robbin,

Thanks for your reply.

Here is the situation I have 2 objects such as: Execption or SMTPExecption
The SMTPExecption has the property StatusCode while the other does not.

I pass the the object into an error handle method where I log the properties into a text file.
Looking at the Watch window it seems that the Execption does not have System.Reflection etc...

Regards,

Joe


"Robbe Morris - [MVP] C#" <in**@eggheadcafe.comwrote in message news:eE**************@TK2MSFTNGP03.phx.gbl...
System.Reflection and iterate through the PropertyInfo[].

The Type of the object has a .GetProperties method.

--
Robbe Morris [Microsoft MVP - Visual C#]
.NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx

"JoeP" <No****@Hotmail.comwrote in message
news:Of**************@TK2MSFTNGP03.phx.gbl...
>Hi All,

Need to check if the propery of an object exits.

oMyObject.Message

In some cases the Message property may not exists. I know the GetType()
can do it.
How would you check it?

Thanks,

Joe
Jan 2 '08 #4

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

Similar topics

1
by: beachnut | last post by:
Hi, all. This should be pretty easy: When parsing my XmlDocument object with a validating reader, what's the proper way to detect when it "exits" an element's block? It's the first time I've...
2
by: CSDunn | last post by:
Hello, I need some assistance with error handling in an Access 2003 Project form. The project is has a data source connection to a SQL Server 2000 database. The main form is named...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
3
by: Mike | last post by:
I have a web page that displays contact people in a drop down. the users selects a person then clicks the go button. The datagrid should pop with all the information on the select contact person,...
3
by: Sky Sigal | last post by:
I coming unglued... really need some help. 3 days chasing my tail all over MSDN's documentation ...and I'm getting nowhere. I have a problem with TypeConverters and storage of expandableobjects...
2
by: Jeff | last post by:
Hello, I assigned a new object to a local variable ("req") in a function (see below). The local variable "req" is obviously destroyed when the function exits, but should the object referenced by...
6
by: Jack | last post by:
Hi, I am still new to .NET so, i'm sorry if my question is a bit too simple :-) I would like to know what is the "best-practice-way" of sending email from asp.net (VbScript). I want to make a...
1
by: ABHIJIT B | last post by:
Hi, I am using 2 web pages parent and popup.PopUp window is opened using window.showModalDialog().This is client requiremnt they don't wnat window.open() In PopUp page I am using GridView and...
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.