HighTechTalks DotNet Forums  

Reflect on a property of a property

Dotnet Framework microsoft.public.dotnet.framework


Discuss Reflect on a property of a property in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Barry Gilbert
 
Posts: n/a

Default Reflect on a property of a property - 11-01-2007 , 02:26 PM






I have a class that has a property of a type of another class. Like this:

Public Class Employee
Public Property Shift As Shift
' Get and set stuff
End Property
End Class

Public Class Shift
Public Property ShiftId As Integer
' Get and set stuff
End Property
End Class

Using reflection, I need to be able to get to the value contained in ShiftId
from looking at an Employee object. I've come close, but I cannot get the
right syntax. Here's what I have so far (this is in a base class):

Dim myType As Type=Me.GetType
For Each mi As MemberInfo In itemType.GetMembers(BindingFlags.Public Or _
BindingFlags.SetProperty Or BindingFlags.Instance Or _
BindingFlags.Static Or BindingFlags.NonPublic)
myType.GetProperty(mi.Name).GetValue(me,nothing).G etType.GetProperty("ShiftId").GetValue(

I'm stuck on the object to pass into the last GetValue call. I;m not sure
how to get a reference to the object contained in the outer class's property.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.