-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
interpolated-strings2.vb
59 lines (55 loc) · 1.95 KB
/
interpolated-strings2.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Imports System.Globalization
Imports System.Reflection
Public Module Example
Public Sub Main()
Dim price = 1000
Dim s2 As IFormattable = $"The cost of this item is {price:C}."
ShowInfo(s2)
CultureInfo.CurrentCulture = New CultureInfo("en-US")
Console.WriteLine(s2)
CultureInfo.CurrentCulture = New CultureInfo("fr-FR")
Console.WriteLine(s2)
End Sub
Private Sub ShowInfo(obj As Object)
Console.WriteLine($"Displaying member information:{vbCrLf}")
Dim t = obj.GetType()
Dim flags = BindingFlags.Public Or BindingFlags.Instance Or BindingFlags.Static Or BindingFlags.NonPublic
For Each m In t.GetMembers(flags)
Console.Write($" {m.Name} {m.MemberType}")
If m.MemberType = MemberTypes.Property Then
Dim p = t.GetProperty(m.Name, flags)
Console.Write($" Value: {p.GetValue(obj)}")
End If
If m.MemberType = MemberTypes.Field Then
Dim f = t.GetField(m.Name, flags)
Console.Write($" Value: {f.GetValue(obj)}")
End If
Console.WriteLine()
Next
Console.WriteLine($"-------{vbCrLf}")
End Sub
End Module
' The example displays the following output:
Displaying member information:
' get_Format Method
' GetArguments Method
' get_ArgumentCount Method
' GetArgument Method
' ToString Method
' System.IFormattable.ToString Method
' ToString Method
' Equals Method
' GetHashCode Method
' GetType Method
' Finalize Method
' MemberwiseClone Method
' .ctor Constructor
' Format Property Value: The cost of this item is {0:C}.
' ArgumentCount Property Value: 1
' _format Field Value: The cost of this item is {0:C}.
' _arguments Field Value: System.Object[]
' -------
'
' The cost of this item is $1,000.00.
' The cost of this item is 1 000,00 €.
' </Snippet1>