コード例 #1
0
ファイル: RouteNode.cs プロジェクト: waqasahmed0323/jasper
        public virtual void WriteSelectCode(ISourceWriter writer)
        {
            foreach (var route in ComplexArgRoutes)
            {
                writer.WriteComment("Look for odd shaped routes with complex parameter structures");
                writer.Write($"if (Matches{route.VariableName}(segments)) return {route.VariableName};");
            }


            if (_children.Any())
            {
                writer.Write($"BLOCK:if (segments.Length > {LeafDepth})");
                foreach (var node in _children)
                {
                    writer.IfCurrentSegmentEquals(Depth, node.Segment, node.WriteSelectCode);
                }

                if (SpreadRoute != null)
                {
                    writer.Return(SpreadRoute);
                }

                writer.ReturnNull();

                writer.FinishBlock();
            }

            foreach (var leaf in Leaves.OrderBy(x => x.LastSegment))
            {
                writer.IfCurrentSegmentEquals(Depth, leaf.LastSegment, w => w.Return(leaf));
            }

            if (TryFindLeafArgRoute(out var leafArg))
            {
                writer.Return(leafArg);
            }

            if (SpreadRoute != null)
            {
                writer.Return(SpreadRoute);
            }

            writer.ReturnNull();
        }