예제 #1
0
        public Fragment InferFragmentType(Expression expression)
        {
            ArgumentUtility.CheckNotNull("expression", expression);

            var fragmentType = Fragment.CreateEmpty();

            if (expression is Literal)
            {
                fragmentType = Fragment.CreateLiteral();
            }
            else if (expression is Local)
            {
                Local local = (Local)expression;
                fragmentType = Lookup(local.Name.Name);
            }
            else if (expression is Parameter)
            {
                Parameter parameter = (Parameter)expression;
                fragmentType = Lookup(parameter.Name.Name);
            }
            else if (expression is MemberBinding)
            {
                MemberBinding memberBinding = (MemberBinding)expression;
                fragmentType = FragmentUtility.GetMemberBindingFragmentType(memberBinding);
            }
            else if (expression is MethodCall)
            {
                MethodCall methodCall = (MethodCall)expression;
                fragmentType = InferMethodCallReturnFragmentType(methodCall);
            }
            else if (expression is UnaryExpression)
            {
                UnaryExpression unaryExpression = (UnaryExpression)expression;
                fragmentType = InferFragmentType(unaryExpression.Operand);
            }
            else if (expression is Indexer)
            {
                Indexer indexer = (Indexer)expression;
                fragmentType = InferFragmentType(indexer.Object);
            }

            return(fragmentType);
        }