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


C# Grammar.ToString方法代码示例

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


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

示例1: Visit

        public TypeInferenceUnit Visit(Grammar.Expressions.RelinqScriptExpression e)
        {
            if (e == null)
            {
                return null;
            }
            else
            {
                switch (e.NodeType)
                {
                    case RelinqExpressionType.Keyword:
                        var ke = (Grammar.Expressions.KeywordExpression)e;
                        return new KeywordExpression(ke.Name);

                    case RelinqExpressionType.Variable:
                        var ve = (Grammar.Expressions.VariableExpression)e;
                        return new VariableExpression(ve.Name);

                    case RelinqExpressionType.Constant:
                        var le = (Grammar.Expressions.ConstantExpression)e;
                        return new LiteralExpression(le.Data);

                    case RelinqExpressionType.New:
                        var je = (Grammar.Expressions.NewExpression)e;
                        var dic = new Dictionary<String, TypeInferenceUnit>();
                        je.Props.ForEach(kvp => dic.Add(kvp.Key, Visit(kvp.Value)));
                        return new JsonExpression(dic);

                    case RelinqExpressionType.Lambda:
                        var lae = (Grammar.Expressions.LambdaExpression)e;
                        return new LambdaExpression(lae.Args, Visit(lae.Body));

                    case RelinqExpressionType.Field:
                        var fe = (Grammar.Expressions.FieldExpression)e;
                        return new FieldExpression(fe.Name, Visit(fe.Target));

                    case RelinqExpressionType.Call:
                        var ce = (Grammar.Expressions.CallExpression)e;

                        // To express parameter conversion semantics we prepare N auxiliary conversion expressions
                        // One might think that target expression also needs conversion stuff 
                        // when the method is called in extension style. However that's unnecessary 
                        // since GetMethods dispenser will be set up to yield extension methods 
                        // in form of forged instance methods.
                        //
                        // Conversion calls have special name that matches both "op_Implicit" and "op_Explicit"
                        // To provide unified approach to conversions, inheritance-based coercions 
                        // are treated in a special way: when resolver will ask ReflectionHelper for 
                        // conversion operators they will be forged and yielded as "op_Implicit" 
                        // dynamic methods along with real ops.

                        // upd. Commenting this so far. Nicely working method alternative resolution
                        // based on type alternatives + conversion nodes for targets/args
                        // will be implemented only in v4.

//                        var argConversions = 
//                            ce.Args.Select(arg => new ConversionExpression(Visit(arg))).ToArray();
//                        return new CallExpression(ce.Name, Visit(ce.Target), argConversions);

                        // todo: jeez.. wtf
                        var args = ce.Args.Select(arg => Visit(arg)).ToArray();
                        return new CallExpression(ce.Name, Visit(ce.Target), args);

                    case RelinqExpressionType.Conditional:
                        var te = (Grammar.Expressions.ConditionalExpression)e;

                        // todo: insert conversion nodes for ifTrue and ifFalse expressions
                        return new ConditionalExpression(Visit(te.Condition), Visit(te.IfTrue), Visit(te.IfFalse));

                    default:
                        throw new NotSupportedException(e.ToString());
                }
            }
        }
开发者ID:xeno-by,项目名称:relinq,代码行数:74,代码来源:TypeInferenceAstBuilder.cs


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