// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using Microsoft.AspNet.Mvc.Core; namespace Microsoft.AspNet.Mvc.Description { /// /// A metadata description of the source of an for an HTTP request. /// [DebuggerDisplay("Source: {DisplayName}")] public class ApiParameterSource : IEquatable { /// /// An for the request body. /// public static readonly ApiParameterSource Body = new ApiParameterSource( "Body", Resources.ApiParameterSource_Body); /// /// An for a custom model binder (unknown data source). /// public static readonly ApiParameterSource Custom = new ApiParameterSource( "Custom", Resources.ApiParameterSource_Custom); /// /// An for the request form-data. /// public static readonly ApiParameterSource Form = new ApiParameterSource( "Form", Resources.ApiParameterSource_Form); /// /// An for the request headers. /// public static readonly ApiParameterSource Header = new ApiParameterSource( "Header", Resources.ApiParameterSource_Header); /// /// An for a parameter that should be hidden. Used when /// a parameter cannot be set with user input. /// public static readonly ApiParameterSource Hidden = new ApiParameterSource( "Hidden", Resources.ApiParameterSource_Hidden); /// /// An for model binding. Includes form-data, query-string /// and headers from the request. /// public static readonly ApiParameterSource ModelBinding = new ApiParameterSource( "ModelBinding", Resources.ApiParameterSource_ModelBinding); /// /// An for the request url path. /// public static readonly ApiParameterSource Path = new ApiParameterSource( "Path", Resources.ApiParameterSource_Path); /// /// An for the request query-string. /// public static readonly ApiParameterSource Query = new ApiParameterSource( "Query", Resources.ApiParameterSource_Query); /// /// Creates a new . /// /// The id. Used for comparison. /// The display name. public ApiParameterSource([NotNull] string id, string displayName) { Id = id; DisplayName = displayName; } /// /// Gets the display name. /// public string DisplayName { get; } /// /// Gets the id. /// public string Id { get; } /// public bool Equals(ApiParameterSource other) { return other == null ? false : string.Equals(other.Id, Id, StringComparison.Ordinal); } /// public override bool Equals(object obj) { return Equals(obj as ApiParameterSource); } /// public override int GetHashCode() { return Id.GetHashCode(); } /// public static bool operator ==(ApiParameterSource s1, ApiParameterSource s2) { if (object.ReferenceEquals(s1, null)) { return object.ReferenceEquals(s2, null); ; } return s1.Equals(s2); } /// public static bool operator !=(ApiParameterSource s1, ApiParameterSource s2) { return !(s1 == s2); } } }