예제 #1
0
        /// <summary>
        /// Lookup an expression factory used to coerce method parameters in context under key
        /// <code>"javax.el.ExpressionFactory"</code>.
        /// If no expression factory can be found under that key, use a default instance created with
        /// <seealso cref="ExpressionFactory.newInstance()"/>. </summary>
        /// <param name="context">
        ///            The context of this evaluation. </param>
        /// <returns> expression factory instance </returns>
        private ExpressionFactory GetExpressionFactory(ELContext context)
        {
            object obj = context.GetContext(typeof(ExpressionFactory));

            if (obj is ExpressionFactory)
            {
                return((ExpressionFactory)obj);
            }
            if (defaultFactory == null)
            {
                defaultFactory = ExpressionFactory.NewInstance();
            }
            return(defaultFactory);
        }
        public override object GetValue(ELContext context, object @base, object property)
        {
            if (property != null)
            {
                var @object = context.GetContext(typeof(IScope));
                if (@object != null)
                {
                    var  variableScope = (Dictionary <string, Type>)@object;
                    Type type;
                    variableScope.TryGetValue(property.ToString(), out type);
                    if (type != null)
                    {
                        if (IsResolvable(type))
                        {
                            if (Context.CommandContext.Scope != null)
                            {
                                if (Context.CommandContext.Scope.IsRegistered(type))
                                {
                                    var val = Context.CommandContext.Scope.Resolve(type);
                                    context.PropertyResolved = true;
                                    return(val);
                                }
                            }
                            else
                            {
                                using (var scope = ObjectContainer.BeginLifetimeScope())
                                {
                                    if (scope.IsRegistered(type))
                                    {
                                        var val = scope.Resolve(type);
                                        context.PropertyResolved = true;
                                        return(val);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }