Skip to content

Using CanConvertTo

Lorenz Lo Sauer edited this page Oct 3, 2016 · 1 revision

The wrapper function CanConvertTo allows intuitively checking whether an converter exists for the given input and output types. The function returns true upon success, else false, and is parametrically identical to the usage of CastTo:

    if("500".CanConvertTo(1337))
    { 
        // ... CastTo
    }

    if("500".CanConvertTo<int>())
    {
        // ... CastTo
    }

    if("500".CanConvertTo(0f, Point.Empty))
    {
        // ... ConvertTo
    }

    if("500".CanConvertTo<int, Point>())
    {
        // ... ConvertTo
    }