/// <summary>Returns the instance value as a <typeparamref name="V"/>, if supported, or <c>null</c>.</summary> /// <typeparam name="V">The target type.</typeparam> /// <param name="instance">An <see cref="IValueProvider"/> instance.</param> /// <returns>A value of type <typeparamref name="V"/>.</returns> public static V GetValueAs <V>(this IValueProvider instance) where V : class { return(instance.GetValueOrDefault <object>(null) as V); }
/// <summary>Returns the instance value cast to <typeparamref name="V"/>.</summary> /// <typeparam name="V">The target type.</typeparam> /// <param name="instance">An <see cref="IValueProvider"/> instance.</param> /// <returns>A value of type <typeparamref name="V"/>.</returns> /// <exception cref="InvalidCastException">The specified cast is invalid.</exception> public static V CastValue <V>(this IValueProvider instance) where V : class { return((V)instance.GetValueOrDefault <object>(null)); }
/// <summary> /// Retrieves a value of type <typeparamref name="V"/>, if supported by the instance, or <c>default(V)</c> otherwise. /// </summary> /// <typeparam name="V">The value type.</typeparam> /// <param name="instance">An <see cref="IValueProvider"/> instance.</param> /// <returns>A value of type <typeparamref name="V"/>.</returns> public static V GetValue <V>(this IValueProvider instance) { return(instance.GetValueOrDefault(default(V))); }