static bool TryGetRequestedApiVersion(HttpContext httpContext, IApiVersioningFeature feature, out ApiVersion apiVersion) { Contract.Requires(httpContext != null); Contract.Requires(feature != null); try { apiVersion = feature.RequestedApiVersion; } catch (AmbiguousApiVersionException) { apiVersion = default; return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="ApiVersionUrlHelper"/> class. /// </summary> /// <param name="actionContext">The current <see cref="ActionContext">action context</see>.</param> /// <param name="url">The inner <see cref="IUrlHelper">URL helper</see>.</param> public ApiVersionUrlHelper(ActionContext actionContext, IUrlHelper url) { ActionContext = actionContext ?? throw new ArgumentNullException(nameof(actionContext)); Url = url; feature = actionContext.HttpContext.Features.Get <IApiVersioningFeature>(); }