eightHundreds
6/24/2017 - 2:59 AM

通用装换,判断指定字符串能不能转换成指定Type

通用装换,判断指定字符串能不能转换成指定Type

public static bool Is(this string input, Type targetType)
{
    try
    {
        TypeDescriptor.GetConverter(targetType).ConvertFromString(input);
        return true;
    }
    catch
    {
        return false;
    }
}