Inheritance: Castle.MonoRail.Framework.DataBindAttribute
Esempio n. 1
0
        protected override bool BindComplexParameter(ParameterInfo param, IRequest request, object[] args, int argIndex)
        {
            object[] arBinderAttributes = param.GetCustomAttributes(typeof(ARDataBindAttribute), false);

            if (arBinderAttributes.Length != 0)
            {
                ARDataBindAttribute attr = (ARDataBindAttribute)arBinderAttributes[0];

                args[argIndex] = CustomBindObject(attr.From, param.ParameterType,
                                                  attr.Prefix, attr.NestedLevel, attr.Exclude, attr.Allow, attr.AutoLoad);

                return(true);
            }

            object[] fetchAttributes = param.GetCustomAttributes(typeof(ARFetchAttribute), false);

            if (fetchAttributes.Length != 0)
            {
                ARFetchAttribute attr = (ARFetchAttribute)fetchAttributes[0];
                args[argIndex] = FetchActiveRecord(param, attr, request);
                return(true);
            }

            return(base.BindComplexParameter(param, request, args, argIndex));
        }
Esempio n. 2
0
        /// <summary>
        /// Check if any method argument is associated with an ARDataBinderAttribute
        /// that has the Validate property set to true,
        /// and perform automatic validation for it (as long it inherit from ActiveRecordValidationBase)
        /// </summary>
        protected override object[] BuildMethodArguments(ParameterInfo[] parameters, IRequest request)
        {
            object[] args = base.BuildMethodArguments(parameters, request);

            for (int i = 0; i < args.Length; i++)
            {
                ParameterInfo param = parameters[i];

                object[] bindAttributes = param.GetCustomAttributes(typeof(ARDataBindAttribute), false);

                if (bindAttributes.Length > 0)
                {
                    ARDataBindAttribute dba = bindAttributes[0] as ARDataBindAttribute;

                    if (dba.AutoPersist)
                    {
                        PersistInstances(args[i]);
                    }
                    else if (dba.Validate)
                    {
                        ValidateInstances(args[i], param);
                    }
                }
            }

            return(args);
        }