Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Knowing if a property exists
Message
 
À
02/03/2011 14:20:09
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01502282
Message ID:
01502407
Vues:
44
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform