// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.Http.Controllers;
using System.Web.Http.Internal;
namespace System.Web.Http.Description
{
///
/// Describes a parameter on the API defined by relative URI path and HTTP method.
///
public class ApiParameterDescription
{
///
/// Gets or sets the name.
///
///
/// The name.
///
public string Name { get; set; }
///
/// Gets or sets the documentation.
///
///
/// The documentation.
///
public string Documentation { get; set; }
///
/// Gets or sets the source of the parameter. It may come from the request URI, request body or other places.
///
///
/// The source.
///
public ApiParameterSource Source { get; set; }
///
/// Gets or sets the parameter descriptor.
///
///
/// The parameter descriptor. if (and only if) a
/// parameter is declared in route template but unused in the API. Never- for other
/// sources.
///
///
/// For more information on the case, search for "undeclared"
/// route parameter handling.
///
public HttpParameterDescriptor ParameterDescriptor { get; set; }
internal IEnumerable GetBindableProperties()
{
return GetBindableProperties(ParameterDescriptor.ParameterType);
}
internal bool CanConvertPropertiesFromString()
{
return GetBindableProperties().All(p => TypeHelper.CanConvertFromString(p.PropertyType));
}
internal static IEnumerable GetBindableProperties(Type type)
{
return type.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.GetGetMethod() != null && p.GetSetMethod() != null);
}
}
}