Convert String to Type unknown at compile time C# : Given a string and a type of number, I would like to check if the string can be converted to that type and would like the string to be converted to that type if possible. Bellow is the sudo code for what I am trying to do:

    public bool DataIsValid(string s, Type someNumType) {
        d = 0; // a class member variable

        if (s.CanBeConvertedTo(someNumType)) {
            d = (double)s;
            return true;
        } else {
            return false;
    }


I'm always trying to convert a string to some type of number but I don't know what type. I've tried using a try/catch block with

    d = (double)Convert.ChangeType(s, someNumType);
but this only works for doubles and not integers.

Thanks in advance.