bool IActionBinding.TryBinding(IHttpContext context, IPathStack path, out object[] parameters, out int overloadWeight)
{
foreach (IMappingBinding mapping in this.Mappings)
if (!mapping.TryMapping(context, path))
{
parameters = null;
overloadWeight = 0;
return false;
}
// Allow IExtension to affect mapping?
//foreach (IExtension extension in this.Extensions)
// if (!extension.TryMapping(context, path))
// return false;
overloadWeight = Mappings.Count * 10000;
if (Bindings == null)
{
parameters = new object[0];
return true;
}
int l = Bindings.Length;
parameters = new object[Bindings.Length];
for (int i = 0; i < l; i++)
{
ParamBindings pb = Bindings[i];
if (pb.IsIn)
{
bool bound = false;
int index = path.Index;
foreach (IParameterBinding bindable in pb.Bindings)
{
object obj;
int weight;
if (bindable.TryBinding(context, path, out obj, out weight))
{
bool constrained = false;
if (pb.Constraints != null)
foreach (IBindingConstraint constraint in pb.Constraints)
if (!constraint.TryConstraint(context, obj))
{
constrained = true;
path.ReverseToIndex(index);
break;
}
if (!constrained)
{
overloadWeight += weight;
parameters[i] = obj;
bound = true;
break;
}
}
else
{
path.ReverseToIndex(index);
}
}
if (!bound)
{
overloadWeight = 0;
parameters = null;
return false;
}
}
}
return true;
}