Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Knowing if a property exists
Message
De
03/03/2011 11:45:59
 
 
À
03/03/2011 09:05:30
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:
01502518
Vues:
40
>>Does the property have a public accessor. Docs:
>>"A property is considered public to reflection if it has at least one accessor that is public." For clarity if should read:
>>"A property is only considered public to reflection if it has at least one accessor that is public."
>>For the following class GetProperties() would only return PropertyA, GetMembers() would return PropertyA and PropertyB:
Public Class SomeClass
>>    Public PropertyB As String
>>    Dim _propertyA As String
>>    Public Property PropertyA As String
>>        Get
>>            Return _propertyA
>>        End Get
>>        Set(ByVal value As String)
>>            _propertyA = value
>>        End Set
>>    End Property
>>End Class
>
>Thanks, that is what I started to suspect last night.
>
>Would there be a way to verify for PropertyB, in your example, and get its value if it exists?

Looks like you've got it - but just to throw in some Linq :-} :
Dim mi As System.Reflection.MemberInfo = (From xx In oLabel.GetType().GetMembers() _
                                                  Where xx.Name = "PropertyB" Select xx).FirstOrDefault()

        If Not mi Is Nothing Then
            'Got it
        End If
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform