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

How to test for objects property that does not exist

How does one test to insure a property of an objects exists?

The debugger shows the object.property as: "error: 'object.property' does not exist"

using: if (object.property != null) results in: "Object reference not set to an instance of an object."

Thanks for help!
Nov 15 '05 #1
3 21527
You can use reflection to do it safely, here is a snip

----------------------------
bob b = new bob();

Type t = b.GetType();
PropertyInfo p = t.GetProperty("FName");
if (p == null)
{
// property does not exist
}
else
{
// property exists
}

--------------------------

"Steve Montague" <st************@getronics.com> wrote in message news:#q**************@TK2MSFTNGP12.phx.gbl...
How does one test to insure a property of an objects exists?

The debugger shows the object.property as: "error: 'object.property' does not exist"

using: if (object.property != null) results in: "Object reference not set to an instance of an object."

Thanks for help!
Nov 15 '05 #2

Hi Steve,

Thank you for posting in the community!

In Visual Studio.Net, both edting-time debugger and intellisense use the
Reflection to do validation and prompt.

.Net Reflection will query the meta of the assembly to get the information
of the classes in this assembly. It is a powerful tool in .Net.

In Bob's reply, he has told you how to get what you want through
Reflection.

.Net gives you many more feature and functions, for a quickstart of
Reflection, please refer to:
http://samples.gotdotnet.com/quickstart/howto/

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
Steve Montague <st************@getronics.com> wrote:
How does one test to insure a property of an objects exists?

The debugger shows the object.property as: "error:
'object.property' does not exist"

using: if (object.property != null) results in:
"Object reference not set to an instance of an object."


That suggests that it's not that the property doesn't exist, but that
your reference is to null (rather than to a real object) in the first
place.

If the property didn't exist within the type, your code wouldn't
compile to start with.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

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

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
1
by: Georg Scholz | last post by:
Hello, The class "Control" contains a documented Property "ControlType". So for example, in a form, you can write code like this: Dim c as control set c = me.Controls("textbox1") if...
2
by: genojoe | last post by:
Using ADOX to update a Property does not work. I want to change the Access database for a linked table. My abridged code is: Dim oCAT As ADOX.Catalog oCAT = New ADOX.Catalog...
6
by: Marc Robitaille | last post by:
Hello, Hello, I developed a UserControl. It has funny behavior. It is composed of three controls. A texbox, a combobox and a button. There are three properties to indicate the visibility of...
4
by: Hardik Shah | last post by:
Hi, I have created a form , and have a different controls on them. I want to check that control has particular property name or not. I wrote following code , tell me what I missing :- Dim...
2
by: reynardmh | last post by:
I tried to change the image.src on the fly when the user click a link. But for some reason it does not work in IE 6 (the image just disappear when I click the link), but if I add the alert('test')...
2
by: Keithb | last post by:
I need to hide a GridView's "edit" column if the user's role does not support editing. However, the column's Visible property does not support databinding. Is there a workaround? Thanks, ...
1
by: --== Alain ==-- | last post by:
Hi, I have a huge problem... My property does not appear in the "propertyGrid" of "test Container", when i test my custom control. Here is the custom control code : namespace...
1
by: =?Utf-8?B?a2thcnJl?= | last post by:
Hi all, We decided to clear the test db more frequently and I was asked to serialize som test objects to make sure our unit testing continues to work after clearing the db. Does anyone have...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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,...
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.