Пример #1
0
        public ViewDataInfo Eval(string expression)
        {
            ViewDataInfo evaluated = EvalComplexExpression(
                _dictionary, expression);

            return(evaluated);
        }
Пример #2
0
        private static ViewDataInfo EvalComplexExpression(object instance, string expression)
        {
            foreach (ExpressionPair pair in GetRightToLeftExpressions(expression))
            {
                string subExpression  = pair.Left;
                string postExpression = pair.Right;

                ViewDataInfo subTarget = GetPropertyValue(instance, subExpression);
                if (subTarget != null)
                {
                    if (String.IsNullOrEmpty(postExpression))
                    {
                        return(subTarget);
                    }

                    if (subTarget.Value != null)
                    {
                        ViewDataInfo potential =
                            EvalComplexExpression(subTarget.Value, postExpression);
                        if (potential != null)
                        {
                            return(potential);
                        }
                    }
                }
            }
            return(null);
        }
Пример #3
0
        protected string Template(string expression, string templateName,
                                  string htmlElementName, DataBoundControlMode mode)
        {
            Type   containerType = null;
            Type   modelType     = null;
            object modelValue    = null;
            string propertyName  = null;

            ViewDataInfo vdi = Context.ViewData.GetViewDataInfo(expression);

            if (vdi != null)
            {
                containerType = vdi.Container.GetType();

                if (vdi.Descriptor != null)
                {
                    propertyName = vdi.Descriptor.Name;
                    modelType    = vdi.Descriptor.PropertyType;
                }

                modelValue = vdi.Value;
                if (modelValue != null)
                {
                    modelType = modelValue.GetType();
                }
            }

            return(Render(mode, templateName, htmlElementName ?? expression,
                          containerType, modelType ?? typeof(string), propertyName, modelValue));
        }
Пример #4
0
        private ModelValidatorSet GetValidatorsFromExpression(string expression)
        {
            if (String.IsNullOrEmpty(expression))
            {
                return(new ModelValidatorSet(Context.ViewData.Validator));
            }

            ViewDataInfo vdi = Context.ViewData.GetViewDataInfo(expression);

            if (vdi == null)
            {
                return(new ModelValidatorSet());
            }

            Type   containerType = null;
            Type   modelType     = null;
            string propertyName  = null;
            object model         = vdi.Value;

            if (vdi.Container != null)
            {
                containerType = vdi.Container.GetType();
            }

            if (vdi.Descriptor != null)
            {
                propertyName = vdi.Descriptor.Name;
                modelType    = vdi.Descriptor.PropertyType;
            }

            if (model != null && modelType == null)
            {
                modelType = model.GetType();
            }

            return(GetValidatorsFromProvider(containerType, modelType ?? typeof(string), propertyName));
        }
Пример #5
0
        private static ViewDataInfo GetPropertyValue(object container, string propertyName)
        {
            ViewDataInfo value = GetIndexedPropertyValue(container, propertyName);

            if (value != null)
            {
                return(value);
            }

            ViewDataDictionary vdd = container as ViewDataDictionary;

            if (vdd != null)
            {
                container = vdd.Model;
            }

            if (container == null)
            {
                return(null);
            }

            PropertyDescriptor descriptor = TypeDescriptor.GetProperties(container)
                                            .Find(propertyName, true);

            if (descriptor == null)
            {
                return(null);
            }

            return(new ViewDataInfo()
            {
                Container = container,
                Descriptor = descriptor,
                Value = descriptor.GetValue(container)
            });
        }