|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > Article Dicussion: Dynamically Using Methods |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|