本文整理汇总了C#中HttpParameterDescriptor.BindWithAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# HttpParameterDescriptor.BindWithAttribute方法的具体用法?C# HttpParameterDescriptor.BindWithAttribute怎么用?C# HttpParameterDescriptor.BindWithAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpParameterDescriptor
的用法示例。
在下文中一共展示了HttpParameterDescriptor.BindWithAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetParameterBinding
// Determine how a single parameter will get bound.
// This is all sync. We don't need to actually read the body just to determine that we'll bind to the body.
protected virtual HttpParameterBinding GetParameterBinding(HttpParameterDescriptor parameter)
{
// Attribute has the highest precedence
// Presence of a model binder attribute overrides.
ParameterBindingAttribute attr = parameter.ParameterBinderAttribute;
if (attr != null)
{
return attr.GetBinding(parameter);
}
// No attribute, so lookup in global map.
ParameterBindingRulesCollection pb = parameter.Configuration.ParameterBindingRules;
if (pb != null)
{
HttpParameterBinding binding = pb.LookupBinding(parameter);
if (binding != null)
{
return binding;
}
}
// Not explicitly specified in global map or attribute.
// Use a default policy to determine it. These are catch-all policies.
Type type = parameter.ParameterType;
if (TypeHelper.IsSimpleUnderlyingType(type) || TypeHelper.HasStringConverter(type))
{
// For simple types, the default is to look in URI. Exactly as if the parameter had a [FromUri] attribute.
return parameter.BindWithAttribute(new FromUriAttribute());
}
// Fallback. Must be a complex type. Default is to look in body. Exactly as if this type had a [FromBody] attribute.
attr = new FromBodyAttribute();
return attr.GetBinding(parameter);
}