SunQuest
 
           Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 29th, 2003, 02:56 AM
benos benos is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Posts: 233 benos User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Article Dicussion: Dynamically Using Methods

If you have any questions or comments about this article please post them here.

This forum post relates to this article

Reply With Quote
  #2  
Old July 15th, 2003, 05:06 PM
dplante dplante is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 3 dplante User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
System.Reflection use question

Ok, I hope I can explain this:
I am trying to create a function that will allow me to take any instanced object and return a key value pair of all of the data members inside of it. For example:

Public Structure myStruct
Dim str1 as String
Dim str2 as String
End Structure

Public Function myFunction()
Dim myStr as myStruct
myStr.str1 = "Val1"
myStr.str2 = "Val2"
Dim results()() = FancyFunction(myStruct)
End Function

Results should contain:
str1 val1
str2 val2

The example is trivial and if I knew what myStruct looked like at design time I could just hardcode the two properties. The problem is I will not know (i.e. FancyFunction will be given an arbitrary user defined structure).
Using the System.Reflection I can retrieve a list of all of the names of the members, but in String form I cannot retieve the property. Below is as far as I have gotten

Dim structStuff = myStruct.GetType.GetMembers()
Dim prop As System.Reflection.MemberInfo
For Each prop In structStuff
Dim field As String = prop.Name.ToString
Next
At this point, field contains a single member of the structure ("str1" in the above example) Since field is just a string variable I cannot very well call myStruct.field but essentially this is what I want to do!

If anyone has an idea on this please let me know!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > Article Dicussion: Dynamically Using Methods


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway