Esempio n. 1
0
        /// <summary>
        /// We are going to reference a member item - this is a simple "." coding. If this is a reference
        /// to some sort of array, then we need to deal with getting back the proper array type.
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        protected override Expression VisitMember(MemberExpression expression)
        {
            //
            // See if we have special handling for this.
            //

            var r = TypeHandlers.TryMemberReference(expression, _codeEnv, _codeContext, MEFContainer);

            if (r != null)
            {
                _result = r;
                return(expression);
            }

            //
            // Ok - we need to do this the normal way - we split things in
            // two - and do the base expression and then try to apply the
            // member to that.
            //

            var baseExpr = GetExpression(expression.Expression);

            ///
            /// Figure out how to represent the variable type. We base this on the type - enumerables, for
            /// example, know how to loop, other things like "int" just know how to be simpe values. Eventually
            /// this will likely have to be made "common".
            ///

            _result = null;
            var leafName = expression.Member.Name;

            _codeEnv.AddReferencedLeaf(leafName);

            //
            // If this is a generic - there is pretty much only one thing we know how to deal with, IEnumerable.
            //

            if (expression.Type.IsGenericType)
            {
                if (expression.Type.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    _result = new ValSimple(baseExpr.AsObjectReference(expression) + "." + leafName, expression.Type, baseExpr.Dependants);
                }
                else
                {
                    throw new NotImplementedException("Can't deal with a generic type for iterator for " + expression.Type.Name + ".");
                }
            }

            ///
            /// If we can't figure out what the proper special variable type is from above, then we
            /// need to just fill in the default.
            ///

            if (_result == null)
            {
                _result = new ValSimple(baseExpr.AsObjectReference(expression.Expression) + "." + leafName, expression.Type, baseExpr.Dependants);
            }

            return(expression);
        }