Skip to content

Instantly share code, notes, and snippets.

@AdamSpeight2008
Created May 18, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamSpeight2008/b4ef5b7c8b52d1a9009ac8b16f258a13 to your computer and use it in GitHub Desktop.
Save AdamSpeight2008/b4ef5b7c8b52d1a9009ac8b16f258a13 to your computer and use it in GitHub Desktop.
Shared Function TypeofIntoNullableT(of T As Structure, U As Structure)(input As T?, ByRef output As U?) As Boolean
  output = If(input.HasValue, Microsoft.VisualBasic.CompilerServices.Conversions.ToGenericParameter(Of U?)(input.Value)), NOthing)
  Return output.HasValue
End Function
Dim input As Integer? = 123
Dim output As Double? = 0
Dim valid = TypeofIntoNullable(input, output)
Debug.Assert(valid)
Debug.Assert(input.ToString() = output.ToString())

The code works within the language, but I can attempting to write a lowering the does the equalvent transformation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment