public static object Convert(object initialValue, CultureInfo culture, Type targetType) { object obj; switch (ConvertUtils.TryConvertInternal(initialValue, culture, targetType, out obj)) { case ConvertUtils.ConvertResult.Success: { return(obj); } case ConvertUtils.ConvertResult.CannotConvertNull: { throw new Exception("Can not convert null {0} into non-nullable {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType)); } case ConvertUtils.ConvertResult.NotInstantiableType: { throw new ArgumentException("Target type {0} is not a value type or a non-abstract class.".FormatWith(CultureInfo.InvariantCulture, targetType), "targetType"); } case ConvertUtils.ConvertResult.NoValidConversion: { throw new InvalidOperationException("Can not convert from {0} to {1}.".FormatWith(CultureInfo.InvariantCulture, initialValue.GetType(), targetType)); } default: { throw new InvalidOperationException("Unexpected conversion result."); } } }
private static bool TryConvert( object initialValue, CultureInfo culture, Type targetType, out object value) { try { if (ConvertUtils.TryConvertInternal(initialValue, culture, targetType, out value) == ConvertUtils.ConvertResult.Success) { return(true); } value = (object)null; return(false); } catch { value = (object)null; return(false); } }
// Token: 0x06000E7E RID: 3710 RVA: 0x0005715C File Offset: 0x0005535C private static bool TryConvert([Nullable(2)] object initialValue, CultureInfo culture, Type targetType, [Nullable(2)] out object value) { bool result; try { if (ConvertUtils.TryConvertInternal(initialValue, culture, targetType, out value) == ConvertUtils.ConvertResult.Success) { result = true; } else { value = null; result = false; } } catch { value = null; result = false; } return(result); }
private static bool TryConvert(object initialValue, CultureInfo culture, Type targetType, out object value) { bool flag; try { if (ConvertUtils.TryConvertInternal(initialValue, culture, targetType, out value) != ConvertUtils.ConvertResult.Success) { value = null; flag = false; } else { flag = true; } } catch { value = null; flag = false; } return(flag); }