[VB.Net] Typecasting generic parameters.
- by CFP
Hello world!
Using the following code:
Function GetSetting(Of T)(ByVal SettingName As String, ByRef DefaultVal As T) As T
Return If(Configuration.ContainsKey(SettingName), CType(Configuration(SettingName), T), DefaultVal)
End Function
Yields the following error:
Value of type 'String' cannot be converted to 'T'.
Any way I could specify that in all cases, the conversion will indeed be possible (I'm basically getting integers, booleans, doubles and strings).
Thanks!