Search code examples
.netvb.netwindows-store-apps

Windows Runtime App TypeCode


I am trying to port the Basic Dynamic LINQ VB Example by Scott Guthrie to use in my Windows Store App on my Windows 8.1 Pro machine.

The TypeCode enum and its related functions are no longer available (Source: MSDN social Post titled: "Is the standard enum 'TypeCode' omitted from Store and Phone 8 ???" (Can't link, not enough rep)) in .NET for Windows Store Apps.

How should I best translate this TypeCode comparison code?

From the PromoteExpression() function in the ExpressionParser class:

Dim value As Object = Nothing

Select Case Type.GetTypeCode(ce.Type)
    Case TypeCode.Int32, TypeCode.UInt32, TypeCode.Int64, TypeCode.UInt64
        value = ParseNumber(text, target)
    Case TypeCode.Double
        If target.Equals(GetType(Decimal)) Then value = ParseNumber(text, target)
    Case TypeCode.String
        value = ParseEnum(text, target)
End Select

If value IsNot Nothing Then Return Expression.Constant(value, type)

(ParseNumber() and ParseEnum() are functions defined in the class.)

Solution

  • One option is to change the Select Case block to a set of If Else statements, and the comparisons from TypeCode to GetType:

    Dim type = ce.GetType()
    If type Is GetType(Int32) OrElse type Is GetType(UInt32) OrElse _
       type Is GetType(Int64) OrElse type Is GetType(UInt64) Then
        value = ParseNumber(Text, target)
    ElseIf type Is GetType(Double) Then
        If target.Equals(GetType(Decimal)) Then value = ParseNumber(Text, target)
    ElseIf type Is GetType(String) Then
        value = ParseEnum(Text, target)
    End If