protected override IClientModel VisitLateBoundExpression(LateBoundExpressionNode lateboundExpression)
            {
                if (lateboundExpression.Scope == ExpressionScope.ModelOfParentScope)
                {
                    var outer = _modelStack.Peek();

                    if (lateboundExpression.RecursionLevel < _modelStack.Count && lateboundExpression.RecursionLevel < 100)
                    {
                        var expressionNodes = new IClientModel[100];
                        var recursionLevel  = 0;
                        while (recursionLevel < lateboundExpression.RecursionLevel)
                        {
                            expressionNodes[recursionLevel] = _modelStack.Pop();
                            recursionLevel++;
                        }
                        outer = _modelStack.Peek();
                        for (var i = recursionLevel - 1; i >= 0; i--)
                        {
                            _modelStack.Push(expressionNodes[i]);
                        }
                    }

                    return(outer.Get(lateboundExpression.ItemName));
                }

                return(_modelStack.Peek().Get(lateboundExpression.ItemName));
            }
Exemple #2
0
        public static object RuntimeBind(object model, LateBoundExpressionNode node)
        {
            var itemName      = node.ItemName;
            var memberLocator = node.MemberLocator;

            CheckNotNull(string.Format("Could not bind expression with name '{0}'. The value is null.", node.ItemName),
                         model, node);

            var runtimeModel = model as IRuntimeModel;

            if (runtimeModel != null && runtimeModel.Data != null)
            {
                model = runtimeModel.Data;
            }

            var binder = lateBoundCache.GetOrAdd(Tuple.Create(model.GetType(), itemName), new Func <Tuple <Type, string>, Func <object, object> >(pair =>
            {
                var type = pair.Item1;
                var name = pair.Item2;

                if (name.EndsWith("()"))
                {
                    var function = memberLocator.FindMember(type, name.Substring(0, name.Length - 2), MemberTypes.Method) as MethodInfo;
                    if (function != null)
                    {
                        return(DelegateBuilder.FunctionCall(type, function));
                    }
                }

                var property = memberLocator.FindMember(type, name, MemberTypes.Property) as PropertyInfo;
                if (property != null)
                {
                    return(DelegateBuilder.Property(type, property));
                }

                var field = memberLocator.FindMember(type, name, MemberTypes.Field) as FieldInfo;
                if (field != null)
                {
                    return(DelegateBuilder.Field(type, field));
                }

                var dictionaryType = type.GetDictionaryTypeWithKey <string>();
                if (dictionaryType != null)
                {
                    return(DelegateBuilder.Dictionary(dictionaryType, name));
                }

                return(null);
            }));

            if (binder == null)
            {
                throw new VeilCompilerException("Unable to late-bind '{0}' against model {1}".FormatInvariant(itemName, model.GetType().Name), node);
            }

            var result = binder(model);

            return(result);
        }
Exemple #3
0
        private Expression EvaluateLateBoundExpression(LateBoundExpressionNode node)
        {
            var modelExpression = EvaluateScope(node);

            return(Expression.Call(null, RuntimeBindFunction, new[] {
                modelExpression,
                Expression.Constant(node)
            }));
        }
Exemple #4
0
        private Expression EvaluateLateBoundExpression(LateBoundExpressionNode node)
        {
            var model = EvaluateScope(node.Scope);

            return(Expression.Call(null, runtimeBindFunction, new[] {
                model,
                Expression.Constant(node.ItemName),
                Expression.Constant(node.IsCaseSensitive)
            }));
        }
Exemple #5
0
            protected override JSchema VisitLateBoundExpression(LateBoundExpressionNode lateboundExpression)
            {
                var modelSchema = _schemas.Peek();

                if (lateboundExpression.Scope == ExpressionScope.ModelOfParentScope)
                {
                    if (lateboundExpression.RecursionLevel < _schemas.Count && lateboundExpression.RecursionLevel < 100)
                    {
                        var expressionNodes = new JSchema[100];
                        var recursionLevel  = 0;
                        while (recursionLevel < lateboundExpression.RecursionLevel)
                        {
                            expressionNodes[recursionLevel] = _schemas.Pop();
                            recursionLevel++;
                        }
                        modelSchema = _schemas.Peek();
                        for (var i = recursionLevel - 1; i >= 0; i--)
                        {
                            _schemas.Push(expressionNodes[i]);
                        }
                    }
                }

                string propertyName = lateboundExpression.ItemName;

                modelSchema.Type = JSchemaType.Object;
                JSchema existingSchema;

                if (!modelSchema.Properties.TryGetValue(propertyName, out existingSchema))
                {
                    existingSchema = new JSchema();
                    modelSchema.Properties.Add(propertyName, existingSchema);
                }
                modelSchema.Required.Add(propertyName);

                return(existingSchema);
            }
Exemple #6
0
 private void EvaluateLateBoundExpression(LateBoundExpressionNode node)
 {
     emitter.LoadConstant(node.ItemName);
     emitter.LoadConstant(node.IsCaseSensitive);
     emitter.CallMethod(runtimeBindMethod);
 }
 protected virtual TResult VisitLateBoundExpression(LateBoundExpressionNode lateboundExpression)
 {
     return(null);
 }