/// <summary> /// Parses the specified <paramref name="exception"/> for a match on <typeparamref name="TResult"/>. /// </summary> /// <typeparam name="TResult">The type of the <paramref name="exception"/> to find a match on.</typeparam> /// <param name="exception">The exception to parse for a match on <typeparamref name="TResult"/>.</param> /// <returns>The matched <paramref name="exception"/> cast as <typeparamref name="TResult"/> or <c>null</c> if no match could be resolved.</returns> /// <exception cref="System.ArgumentNullException"> /// <paramref name="exception"/> is null. /// </exception> public static TResult Parse <TResult>(Exception exception) where TResult : Exception { Type resultType = typeof(TResult); var exceptions = Flatten(exception); foreach (var e in exceptions) { Type sourceType = e.GetType(); if (TypeUtility.ContainsType(sourceType, resultType)) { return(e as TResult); } } return(null); }
/// <summary> /// Determines whether the specified source type contains one or more of the specified target types. /// </summary> /// <param name="source">The source type to match against.</param> /// <param name="targets">The target types to be matched against.</param> /// <returns> /// <c>true</c> if the specified source contains one or more of the specified target types; otherwise, <c>false</c>. /// </returns> public static bool HasTypes(this Type source, params Type[] targets) { return(TypeUtility.ContainsType(source, targets)); }