Castle.MonoRail.ActiveRecordSupport.ARFetcher.FetchActiveRecord C# (CSharp) Méthode

FetchActiveRecord() public méthode

public FetchActiveRecord ( ParameterInfo param, ARFetchAttribute attr, IRequest request ) : object
param System.Reflection.ParameterInfo
attr ARFetchAttribute
request IRequest
Résultat object
		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;
		}

Usage Example

        public virtual object Bind(IEngineContext context, IController controller, IControllerContext controllerContext, ParameterInfo parameterInfo)
        {
            EnsureBinderExists();

            var fetcher = new ARFetcher(binder.Converter);

            return(fetcher.FetchActiveRecord(parameterInfo, this, context.Request, controllerContext.CustomActionParameters));
        }
All Usage Examples Of Castle.MonoRail.ActiveRecordSupport.ARFetcher::FetchActiveRecord