public ViewDataInfo Eval(string expression) { ViewDataInfo evaluated = EvalComplexExpression( _dictionary, expression); return(evaluated); }
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); }
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)); }
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)); }
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) }); }