属性で装飾されたプロパティを別の名前のリクエスト プロパティにバインドできるカスタム モデル バインダーを作成しようとしています。
JSON リクエスト
{
"app": "acme"
}
依頼モデル(抜粋)
[Alias("app")]
public string ApplicationName { get; set; }
...ApplicationName
値「acme」が入力されるはずです。このためのカスタム モデル バインダーの作成に行き詰まっています。
モデルバインダー
public BindToAliasModelBinder : IModelBinder {
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) {
...
}
}
モデル バインダー プロバイダー
public class BindFromAliasModelBinderProvider : ModelBinderProvider {
public override IModelBinder GetBinder(HttpConfiguration configuration, Type modelType) {
return new BindFromAliasModelBinder();
}
}
プロバイダーをグローバルに登録しましたが、バインダーは期待どおりにヒットしています。次に何をすべきか途方に暮れています - リクエスト値を繰り返し処理し、属性の存在に基づいて条件付きでバインドするにはどうすればよいですか?