How to return the value of a Property in a custom class

gspeedtech

Member
Joined
Mar 13, 2010
Messages
11
Programming Experience
Beginner
I have a custom class named Location with multiple properties.

Example

Class = Location

Property = Street

Value = "Main St"

Property = City

Value = "AnyTown"

Property = Country

Value = "USA"


Through reflection I can get the names of each property:

VB.NET:
Public Function GetLocationValue(ByRef sLocation)    
    Dim sTable As New ProjectSchema.Location
    sTable = sLocation
    For Each p As System.Reflection.PropertyInfo In sTable.GetType().GetProperties()
            If p.CanRead Then
               Console.WriteLine(p.Name)
            End If
    Next
    End Function
Results:

p.Name = Street

p.Name = City

p.Name = Country

How can I get the value of each p.Name and return "Main St", "AnyTown" o "USA"
 
Back
Top