public object FetchActiveRecord(ParameterInfo param, ARFetchAttribute attr, IRequest request)
{
Type type = param.ParameterType;
bool isArray = type.IsArray;
if (isArray) type = type.GetElementType();
ActiveRecordModel model = ActiveRecordModel.GetModel(type);
if (model == null)
{
throw new RailsException(String.Format("'{0}' is not an ActiveRecord " +
"class. It could not be bound to an [ARFetch] attribute.", type.Name));
}
if (model.CompositeKey != null)
{
throw new RailsException("ARFetch only supports single-attribute primary keys");
}
String webParamName = attr.RequestParameterName != null ? attr.RequestParameterName : param.Name;
if (!isArray)
{
return LoadActiveRecord(type, request.Params[webParamName], attr, model);
}
object[] pks = request.Params.GetValues(webParamName);
if (pks == null)
{
pks = new object[0];
}
Array objs = Array.CreateInstance(type, pks.Length);
for(int i = 0; i < objs.Length; i++)
{
objs.SetValue(LoadActiveRecord(type, pks[i], attr, model), i);
}
return objs;
}