Reputation: 1364
VB2010. Not even sure if this is possible but for debugging purposes I want to print out the name of the variable that was assigned to a master variable (both being classes).
Dim mstTripClass As Trip = Nothing
Select Case sc
Case "0"
mstTripClass = driver.BusinessTrip
Case "7", "8"
mstTripClass = driver.LeisureTrip
Case "10"
mstTripClass = driver.OtherTrip
Case Else
Throw New Exception("Invalid trip class")
End Select
Debug.Print("Trip class=" & mstTripClass.GetType.ToString)
This prints out
Trip class=MyCompany.MyDept.MyApp.Trip
What i would like to print out is something like:
Trip class=BusinessTrip
I'm not even sure how to search for this type of thing. I searched for reflection but came up empty.
Upvotes: 0
Views: 56
Reputation: 84835
No reflection needed here at all. Two easy alternatives come to mind:
Turn driver
into an Enum
having the values BusinessTrip
, LeisureTrip
etc.
Whatever type driver.BusinessTrip
has, extend that type with a abstract string property TypeDescription
and have the BusinessTrip
, LeisureTrip
etc. subtypes override the property so that they return a textual description.
Upvotes: 1