Ejemplo n.º 1
0
            string ParsePropertyName(Expression expr, Token exprToken)
            {
                //Debug.Assert(expr != null);
                string propName = null;

                if (Token.Keyword == Keyword.As)
                {
                    NextToken();
                    propName = Token.GetIdentifier();
                    if (propertyNames.Contains(propName))
                    {
                        throw Error.AliasNameAlreadyUsed(Token, propName);
                    }

                    NextToken();
                }
                else
                {
                    switch (expr.NodeType)
                    {
                    case ExpressionType.MemberAccess:
                        propName = ((MemberExpression)expr).Member.Name;
                        break;

                    case ExpressionType.Call:
                        var call = ((MethodCallExpression)expr);
                        if (call.Method.Name == "get_Item" && call.Arguments.Count == 1 &&
                            call.Arguments[0].NodeType == ExpressionType.Constant)
                        {
                            propName = ((ConstantExpression)call.Arguments[0]).Value.ToString();
                        }
                        else
                        {
                            propName = call.Method.Name;
                        }

                        break;

                    case ExpressionType.Parameter:
                        propName = ((ParameterExpression)expr).Name;
                        break;
                    }
                    propName = UniquePropertyName(propName);
                }


                if (propName == null)
                {
                    throw Error.ParseError(exprToken, Res.MissingAsClause);
                }

                Debug.Assert(propertyNames.Contains(propName) == false);
                propertyNames.Add(propName);

                return(propName);
            }