0

Hi,

I'd like to get an entire structure to a string, without having to use a string.format for each datatype in the structure for example.


So basically I want to do something like a 'For Each value In struc'.
Is this possible?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by GeekByChoiCe
0

are you looking for something like this?

Private Structure myTest
        Dim x As Integer
        Dim y As String
        Dim z As Short
    End Structure
    
        Dim xyz As New myTest With {.x = 10, .z = 12}
        Dim fields As System.Reflection.FieldInfo() = xyz.[GetType]().GetFields(System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.[Public])

        For Each field As System.Reflection.FieldInfo In fields
            Try
                MessageBox.Show(field.GetValue(xyz).ToString())
            Catch ex As NullReferenceException
                'empty y
            End Try
        Next
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.