当前位置: 首页>>代码示例>>C#>>正文


C# Expression.As方法代码示例

本文整理汇总了C#中Expression.As方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.As方法的具体用法?C# Expression.As怎么用?C# Expression.As使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Expression的用法示例。


在下文中一共展示了Expression.As方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RewriteBranch

 private void RewriteBranch(Expression cond)
 {
     // SPARC architecture always has delay slot.
     ric.Class = RtlClass.ConditionalTransfer;
     var rtlClass = RtlClass.ConditionalTransfer | RtlClass.Delay;
     if (instrCur.Annul)
         rtlClass |= RtlClass.Annul;
     Constant c;
     if (cond.As(out c) && c.ToBoolean())
     {
         emitter.Goto(((AddressOperand)instrCur.Op1).Address, rtlClass);
     }
     else
     {
         emitter.Branch(cond, ((AddressOperand)instrCur.Op1).Address, rtlClass);
     }
 }
开发者ID:uxmal,项目名称:reko,代码行数:17,代码来源:SparcRewriter.Control.cs

示例2: EvaluateExpression

        public object EvaluateExpression(Expression expression)
        {
            _lastSyntaxNode = expression;

            switch (expression.Type)
            {
                case SyntaxNodes.AssignmentExpression:
                    return _expressions.EvaluateAssignmentExpression(expression.As<AssignmentExpression>());

                case SyntaxNodes.ArrayExpression:
                    return _expressions.EvaluateArrayExpression(expression.As<ArrayExpression>());

                case SyntaxNodes.BinaryExpression:
                    return _expressions.EvaluateBinaryExpression(expression.As<BinaryExpression>());

                case SyntaxNodes.CallExpression:
                    return _expressions.EvaluateCallExpression(expression.As<CallExpression>());

                case SyntaxNodes.ConditionalExpression:
                    return _expressions.EvaluateConditionalExpression(expression.As<ConditionalExpression>());

                case SyntaxNodes.FunctionExpression:
                    return _expressions.EvaluateFunctionExpression(expression.As<FunctionExpression>());

                case SyntaxNodes.Identifier:
                    return _expressions.EvaluateIdentifier(expression.As<Identifier>());

                case SyntaxNodes.Literal:
                    return _expressions.EvaluateLiteral(expression.As<Literal>());

                case SyntaxNodes.RegularExpressionLiteral:
                    return _expressions.EvaluateLiteral(expression.As<Literal>());

                case SyntaxNodes.LogicalExpression:
                    return _expressions.EvaluateLogicalExpression(expression.As<LogicalExpression>());

                case SyntaxNodes.MemberExpression:
                    return _expressions.EvaluateMemberExpression(expression.As<MemberExpression>());

                case SyntaxNodes.NewExpression:
                    return _expressions.EvaluateNewExpression(expression.As<NewExpression>());

                case SyntaxNodes.ObjectExpression:
                    return _expressions.EvaluateObjectExpression(expression.As<ObjectExpression>());

                case SyntaxNodes.SequenceExpression:
                    return _expressions.EvaluateSequenceExpression(expression.As<SequenceExpression>());

                case SyntaxNodes.ThisExpression:
                    return _expressions.EvaluateThisExpression(expression.As<ThisExpression>());

                case SyntaxNodes.UpdateExpression:
                    return _expressions.EvaluateUpdateExpression(expression.As<UpdateExpression>());

                case SyntaxNodes.UnaryExpression:
                    return _expressions.EvaluateUnaryExpression(expression.As<UnaryExpression>());

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:skipme,项目名称:jint,代码行数:61,代码来源:Engine.cs

示例3: ProcessExpression

        private void ProcessExpression(Expression exp, ParserContext context)
        {
            if (exp == null)
            {
                return;
            }

            if (exp is BinaryExpression)
            {
                var bexp = exp.As<BinaryExpression>();

                ProcessExpression(bexp.Left, context);

                ProcessExpression(bexp.Right, context);
                return;
            }

            if (exp is CallExpression)
            {
                var invexp = exp.As<CallExpression>();
                ProcessExpression(invexp.Callee, context);

                foreach (var arg in invexp.Arguments)
                {
                    var cc = new ParserContext(context, copyNames: true);
                    cc.NameStack.Insert(0, "?");
                    ProcessExpression(arg, cc);
                }
                return;
            }

            if (exp is UnaryExpression)
            {
                var uexp = (UnaryExpression)exp;
                ProcessExpression(uexp.Argument, context);
                return;
            }

            if (exp is IFunctionDeclaration)
            {
                ProcessFunctionDeclaration((IFunctionDeclaration)exp, context);
                return;
            }

            if (exp is ObjectExpression)
            {
                var ojexp = (ObjectExpression)exp;

                if (ojexp.Properties.Any())
                {
                    var codeNode = new CodeNode
                    {
                        Alias = context.GetNameFromStack(),
                        NodeType = CodeNodeType.Object,
                        StartLine = exp.Location.Start.Line,
                        StartColumn = exp.Location.Start.Column,
                        EndLine = exp.Location.End.Line,
                        EndColumn = exp.Location.End.Column,
                        Comment = _comments.GetComment(exp.Location.Start.Line, exp.Location.End.Line)
                    };
                    Hierarchy<CodeNode> hi = context.Nodes.Add(codeNode);

                    foreach (var element in ojexp.Properties)
                    {
                        var childContext = new ParserContext(hi);
                        ProcessExpression((Expression)element.Key, childContext);
                        ProcessExpression(element.Value, childContext);
                    }
                }

                return;
            }

            if (exp is AssignmentExpression)
            {
                var qexp = (AssignmentExpression)exp;
                ProcessExpression(qexp.Left, context);
                ProcessExpression(qexp.Right, context);
                return;
            }

            if (exp is Identifier)
            {
                var iexp = (Identifier)exp;
                context.NameStack.Push(iexp.Name);
                return;
            }

            if (exp is Literal)
            {
                var slexp = (Literal)exp;
                context.NameStack.Push(slexp.Raw);
                return;
            }

            if (exp is MemberExpression)
            {
                var mexp = exp.As<MemberExpression>();
                ProcessExpression(mexp.Property, context);
                ProcessExpression(mexp.Object, new ParserContext(context));
//.........这里部分代码省略.........
开发者ID:hxhlb,项目名称:jsparser,代码行数:101,代码来源:JavaScriptStructureParserV2.cs

示例4: ProcessModuleDefinition

        private void ProcessModuleDefinition(Expression moduleNode, RequireCall parentCall, NodeWithChildren parentNode)
        {
            // hardcoded check for the factory pattern that cheks if we have amd support
            // this will happen when the module node is an identifier.
            // We'll go up the tree until we find the first enclosing function definition. If that 
            // function has an argument with the same identifier as the module and the function is self-calling with a function 
            // as its parameter, we'll process that function as a child of this requireCall
            if (moduleNode is Identifier)
            {
                var moduleIdentifier = moduleNode.As<Identifier>();

                // backtrack to the first callExpression, skipping the one that we're in
                var skipped = 0;
                var currentParent = parentNode;
                while (currentParent != null)
                {
                    if (currentParent.Node is CallExpression)
                    {
                        if (skipped > 0)
                        {
                            break;    
                        }

                        skipped++;
                    }

                    currentParent = currentParent.Parent;
                }

                if (currentParent == null)
                {
                    return;
                }

                var containingCall = currentParent.Node.As<CallExpression>();
                if (containingCall.Arguments.Count() != 1)
                {
                    return;
                }

                // check if our containing function has one argument with the same name as the factory identifier we've received
                var containingCallee = containingCall.Callee.As<FunctionExpression>();
                if (containingCallee.Parameters.Count() != 1)
                {
                    return;
                }

                var calleeParam = containingCallee.Parameters.ElementAt(0).As<Identifier>();
                if (calleeParam == null)
                {
                    return;
                }

                if (calleeParam.Name != moduleIdentifier.Name)
                {
                    return;
                }

                var argumentFunction = containingCall.Arguments.ElementAt(0).As<FunctionExpression>();
                if (argumentFunction == null)
                {
                    return;
                }

                parentCall.ModuleDefinitionNode = argumentFunction;
                this.VisitExpression(argumentFunction, parentCall, currentParent);
                this.nodesToSkip.Add(argumentFunction.Location);
            }
            else
            {
                this.VisitExpression(moduleNode, parentCall, parentNode);    
            }
        }
开发者ID:hasaki,项目名称:RequireJSDotNet,代码行数:73,代码来源:RequireVisitor.cs

示例5: ProcessDependencyArray

        private IEnumerable<string> ProcessDependencyArray(Expression depsNode, RequireCall parentCall)
        {
            var depsArray = depsNode.As<ArrayExpression>();
            if (depsArray == null)
            {
                yield break;

                // throw new Exception("Dependency array node was not an ArrayExpression " + relativeFileName);    
            }

            parentCall.DependencyArrayNode = depsArray;

            foreach (var expression in depsArray.Elements)
            {
                var val = expression.As<Literal>();
                if (val == null)
                {
                    // TODO: decide if we want to ignore, throw exception or add basic support for string concatenation
                    // An implementation where the user could define a value for a variable name in case of string concatenation
                    // (or a set of values, and we would all of the possible values in the dependency array)
                    //// throw new Exception("One of the elements in a require() dependency array was not a string literal");
                    continue;
                }
               
                yield return val.Value.ToString();
            }
        }
开发者ID:hasaki,项目名称:RequireJSDotNet,代码行数:27,代码来源:RequireVisitor.cs

示例6: VisitExpression

        private void VisitExpression(Expression node, RequireCall parentCall, NodeWithChildren parentNode)
        {
            if (node == null || this.ShouldSkipNode(node))
            {
                return;
            }

            var currentNode = new NodeWithChildren { Node = node };
            if (parentNode != null)
            {
                currentNode.Parent = parentNode;
                parentNode.Children.Add(currentNode);
            }
            else
            {
                visitedNodes.Add(currentNode);
            }

            switch (node.Type)
            {
                case SyntaxNodes.ArrayExpression:
                    var arrExpression = node.As<ArrayExpression>();
                    VisitNodeEnumerator(arrExpression.Elements, parentCall, currentNode);
                    break;
                case SyntaxNodes.AssignmentExpression:
                    var assignment = node.As<AssignmentExpression>();
                    VisitExpression(assignment.Right, parentCall, currentNode);
                    break;
                case SyntaxNodes.BinaryExpression:
                    var binaryExpression = node.As<BinaryExpression>();
                    VisitExpression(binaryExpression.Left, parentCall, currentNode);
                    VisitExpression(binaryExpression.Right, parentCall, currentNode);
                    break;
                case SyntaxNodes.CallExpression:
                    // TOOD: do stuff with this
                    var callExpression = node.As<CallExpression>();
                    var callee = callExpression.Callee;
                    if (callee.Type == SyntaxNodes.Identifier)
                    {
                        var calleeIdentifier = callee.As<Identifier>();

                        if (calleeIdentifier.Name == "require")
                        {
                            ProcessRequireCall(ref parentCall, callExpression, currentNode);
                        }

                        if (calleeIdentifier.Name == "define")
                        {
                            ProcessDefineCall(ref parentCall, callExpression, currentNode);
                        }
                    }
                    else
                    {
                        this.VisitExpression(callee, parentCall, currentNode);
                        VisitNodeEnumerator(callExpression.Arguments, parentCall, currentNode);
                    }

                    break;
                case SyntaxNodes.ConditionalExpression:
                    var conditionalExpression = node.As<ConditionalExpression>();
                    VisitExpression(conditionalExpression.Consequent, parentCall, currentNode);
                    VisitExpression(conditionalExpression.Alternate, parentCall, currentNode);
                    break;
                case SyntaxNodes.FunctionExpression:
                    var functionExpression = node.As<FunctionExpression>();
                    VisitStatement(functionExpression.Body, parentCall, currentNode);
                    break;
                case SyntaxNodes.LogicalExpression:
                    var logicalExpression = node.As<LogicalExpression>();
                    VisitExpression(logicalExpression.Left, parentCall, currentNode);
                    VisitExpression(logicalExpression.Right, parentCall, currentNode);
                    break;
                case SyntaxNodes.NewExpression:
                    var newExpression = node.As<NewExpression>();
                    VisitNodeEnumerator(newExpression.Arguments, parentCall, currentNode);
                    VisitExpression(newExpression.Callee, parentCall, currentNode);
                    break;
                case SyntaxNodes.ObjectExpression:
                    var objectExpression = node.As<ObjectExpression>();
                    VisitNodeEnumerator(objectExpression.Properties, parentCall, currentNode);
                    break;
                case SyntaxNodes.Property:
                    var property = node.As<Property>();
                    VisitExpression(property.Value, parentCall, currentNode);
                    break;
                case SyntaxNodes.SequenceExpression:
                    var sequence = node.As<SequenceExpression>();
                    VisitNodeEnumerator(sequence.Expressions, parentCall, currentNode);
                    break;
                case SyntaxNodes.UnaryExpression:
                    var unary = node.As<UnaryExpression>();
                    VisitExpression(unary.Argument, parentCall, currentNode);
                    break;
                case SyntaxNodes.VariableDeclarator:
                    var variableDeclarator = node.As<VariableDeclarator>();
                    VisitExpression(variableDeclarator.Init, parentCall, currentNode);
                    break;
                default:
                    break;
            }
//.........这里部分代码省略.........
开发者ID:hasaki,项目名称:RequireJSDotNet,代码行数:101,代码来源:RequireVisitor.cs


注:本文中的Expression.As方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。