Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Knowing if a property exists
Message
 
To
02/03/2011 18:29:15
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:
01502504
Views:
61
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform