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


C# Env.CreateChildEnv方法代码示例

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


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

示例1: Evaluate

        public Ruleset Evaluate(List<NamedArgument> args, Env env, List<Ruleset> closureContext)
        {
            var frame = EvaluateParams(env, args);

            var frames = new[] { this, frame }.Concat(env.Frames).Concat(closureContext).Reverse();
            var context = env.CreateChildEnv(new Stack<Ruleset>(frames));

            var newRules = new NodeList();

            foreach (var rule in Rules)
            {
                if (rule is MixinDefinition)
                {
                    var mixin = rule as MixinDefinition;
                    var parameters = Enumerable.Concat(mixin.Params, frame.Rules.Cast<Rule>());
                    newRules.Add(new MixinDefinition(mixin.Name, new NodeList<Rule>(parameters), mixin.Rules, mixin.Condition));
                }
                else if (rule is Directive)
                {
                    newRules.Add(rule);
                }
                else if (rule is Ruleset)
                {
                    var ruleset = (rule as Ruleset);

                    context.Frames.Push(ruleset);

                    var rules = new NodeList(NodeHelper.NonDestructiveExpandNodes<MixinCall>(context, ruleset.Rules)
                        .Select(r => r.Evaluate(context)));

                    context.Frames.Pop();

                    newRules.Add(new Ruleset(ruleset.Selectors, rules));
                }
                else if (rule is MixinCall)
                {
                    newRules.AddRange((NodeList)rule.Evaluate(context));
                }
                else
                {
                    newRules.Add(rule.Evaluate(context));
                }
            }

            return new Ruleset(null, newRules);
        }
开发者ID:emiaj,项目名称:dotless,代码行数:46,代码来源:MixinDefinition.cs

示例2: Evaluate

        public Ruleset Evaluate(List<NamedArgument> args, Env env, List<Ruleset> closureContext)
        {
            var frame = EvaluateParams(env, args);

            var frames = new[] { this, frame }.Concat(env.Frames).Concat(closureContext).Reverse();
            var context = env.CreateChildEnv(new Stack<Ruleset>(frames));

            var newRules = new NodeList();

            foreach (var rule in Rules)
            {
                if (rule is MixinDefinition)
                {
                    var mixin = rule as MixinDefinition;
                    var parameters = Enumerable.Concat(mixin.Params, frame.Rules.Cast<Rule>());
                    newRules.Add(new MixinDefinition(mixin.Name, new NodeList<Rule>(parameters), mixin.Rules, mixin.Condition, mixin.Variadic));
                }
                else if (rule is Import)
                {
                    var potentiolNodeList = rule.Evaluate(context);
                    var nodeList = potentiolNodeList as NodeList;
                    if (nodeList != null)
                    {
                        newRules.AddRange(nodeList);
                    }
                    else
                    {
                        newRules.Add(potentiolNodeList);
                    }
                }
                else if (rule is Directive || rule is Media)
                {
                    newRules.Add(rule.Evaluate(context));
                }
                else if (rule is Ruleset)
                {
                    var ruleset = (rule as Ruleset);

                    context.Frames.Push(ruleset);

                    newRules.Add(ruleset.Evaluate(context));

                    context.Frames.Pop();
                }
                else if (rule is MixinCall)
                {
                    newRules.AddRange((NodeList)rule.Evaluate(context));
                }
                else
                {
                    newRules.Add(rule.Evaluate(context));
                }
            }

            return new Ruleset(null, newRules);
        }
开发者ID:helephant,项目名称:dotless,代码行数:56,代码来源:MixinDefinition.cs

示例3: Evaluate

        public Ruleset Evaluate(List<NamedArgument> args, Env env)
        {
            var frame = EvaluateParams(env, args);

            var context = env.CreateChildEnv();
            context.Frames.Push(this);
            context.Frames.Push(frame);

            var result = EvaluateRulesForFrame(frame, context);

            context.Frames.Pop();
            context.Frames.Pop();

            return result;
        }
开发者ID:Ralphvanderneut,项目名称:dotless,代码行数:15,代码来源:MixinDefinition.cs

示例4: Evaluate

        public Ruleset Evaluate(List<NamedArgument> args, Env env, List<Ruleset> closureContext)
        {
            //            if (args != null && args.Any())
            //                Guard.ExpectMaxArguments(Params.Count, args.Count, String.Format("'{0}'", Name), Index);

            var arguments = new Dictionary<string, Node>();
            args = args ?? new List<NamedArgument>();

            var hasNamedArgs = false;
            foreach (var arg in args)
            {
                if (!string.IsNullOrEmpty(arg.Name))
                {
                    hasNamedArgs = true;

                    arguments[arg.Name] = new Rule(arg.Name, arg.Value.Evaluate(env)) { Index = arg.Value.Index };
                }
                else if (hasNamedArgs)
                    throw new ParsingException("Positional arguments must appear before all named arguments.", arg.Value.Index);
            }

            for (var i = 0; i < Params.Count; i++)
            {
                if (String.IsNullOrEmpty(Params[i].Name))
                    continue;

                if (arguments.ContainsKey(Params[i].Name))
                    continue;

                Node val;
                if (i < args.Count && string.IsNullOrEmpty(args[i].Name))
                    val = args[i].Value;
                else
                    val = Params[i].Value;

                if (val)
                    arguments[Params[i].Name] = new Rule(Params[i].Name, val.Evaluate(env)) {Index = val.Index};
                else
                    throw new ParsingException(
                        String.Format("wrong number of arguments for {0} ({1} for {2})", Name,
                                      args != null ? args.Count : 0, _arity), Index);
            }

            var _arguments = new List<Node>();

            for(var i = 0; i < Math.Max(Params.Count, args.Count); i++)
            {
              _arguments.Add(i < args.Count ? args[i].Value : Params[i].Value);
            }

            var frame = new Ruleset(null, new NodeList());

            frame.Rules.Insert(0, new Rule("@arguments", new Expression(_arguments.Where(a => a != null)).Evaluate(env)));

            foreach (var arg in arguments)
            {
                frame.Rules.Add(arg.Value);
            }

            var frames = new[] { this, frame }.Concat(env.Frames).Concat(closureContext).Reverse();
            var context = env.CreateChildEnv(new Stack<Ruleset>(frames));

            var newRules = new NodeList();

            foreach (var rule in Rules)
            {
                if (rule is MixinDefinition)
                {
                    var mixin = rule as MixinDefinition;
                    var parameters = Enumerable.Concat(mixin.Params, frame.Rules.Cast<Rule>());
                    newRules.Add(new MixinDefinition(mixin.Name, new NodeList<Rule>(parameters), mixin.Rules));
                }
                else if (rule is Directive)
                {
                    newRules.Add(rule);
                }
                else if (rule is Ruleset)
                {
                    var ruleset = (rule as Ruleset);

                    context.Frames.Push(ruleset);

                    var rules = new NodeList(NodeHelper.NonDestructiveExpandNodes<MixinCall>(context, ruleset.Rules)
                        .Select(r => r.Evaluate(context)));

                    context.Frames.Pop();

                    newRules.Add(new Ruleset(ruleset.Selectors, rules));
                }
                else if (rule is MixinCall)
                {
                    newRules.AddRange((NodeList)rule.Evaluate(context));
                }
                else
                {
                    newRules.Add(rule.Evaluate(context));
                }
            }

            return new Ruleset(null, newRules);
//.........这里部分代码省略.........
开发者ID:nlerikheemskerk,项目名称:cassette,代码行数:101,代码来源:MixinDefinition.cs


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