HttpParameterBinding を継承し、特定のパラメーターにカスタム動作を適用するカスタム パラメーター バインダーを実装しています。場合によっては、カスタム動作を適用したくない場合があります。その場合、Web API が既定で行うことに従いたいと思います。この決定は、ExecuteBindingAsync で行われます。ExecuteBindingAsync でこの既定の動作を実装するにはどうすればよいですか?
これは通常、起動時にバインディングを登録するときにパラメーター バインディングを適用しないことによって行われると思います(つまり、ParameterBindingRules コレクションへのハンドラーは null を返し、Web API が既定のバインディングをパラメーターにバインドできるようにします)。ただし、私の場合、実行時にバインディングを適用するかどうかを決定する必要があるため、ExecuteBindingAsync でこれを行う必要があります。
カスタム HttpParameterBinding クラスで次のようなことをしようとしています。
public override async Task ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
{
if (IsCustomBindingNeeded()) {
// apply custom binding logic... call SetValue()... I'm good with this part
}
else {
// ***************************************************************
// This is where I want to use the default implementation.
// Maybe something like this (using a made up class name):
await return new WhateverDefaultParameterBinding().ExecuteBindingAsync(metadataProvider, actionContext, cancellationToken);
// ...or at least be able to call GetValue() and get the correct value and then I can call SetValue()
// ***************************************************************
}
}
GetValue() を呼び出してみましたが、常に null が返されます。基本クラス (HttpParameterBinding) が値を作成できるように、実行する必要がある追加の手順があると思います。
私の好みは、その既定のロジックを含む .NET フレームワーク内のメソッドを直接呼び出すことです。そのロジックを複製する必要はありません。