Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Knowing if a property exists
Message
 
To
02/03/2011 14:20:09
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01502282
Message ID:
01502407
Views:
43
>Instead of using the Try/Catch approach, would you know if there would be a way to use reflection to know if a property exists in a class?

Something like this:
object dataSource; // The object in question

var prop = dataSource.GetType().GetProperty(boundField, BindingFlags.IgnoreCase |
                                                                            BindingFlags.Public |
                                                                            BindingFlags.Instance);

if (prop != null)
   // The property exists
I (think) the VB version would be something like this:
Dim prop = dataSource.GetType().GetProperty(boundField, BindingFlags.IgnoreCase Or BindingFlags.Public Or BindingFlags.Instance)
If prop <> Nothing Then
   ' Property exists.
You may need to adjust the binding flags, depending on the types of properties you want to check.
-Paul

RCS Solutions, Inc.
Blog
Twitter
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform