/// <summary> /// Converts the value to the specified type. If the value is unable to be converted, the /// value is checked whether it assignable to the specified type. /// </summary> /// <param name="initialValue">The value to convert.</param> /// <param name="culture">The culture to use when converting.</param> /// <param name="targetType">The type to convert the value to.</param> /// <param name="convertedValue">The converted value if the conversion was successful or the default value of <c>T</c> if it failed.</param> /// <returns> /// <c>true</c> if <c>initialValue</c> was converted successfully or is assignable; otherwise, <c>false</c>. /// </returns> public static bool TryConvertOrCast(object initialValue, CultureInfo culture, Type targetType, out object convertedValue) { return(MiscellaneousUtils.TryAction <object>(delegate { return ConvertOrCast(initialValue, culture, targetType); }, out convertedValue)); }
public static bool TryGetSingleItem <T>(IList <T> list, bool returnDefaultIfEmpty, out T value) { return(MiscellaneousUtils.TryAction <T>(() => CollectionUtils.GetSingleItem <T>(list, returnDefaultIfEmpty), out value)); }
public static bool TryParse <T>(string enumMemberName, bool ignoreCase, out T value) where T : struct { ValidationUtils.ArgumentTypeIsEnum(typeof(T), "T"); return(MiscellaneousUtils.TryAction(() => Parse <T>(enumMemberName, ignoreCase), out value)); }
public static string BytesToHex(byte[] bytes) { return(MiscellaneousUtils.BytesToHex(bytes, false)); }
public static bool TryGetSingleItem <T>(IList <T> list, bool returnDefaultIfEmpty, out T value) { return(MiscellaneousUtils.TryAction <T>(delegate { return GetSingleItem(list, returnDefaultIfEmpty); }, out value)); }
public static bool TryConvert(object initialValue, CultureInfo culture, Type targetType, out object convertedValue) { return(MiscellaneousUtils.TryAction <object>(() => ConvertUtils.Convert(initialValue, culture, targetType), out convertedValue)); }
public static Task <T> FromCanceled <T>(this CancellationToken cancellationToken) { MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested); #pragma warning disable CS8603 // Possible null reference return. return(new Task <T>(() => default, cancellationToken));
// From 4.6 on we could use Task.FromCanceled(), but we need an equivalent for // previous frameworks. public static Task FromCanceled(this CancellationToken cancellationToken) { MiscellaneousUtils.Assert(cancellationToken.IsCancellationRequested); return(new Task(() => {}, cancellationToken)); }