ASP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingASP Development

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:
  #1  
Old July 16th, 2003, 08:07 AM
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
Question Getting object members and their instanced values at the same time?

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
  #2  
Old July 29th, 2003, 11:49 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
without claiming to be an expert:
you could think about using an array as the parameters in your fancy function. This way you could take a dynamic number of elements into your function
PHP Code:
Private Function FancyFunction(byval myArray as Array) as string

  Dim i 
as IntegerstrOut as String
  
For 0 To UBound(myArray)
     '
here your statements
  Next

  FancyFunction = strOut
End function 


Hope this helps a tiny bit
__________________
- Rogier Doekes

Reply With Quote
  #3  
Old July 30th, 2003, 08:22 AM
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
I think I understand what you are saying rdoekes and I could be reading it wrong, but I do not think that will help me solve my problem (although I do appreciate the input). You see, FancyFunction can only have 1 parameter being of type Object. The purpose of the function is not to replace all previous functions, but rather to give information on an object. An object explorer in essance.
-Doug

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingASP Development > Getting object members and their instanced values at the same time?


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 3 hosted by Hostway