Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Knowing if a property exists
Message
 
À
02/03/2011 18:29:15
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:
01502504
Vues:
62
This message has been marked as the solution to the initial question of the thread.
>It will show me all the members including all the Public properties I have defined at the top of my class.
>
>Something seems buggy here. The first set of code should have listed the properties.

Members are different than properties (which Viv already mentioned). In your case, if you need to access a member (and not a property) and retrieve it's value, that would look like this:
var dataSource = new SampleA();
dataSource.Test = 5;
var memberInfo = dataSource.GetType().GetMember("Test");
if (memberInfo.Length > 0)
{
	var member = memberInfo[0];
	var field = (FieldInfo)member;
	field.GetValue(dataSource).Dump();
}

public class SampleA
{
	public int Test;
}
Or in VB
Dim dataSource = New SampleA()
dataSource.Test = 5
Dim memberInfo = dataSource.GetType().GetMember("Test")
If memberInfo.Length > 0 Then
	Dim member = memberInfo(0)
	Dim field = CType(member, FieldInfo)
	field.GetValue(dataSource).Dump()
End If

Public Class SampleA
	Public Test As Integer
End Class
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform