private static ExpressionNode ParseAgainstModel(string originalExpression, string expression, SuperSimpleTemplateParserScope scope, ExpressionScope expressionScope) { var subModelIndex = expression.IndexOf('.'); if (subModelIndex >= 0) { var subModel = ParseAgainstModel(originalExpression, expression.Substring(0, subModelIndex), scope, expressionScope); return SyntaxTreeExpression.SubModel( subModel, ParseAgainstModel(originalExpression, expression.Substring(subModelIndex + 1), new SuperSimpleTemplateParserScope { Block = scope.Block, ModelType = subModel.ResultType }, ExpressionScope.CurrentModelOnStack) ); } var propertyInfo = scope.ModelType.GetProperty(expression); if (propertyInfo != null) return SyntaxTreeExpression.Property(scope.ModelType, expression, expressionScope); var fieldInfo = scope.ModelType.GetField(expression); if (fieldInfo != null) return SyntaxTreeExpression.Field(scope.ModelType, expression, expressionScope); if (IsLateBoundAcceptingType(scope.ModelType)) return SyntaxTreeExpression.LateBound(expression, true, expressionScope); if (expression.StartsWith("Has")) { var collectionExpression = ParseAgainstModel(originalExpression, expression.Substring(3), scope, expressionScope); return SyntaxTreeExpression.HasItems(collectionExpression); } throw new VeilParserException(String.Format("Unable to parse model expression '{0}'", originalExpression)); }
private static ExpressionNode ParseAgainstModel(string originalExpression, string expression, SuperSimpleTemplateParserScope scope, ExpressionScope expressionScope) { var subModelIndex = expression.IndexOf('.'); if (subModelIndex >= 0) { var subModel = ParseAgainstModel(originalExpression, expression.Substring(0, subModelIndex), scope, expressionScope); return(SyntaxTreeExpression.SubModel( subModel, ParseAgainstModel(originalExpression, expression.Substring(subModelIndex + 1), new SuperSimpleTemplateParserScope { Block = scope.Block, ModelType = subModel.ResultType }, ExpressionScope.CurrentModelOnStack) )); } var propertyInfo = scope.ModelType.GetProperty(expression); if (propertyInfo != null) { return(SyntaxTreeExpression.Property(scope.ModelType, expression, expressionScope)); } var fieldInfo = scope.ModelType.GetField(expression); if (fieldInfo != null) { return(SyntaxTreeExpression.Field(scope.ModelType, expression, expressionScope)); } if (IsLateBoundAcceptingType(scope.ModelType)) { return(SyntaxTreeExpression.LateBound(expression, true, expressionScope)); } if (expression.StartsWith("Has")) { var collectionExpression = ParseAgainstModel(originalExpression, expression.Substring(3), scope, expressionScope); return(SyntaxTreeExpression.HasItems(collectionExpression)); } throw new VeilParserException(String.Format("Unable to parse model expression '{0}'", originalExpression)); }