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


C# Context.Push方法代码示例

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


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

示例1: Match

        public override bool Match(Context context)
        {
            // To assert a token is to save the state of the context
            // and restore it afterwards. However, the behavior is
            // different for the stack and for capture groups.
            // If a token in an assertion saves state information
            // it will be removed after matching. If it captures
            // this will remain unless this assertion needs to backtrack.

            int startingOffset = context.offset;
            int stackSize = context.stackSize;
            int currentKey = context.Key;

            // Try to match the token
            bool result = matchItem.Match(context);

            // Negative assertions return the oposite of the actual token result
            if (!positive)
                result = !result;

            // Reset the offset and remove any
            // backtracking info for the token
            context.offset = startingOffset;
            context.RestoreStack(stackSize);

            // If we've succeeded save off the largest capture key
            // so we can restore it if we need to during a MatchNext.
            // If not then remove anything captured during the assertion.
            if (result)
                context.Push(currentKey);
            else
                context.RestoreCaptures(currentKey);

            return result;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:35,代码来源:Lookaround.cs

示例2: Match

        public override bool Match(Context context)
        {
            // If we can't match the minimum number of times we've failed
            if (!base.Match(context))
                return false;

            // Matching lazily, so no more is fine.
            context.Push(0);
            return true;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:10,代码来源:Lazy.cs

示例3: MatchNext

        public override bool MatchNext(Context context)
        {
            var ci = context.Pop(groupId);

            bool result = matchItem.MatchNext(context);

            if (result)
                context.Push(ci.beg, context.offset, groupId);

            return result;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:11,代码来源:CaptureGroup.cs

示例4: Match

        public override bool Match(Context context)
        {
            int startingOffset = context.offset;

            bool result = matchItem.Match(context);

            // If we've matched then Push a new capture info to store this offset
            if (result)
                context.Push(startingOffset, context.offset, groupId);

            return result;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:12,代码来源:CaptureGroup.cs

示例5: Execute

        public void Execute(Demo3Input input)
        {
            using (var context = new Context())
            using (var consumer = context.Pull())
            using (var reporter = context.Push())
            {
                consumer.Connect("tcp://localhost:5557");
                reporter.Connect("tcp://localhost:5558");

                DoWork(consumer, reporter, input.WorkerNumberFlag);
            }
        }
开发者ID:brechtvm,项目名称:presentations-zeromq,代码行数:12,代码来源:Worker.cs

示例6: MatchNext

        public override bool MatchNext(Context context)
        {
            // Pop off how many matches we've actually made.
            int count = context.Pop();

            // If we have not reached the maximum iterations and
            // can match again, that's what we'll do.
            if (count < max && matchItem.Match(context))
            {
                // Save state and succeed
                context.Push(++count);
                return true;
            }

            // Current iteration of the token failed, try alternatives
            // backwards through the previously matched iterations
            while (count > 0)
            {
                // If we find an alternative match then save state and exit
                if (matchItem.MatchNext(context))
                {
                    context.Push(count);
                    return true;
                }

                // Alternative failed, go back to a previous iteration
                count--;
            }

            // At this point count == 0 so we have no other options
            // We have to try backtracking into the base behavior.
            // If that fails we're out of options.
            if (!base.MatchNext(context))
                return false;

            // We've successfully matched at the base level.
            // Behave lazily by saving this state and succeeding
            context.Push(0);
            return true;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:40,代码来源:Lazy.cs

示例7: Match

        public override bool Match(Context context)
        {
            // Get context state information
            int stackSize = context.stackSize;
            int key = context.Key;
            int offset = context.offset;

            // Try to match the token
            bool result = matchItem.Match(context);

            // Atomic matches throw away all backtracking information
            context.RestoreStack(stackSize);

            if (result)
            {
                // If we matched we need to store the capture key
                // and the starting offset to restor to if MatchNext
                // is called.
                context.Push(offset);
                context.Push(key);
            }

            return result;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:24,代码来源:Atomic.cs

示例8: Match

        public bool Match(Context context)
        {
            if (!context.GroupHasValue(groupId))
                return false;

            int offset = context.offset;
            string str = context.GroupValue(groupId);
            int len = str.Length;

            if (offset + len > context.Length)
                return false;

            for (int i = 0; i < len; i++)
                if (context.matchString[offset + i] != str[i])
                    return false;

            // Advance the offset to cover the matched string
            context.offset += len;

            // Save the original offset to restore in a MatchNext
            context.Push(offset);
            return true;
        }
开发者ID:TheFellow,项目名称:RegexLib,代码行数:23,代码来源:Backreference.cs

示例9: Execute

        public void Execute(Demo3Input input)
        {
            using (var context = new Context())
            using (var sender = context.Push())
            {
                sender.Bind("tcp://*:5557");

                Console.Write("Press enter when the workers are ready: ");
                Console.ReadKey();
                Console.WriteLine();
                Console.WriteLine("Sending tasks to workers...");

                // Signal the start of the batch
                sender.Send(BitConverter.GetBytes(0));

                var random = new Random();
                for (int i = 0; i < 300; i++)
                {
                    int sleepTime = random.Next(1, 100);
                    var message = BitConverter.GetBytes(sleepTime);
                    sender.Send(message);
                }
            }
        }
开发者ID:brechtvm,项目名称:presentations-zeromq,代码行数:24,代码来源:Ventilator.cs

示例10: RenderSection

            string RenderSection(Token token, Context context, object partials, string originalTemplate)
            {
                var buffer = "";
                var value = context.Lookup(token.Value);

                // This function is used to Render an arbitrary template
                // in the current context by higher-order sections.
                Func<string, string> subRender = template => Render(template, context, partials);

                if (value == null || value is bool && !(bool) value)
                    return ""; // this would have returned null/undefined instead of a string in JS version?

                //if (IsArray(Value)) {
                // TODO: HORRIBLE HACK to differentiate Jobject and iterables.
                if ((value.GetType().ToString().Contains("Jobject")))
                {
                    buffer += RenderTokens(token.SubTokens, context.Push(value), partials, originalTemplate);
                }
                else if (IsArray(value))
                {
                    foreach (var item in (IList) value)
                    {
                        buffer += RenderTokens(token.SubTokens, context.Push(item), partials, originalTemplate);
                    }
                    //} else if (typeof Value === 'object' || typeof Value === 'string' || typeof Value === 'number') {
                    //    buffer += this.RenderTokens(token[4], context.Push(Value), partials, originalTemplate);
                }
                else if (value is Func<string, Func<string, string>, string>)
                {
                    var lambda =
                        value as Func<string, Func<string, string>, string>;
                    //Value = lambda(context._view, originalTemplate.Substring(token.End, token.EndSection), subRender);
                    // TODO: how do we set the "this" in c#? Do we care?
                    value = lambda(originalTemplate.Substring(token.End, token.EndSection - token.End), subRender);

                    if (value != null)
                        buffer += value;

                    //} else if (Value as dynamic != null) {
                    //    buffer += this.RenderTokens(token.SubTokens, context.Push(Value), partials, originalTemplate);
                }
                else
                {
                    buffer += RenderTokens(token.SubTokens, context, partials, originalTemplate);
                }
                return buffer;
            }
开发者ID:vahpetr,项目名称:MustacheCs2,代码行数:47,代码来源:Mustache.cs

示例11: _intOnGetIndex

 public virtual int _intOnGetIndex( Context ctx, bool isprop )
 {
     Variable v = OnGetIndex( ctx, ctx.StackItem( 0 ), isprop );
     if( v != null )
     {
         ctx.Push( v );
         return RC.SUCCESS;
     }
     return RC.ENOTFND;
 }
开发者ID:snake5,项目名称:sgscript,代码行数:10,代码来源:Variable.cs

示例12: _intOnExpr

 public virtual int _intOnExpr( Context ctx, ExprOp op )
 {
     Variable rv = null;
     switch( op )
     {
         case ExprOp.Add: rv = OnAdd( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Sub: rv = OnSub( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Mul: rv = OnMul( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Div: rv = OnDiv( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Mod: rv = OnMod( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Compare: rv = OnCompare( ctx.StackItem( 0 ), ctx.StackItem( 1 ) ); break;
         case ExprOp.Negate: rv = OnNegate(); break;
     }
     if( rv != null )
     {
         ctx.Push( rv );
         return RC.SUCCESS;
     }
     return RC.ENOTSUP;
 }
开发者ID:snake5,项目名称:sgscript,代码行数:20,代码来源:Variable.cs

示例13: _intOnDump

 public virtual int _intOnDump( Context ctx, int maxdepth )
 {
     string dump = OnDump( ctx, maxdepth );
     if( dump != null )
     {
         ctx.Push( dump );
         return RC.SUCCESS;
     }
     return RC.ENOTSUP;
 }
开发者ID:snake5,项目名称:sgscript,代码行数:10,代码来源:Variable.cs

示例14: _intOnConvert

 public virtual int _intOnConvert( Context ctx, ConvOp type )
 {
     switch( type )
     {
         case ConvOp.ToBool: ctx.Push( ConvertToBool() ); return RC.SUCCESS;
         case ConvOp.ToString: ctx.Push( ConvertToString() ); return RC.SUCCESS;
         case ConvOp.Clone: Variable clone = OnClone( ctx ); if( clone != null ) ctx.Push( clone ); return clone != null ? RC.SUCCESS : RC.ENOTSUP;
         case ConvOp.ToIter: Variable iter = OnGetIterator( ctx ); if( iter != null ) ctx.Push( iter ); return iter != null ? RC.SUCCESS : RC.ENOTSUP;
     }
     return RC.ENOTSUP;
 }
开发者ID:snake5,项目名称:sgscript,代码行数:11,代码来源:Variable.cs

示例15: CreateStaticDict

        public static Variable CreateStaticDict( Context ctx, Type type )
        {
            int items = 0;

            MethodInfo[] methods = type.GetMethods( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly );
            foreach( MethodInfo mi in methods )
            {
                if( mi.GetCustomAttributes( typeof(HideMethod), true ).Length != 0 )
                    continue;

                DNMethod dnm = new DNMethod( ctx, mi );

                ctx.Push( mi.Name );
                ctx.Push( dnm );
                items += 2;
            }

            return ctx.DictVar( items );
        }
开发者ID:snake5,项目名称:sgscript,代码行数:19,代码来源:Variable.cs


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