How to dynamic cast from any type

I have a FlattenArray function that returns any so that I can flatten any multidimensional arrays.

FlattenArray(Grid : [][]any) : []any =
    var Result : []any = array{}
    
    # Iterate through each row
    for (Row : Grid):
        # Add all elements from this row to the result
        for (Value : Row):
            set Result = Result + array{Value}
            
    return Result

However, when I then try to cast these any to creative_prop type, I get “the Dynamic cast any to creative_prop: argument type any must be a class.” Searching the documentation I found nothing on how to cast from any type, is this possible? Or can I modify my Flatten array function to specify what type to return?

Don’t think you can cast back to something from any, but you should be able to do this instead

FlattenArray(Array : [][]t where t : type): []t=
    var Result : []t = array{}
    
    # Iterate through each row
    for (Row : Array):
        # Add all elements from this row to the result
        for (Value : Row):
            set Result = Result + array{Value}
            
    return Result

Amazing thank you!

1 Like