How to retrieve strings via reflection and concatenate it ascending-ly
See the question and my original answer on StackOverflowIf the strings are defined in the same order as in your question, you can avoid sorting, and here is a simple VB.NET answer:
Public Function Extract() As String
Dim type As Type = Assembly.LoadFrom("C:\test.dll").GetType("YourNamespace.Test")
Dim instance As Object = Activator.CreateInstance(type)
Dim sb As New StringBuilder
Dim field As FieldInfo
For Each field In type.GetFields
If field.Name.StartsWith("Prefix_") Then
sb.Append(field.GetValue(instance))
End If
Next
Return sb.ToString
End Function
otherwise here is a function with sorting:
Public Function Extract() As String
Dim type As Type = Assembly.LoadFrom("c:\test.dll").GetType("YourNamespace.Test")
Dim fields As New List(Of FieldInfo)
Dim field As FieldInfo
For Each field In type.GetFields
If field.Name.StartsWith("Prefix_") Then
fields.Add(field)
End If
Next
fields.Sort(New FieldComparer)
Dim sb As New StringBuilder
Dim instance As Object = Activator.CreateInstance(type)
For Each field In fields
sb.Append(field.GetValue(instance))
Next
Return sb.ToString
End Function
Private Class FieldComparer
Implements IComparer(Of FieldInfo)
Public Function Compare(ByVal x As FieldInfo, ByVal y As FieldInfo) As Integer Implements IComparer(Of FieldInfo).Compare
Return x.Name.CompareTo(y.Name)
End Function
End Class