|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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:
Hope this helps a tiny bit
__________________
- Rogier Doekes |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > ASP Development > Getting object members and their instanced values at the same time? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|