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


C# MethodDeclaration.AllPrimitiveExpressions方法代码示例

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


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

示例1: FindCandidates

        private IEnumerable<Holder> FindCandidates(MethodDeclaration right, int count)
        {
            var rights_primitives = right.AllPrimitiveExpressions();

            // Find all PrimitiveExpressions except the keyword 'null'
            IEnumerable<PrimitiveExpression> primitives = rights_primitives.Where(x => x.ValueType != null);

            // find the position of each primitive
            var prims_with_position = from p in primitives
                                      select new {p.Value, p.ValueType, Index = rights_primitives.IndexOf(p)};

            // Group them together by literal value.  The groups then are candidates for replacement by a single param.
            var prim_groups = from p in prims_with_position
                              group p by new {p.Value, p.ValueType}
                              into g select new PrimExpSet {Value = g.Key.Value, ValueType = g.Key.ValueType, Positions = g.Select(x => x.Index)};

            // The powerset of the primitive positions is all the possible ways a single primitive value can be converted to a param.
            var all_param_possibles = from pes in prim_groups
                                      let expanded = from positions in Sets<int>.PowerSet(pes.Positions.ToArray())
                                                     select new PrimExpSet {Value = pes.Value, ValueType = pes.ValueType, Positions = positions}
                                      select expanded;

            foreach (var e1 in Sets<PrimExpSet>.CartesianProduct(all_param_possibles, count))
            {
                // If count is neg, let anything through.
                if (count < 0 || e1.Count() == count)
                {
                    var md = MakePermutation(right, e1);
                    const string QUOTE = "\"";
                    var parameters = e1.Select(x => x.ValueType == typeof (string) ? QUOTE + x.Value + QUOTE : x.Value).ToList();
                    yield return new Holder {md = md, parameters = parameters};
                }
            }
        }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:34,代码来源:LiteralToParameterExpansion.cs

示例2: MakePermutation

        private MethodDeclaration MakePermutation(MethodDeclaration right, IEnumerable<PrimExpSet> prim_groups)
        {
            ResetNameCount();

            right = right.DeepCopy();
            var rights_primitives = right.AllPrimitiveExpressions();

            foreach (var prim_grp in prim_groups)
            {
                var param_name = NextName();

                var typeRef = new TypeReference(prim_grp.ValueType.FullName);
                right.Parameters.Add(new ParameterDeclarationExpression(typeRef, param_name));

                var replacer = new PrimitiveReplacer();
                foreach (var pos in prim_grp.Positions)
                {
                    replacer.AddReplacement(rights_primitives[pos], new IdentifierExpression(param_name));
                }
                right.AcceptVisitor(replacer, null);
            }

            return right;
        }
开发者ID:Adam-Fogle,项目名称:agentralphplugin,代码行数:24,代码来源:LiteralToParameterExpansion.cs


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