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


C# Node.AddChildren方法代码示例

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


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

示例1: ConstructExpressionInfoTree

        public static Node<TokenInfo> ConstructExpressionInfoTree(IPluginInvoker invoker, IEnumerable<IGlobalProvider> providers)
        {
            var root = new Node<TokenInfo>();

            root.AddChildren(invoker.ListAllPluginTypes().Select(type => type.ToTokenInfo()));
            root.AddChildren(invoker.ListAllGlobalEnumTypes().Select(type => type.ToTokenInfo()));
            root.AddChildren(providers.SelectMany(gp => gp.ListGlobals().Select(obj => obj.ToTokenInfo())));

            root.SortChildrenRecursive((a, b) => a.Identifier.Value.CompareTo(b.Identifier.Value));

            return root;
        }
开发者ID:RCkanki,项目名称:FreePIE,代码行数:12,代码来源:InfoTransformHelper.cs

示例2: BuilderVisitorShouldBuildEnum

        public void BuilderVisitorShouldBuildEnum()
        {
            #region Arrange Expected NodeTree Input

            var root = new RootNode();
            var enumnode = new Node(NodeType.Enum, "enum");
            var enumname = new Node(NodeType.Identifier, "EnumName");
            var field = new Node(NodeType.EnumField, "DEFAULT");
            var name = new Node(NodeType.Identifier, "DEFAULT");
            var value = new Node(NodeType.FieldNumber, "0");
            var field1 = new Node(NodeType.EnumField, "VALONE");
            var name1 = new Node(NodeType.Identifier, "VALONE");
            var value1 = new Node(NodeType.FieldNumber, "1");
            field.AddChildren(name, value);
            field1.AddChildren(name1, value1);
            enumnode.AddChildren(enumname, field, field1);
            root.AddChild(enumnode);

            #endregion Arrange Expected NodeTree Input

            var expected = new EnumDefinition("EnumName", null, new List<EnumField>
            {
                new EnumField("DEFAULT", 0, null),
                new EnumField("VALONE", 1, null)
            });

            var sut = new BuilderVisitor();
            root.Accept(sut);

            sut.FileDescriptor.Enumerations.First().Should().Be(expected);
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:31,代码来源:VisitorTests.cs

示例3: ShouldBuildInlineStatementWithTrailingComment

        public void ShouldBuildInlineStatementWithTrailingComment()
        {
            #region Arrange Inline Trailing Comment Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "syntax"),
                new Token(TokenType.Control, 0, 1, "="),
                new Token(TokenType.String, 0, 2, "\"proto3\""),
                new Token(TokenType.Control, 0, 3, ";"),
                new Token(TokenType.Comment, 0, 4, "\\\\"),
                new Token(TokenType.String, 0, 5, "This"),
                new Token(TokenType.String, 0, 6, "is"),
                new Token(TokenType.String, 0, 7, "a"),
                new Token(TokenType.String, 0, 8, "comment."),
                new Token(TokenType.EndLine, 0, 9, Environment.NewLine)
            };

            #endregion Arrange Inline Trailing Comment Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var syntax = new Node(NodeType.Syntax, "syntax");
            var proto3 = new Node(NodeType.StringLiteral, "proto3");
            var comment = new Node(NodeType.Comment, "\\\\");
            var commentText = new Node(NodeType.CommentText, "This is a comment.");
            comment.AddChild(commentText);
            syntax.AddChildren(proto3, comment);
            root.AddChild(syntax);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root, null);
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:35,代码来源:SyntaxTreeTests.cs

示例4: BuildTree

 private static void BuildTree(Node<int> root, int M)
 {
     if (root.Value + 1 <= M)
     {
         Node<int> first = new Node<int>(root.Value + 1);
         root.AddChildren(first);
         BuildTree(first, M);
     }
     if (root.Value + 2 <= M)
     {
         Node<int> second = new Node<int>(root.Value + 2);
         root.AddChildren(second);
         BuildTree(second, M);
     }
     if (root.Value * 2 <= M)
     {
         Node<int> third = new Node<int>(root.Value * 2);
         root.AddChildren(third);
         BuildTree(third, M);
     }
 }
开发者ID:rosteslav,项目名称:telerik,代码行数:21,代码来源:Program.cs

示例5: BuilderVisitorShouldBuildImport

        public void BuilderVisitorShouldBuildImport()
        {
            #region Arrange Package Node Input

            var root = new RootNode();
            var import = new Node(NodeType.Import, "import");
            var type = new Node(NodeType.ImportModifier, "public");
            var otherMessage = new Node(NodeType.StringLiteral, "other.message");
            import.AddChildren(type, otherMessage);
            root.AddChild(import);

            #endregion Arrange Package Node Input

            var expected = new Import("public", "other.message");
            var sut = new BuilderVisitor();
            root.Accept(sut);

            sut.FileDescriptor.Imports.First().Should().Be(expected);
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:19,代码来源:VisitorTests.cs

示例6: ParseOneOfField

        private Node ParseOneOfField()
        {
            var oneOfTag = _tokens.Peek();
            if (!oneOfTag.Lexeme.Equals("oneof")) return null;
            _tokens.Dequeue();

            var msgNode = new Node(NodeType.OneOfField, oneOfTag.Lexeme);

            var msgName = ParseIdentifier();
            if (ReferenceEquals(msgName, null))
            {
                _errors.Add(
                    new ParseError(
                        $"Could not find a oneof name on line {oneOfTag.Line} for message token ",
                        oneOfTag));
                return null;
            }

            var openBrack = _tokens.Dequeue();
            if (!openBrack.Type.Equals(TokenType.Control) || !openBrack.Lexeme[0].Equals('{'))
            {
                _errors.Add(
                    new ParseError(
                        $"Expected to find open bracket on line {oneOfTag.Line} for message token ",
                        oneOfTag));
                return null;
            }

            msgNode.AddChild(msgName);

            ScoopComment(msgNode);
            DumpEndline();

            var next = _tokens.Peek();
            while (!next.Type.Equals(TokenType.Control) && !next.Lexeme[0].Equals('}'))
            {
                // Some of these may be null returns. That's ok. AddChildren will ignore.
                var fieldNode = ParseMessageField();
                var oneOf = ParseOneOfField();

                msgNode.AddChildren(fieldNode, oneOf);

                if (_tokens.Any()) next = _tokens.Peek();
            }

            _tokens.Dequeue(); // Dump the }
            DumpEndline();

            return msgNode;
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:50,代码来源:SyntaxAnalyzer.cs

示例7: ParseMessage

        private Node ParseMessage()
        {
            if (!_tokens.Any()) return null;
            var msgTag = _tokens.Peek();
            if (!msgTag.Lexeme.Equals("message")) return null;
            _tokens.Dequeue();

            var msgNode = new Node(NodeType.Message, msgTag.Lexeme);

            var msgName = ParseIdentifier();
            if (ReferenceEquals(msgName, null))
            {
                _errors.Add(
                    new ParseError(
                        $"Could not find a message name on line {msgTag.Line} for message token ",
                        msgTag));
                return null;
            }

            msgNode.AddChild(msgName);

            var openBrack = _tokens.Dequeue();
            if (!openBrack.Type.Equals(TokenType.Control) || !openBrack.Lexeme[0].Equals('{'))
            {
                _errors.Add(
                    new ParseError(
                        $"Expected to find open bracket on line {msgTag.Line} for message token ",
                        msgTag));
                return null;
            }

            ScoopComment(msgNode);
            DumpEndline();

            var next = _tokens.Peek();
            while (!next.Type.Equals(TokenType.Control) && !next.Lexeme[0].Equals('}'))
            {
                // Some of these may be null returns. That's ok. AddChildren will ignore.
                var reservation = ParseReservation();
                var fieldNode = ParseMessageField();
                var nestedMessage = ParseMessage();
                var nestedEnum = ParseEnum();
                var oneOf = ParseOneOfField();
                var map = ParseMapField();

                msgNode.AddChildren(reservation, fieldNode, nestedMessage, nestedEnum, oneOf, map);

                if (_tokens.Any()) next = _tokens.Peek();
            }

            _tokens.Dequeue(); // Dump the }
            DumpEndline();

            return msgNode;
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:55,代码来源:SyntaxAnalyzer.cs

示例8: ParseMapField

        private Node ParseMapField()
        {
            var mapTag = _tokens.Peek();
            if (!mapTag.Lexeme.Equals("map")) return null;
            _tokens.Dequeue();

            var mapNode = new Node(NodeType.Map, mapTag.Lexeme);

            var openAngle = _tokens.Dequeue();
            if (!"<".Equals(openAngle.Lexeme))
            {
                _errors.Add(
                   new ParseError(
                       $"Expected open angle bracket at column {openAngle.Column} on line {openAngle.Line} for map definition ",
                       mapTag));
                return null;
            }

            var key = _tokens.Dequeue();
            if (!key.Lexeme.IsMapKeyType())
            {
                _errors.Add(
                   new ParseError(
                       $"Expected valid map key type at column {key.Column} on line {key.Line} for map definition. Found {key.Lexeme} ",
                       mapTag));
                return null;
            }
            var mapKey = new Node(NodeType.MapKey, key.Lexeme);

            var comma = _tokens.Dequeue();
            if (!",".Equals(comma.Lexeme))
            {
                _errors.Add(
                   new ParseError(
                       $"Expected open comma at column {comma.Column} on line {comma.Line} for map definition ",
                       mapTag));
                return null;
            }

            var value = ParseMapValueType();

            if (ReferenceEquals(null, value))
            {
                _errors.Add(
                    new ParseError(
                        "Expected a user or value type for map definition ",
                        mapTag));
                return null;
            }

            var closeAngle = _tokens.Dequeue();
            if (!">".Equals(closeAngle.Lexeme))
            {
                _errors.Add(
                   new ParseError(
                       $"Expected close angle bracket at column {closeAngle.Column} on line {closeAngle.Line} for map definition ",
                       mapTag));
                return null;
            }

            var msgName = ParseIdentifier();
            if (ReferenceEquals(msgName, null))
            {
                _errors.Add(
                    new ParseError(
                        $"Could not find a oneof name on line {mapTag.Line} for message token ",
                        mapTag));
                return null;
            }

            var assignment = _tokens.Dequeue();
            if (!_parser.IsAssignment(assignment.Lexeme))
            {
                _errors.Add(new ParseError($"Expected an assignment after field name token on line {mapTag.Line}, found ", assignment));
                return null;
            }

            var fieldValue = _tokens.Dequeue();
            if (!_parser.IsIntegerLiteral(fieldValue.Lexeme))
            {
                _errors.Add(new ParseError($"Expected a field value after assignment token on line {mapTag.Line}, found ", fieldValue));
                return null;
            }
            var fieldNumber = new Node(NodeType.FieldNumber, fieldValue.Lexeme);

            mapNode.AddChildren(msgName, mapKey, value, fieldNumber);

            TerminateSingleLineStatement();
            ScoopComment(mapNode);
            DumpEndline();

            return mapNode;
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:93,代码来源:SyntaxAnalyzer.cs

示例9: AddProperties

 private static void AddProperties(Node<TokenInfo> propDelim, List<MemberInfo> members)
 {
     propDelim.AddChildren(members.Where(m => m.MemberType == MemberTypes.Property).Select(m => MapProperty(m as PropertyInfo)));
 }
开发者ID:RCkanki,项目名称:FreePIE,代码行数:4,代码来源:InfoTransformHelper.cs

示例10: AddMethods

 private static void AddMethods(Node<TokenInfo> methodDelim, IEnumerable<MemberInfo> members)
 {
     methodDelim.AddChildren(members.Where(m => m.MemberType == MemberTypes.Method && !(m as MethodInfo).IsSpecialName).Select(m => MapMethod(m as MethodInfo)));
 }
开发者ID:RCkanki,项目名称:FreePIE,代码行数:4,代码来源:InfoTransformHelper.cs

示例11: AddEvents

 private static void AddEvents(Node<TokenInfo> eventDelim, IEnumerable<MemberInfo> members)
 {
     eventDelim.AddChildren(members.Where(m => m.MemberType == MemberTypes.Event).Select(m => MapEvent(m as EventInfo)));
 }
开发者ID:RCkanki,项目名称:FreePIE,代码行数:4,代码来源:InfoTransformHelper.cs

示例12: ShouldBurnEmptyNewlines

        public void ShouldBurnEmptyNewlines()
        {
            #region Arrange Package Declaration Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "package"),
                new Token(TokenType.String, 0, 1, "foo.bar.baz"),
                new Token(TokenType.Control, 0, 2, ";"),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine),
                new Token(TokenType.Id, 0, 0, "option"),
                new Token(TokenType.String, 0, 1, "java_package"),
                new Token(TokenType.Control, 0, 2, "="),
                new Token(TokenType.String, 0, 3, "\"com.example.foo\""),
                new Token(TokenType.Control, 0, 4, ";"),
                new Token(TokenType.EndLine, 0, 4, Environment.NewLine)
            };

            #endregion Arrange Package Declaration Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var package = new Node(NodeType.Package, "package");
            var packageName = new Node(NodeType.Identifier, "foo.bar.baz");
            package.AddChild(packageName);
            root.AddChild(package);
            var option = new Node(NodeType.Option, "option");
            var optionName = new Node(NodeType.Identifier, "java_package");
            var optionValue = new Node(NodeType.StringLiteral, "com.example.foo");
            option.AddChildren(optionName, optionValue);
            root.AddChild(option);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
开发者ID:draylundy,项目名称:ProtobufGenerator,代码行数:39,代码来源:SyntaxTreeTests.cs

示例13: BuilderVisitorShouldBuildMessage

        public void BuilderVisitorShouldBuildMessage()
        {
            #region Arrange Expected NodeTree Input

            var root = new RootNode();
            //  Define base Message with One Field
            var message = new Node(NodeType.Message, "message");
            var msgName = new Node(NodeType.Identifier, "Outer");

            #region Outer Message Field nodes

            var field = new Node(NodeType.Field, "int32");
            var type = new Node(NodeType.Type, "int32");
            var name = new Node(NodeType.Identifier, "field_name");
            var value = new Node(NodeType.FieldNumber, "2");
            field.AddChildren(type, name, value);

            #endregion Outer Message Field nodes

            #region Nested Message nodes

            var nestedMsg = new Node(NodeType.Message, "message");
            var nestedName = new Node(NodeType.Identifier, "Inner");

            var innerField = new Node(NodeType.Field, "fixed64");
            var innerType = new Node(NodeType.Type, "fixed64");
            var innerName = new Node(NodeType.Identifier, "field_name2");
            var innerValue = new Node(NodeType.FieldNumber, "0");
            innerField.AddChildren(innerType, innerName, innerValue);

            #endregion Nested Message nodes

            #region Nested Enumeration nodes

            var enumnode = new Node(NodeType.Enum, "enum");
            var enumname = new Node(NodeType.Identifier, "EnumName");
            var enumfield0 = new Node(NodeType.EnumField, "DEFAULT");
            var enumfieldname0 = new Node(NodeType.Identifier, "DEFAULT");
            var enumfieldvalue0 = new Node(NodeType.FieldNumber, "0");
            var enumfield1 = new Node(NodeType.EnumField, "VALONE");
            var enumfieldname1 = new Node(NodeType.Identifier, "VALONE");
            var enumfieldvalue1 = new Node(NodeType.FieldNumber, "1");
            enumnode.AddChildren(enumname, enumfield0, enumfield1);
            enumfield0.AddChildren(enumfieldname0, enumfieldvalue0);
            enumfield1.AddChildren(enumfieldname1, enumfieldvalue1);

            #endregion Nested Enumeration nodes

            nestedMsg.AddChildren(nestedName, innerField);
            message.AddChildren(msgName, field, enumnode, nestedMsg);
            root.AddChild(message);

            #endregion Arrange Expected NodeTree Input

            #region Arrange Expected Output

            var expFields = new List<Field>
            {
                new Field("int32", "field_name", 2, null, false)
            };
            var inFields = new List<Field>
            {
                new Field("fixed64", "field_name2", 0, null, false)
            };
            var enumDefs = new List<EnumDefinition>
            {
                new EnumDefinition("EnumName", null, new List<EnumField>
                {
                    new EnumField("DEFAULT", 0, null),
                    new EnumField("VALONE", 1, null)
                })
            };
            var msgDefs = new List<MessageDefinition>
            {
                new MessageDefinition("Inner", inFields, null, null, null, null, null)
            };
            var expected = new MessageDefinition("Outer", expFields, null, null, null, enumDefs, msgDefs);

            #endregion Arrange Expected Output

            var sut = new BuilderVisitor();
            root.Accept(sut);

            sut.FileDescriptor.Messages.First().Should().Be(expected);
        }
开发者ID:mholo65,项目名称:ProtobufGenerator,代码行数:85,代码来源:VisitorTests.cs

示例14: ShouldBuildMapFieldNode

        public void ShouldBuildMapFieldNode()
        {
            #region Arrange Map Field Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "message"),
                new Token(TokenType.String, 0, 0, "Outer"),
                new Token(TokenType.Control, 0, 0, "{"),
                new Token(TokenType.EndLine, 0, 0, Environment.NewLine),
                new Token(TokenType.Id, 0, 0, "map"),
                new Token(TokenType.Control, 0, 0, "<"),
                new Token(TokenType.String, 0, 0, "string"),
                new Token(TokenType.Control, 0, 0, ","),
                new Token(TokenType.String, 0, 0, "Project"),
                new Token(TokenType.Control, 0, 0, ">"),
                new Token(TokenType.String, 0, 0, "projects"),
                new Token(TokenType.Control, 0, 0, "="),
                new Token(TokenType.Numeric, 0, 0, "3"),
                new Token(TokenType.Control, 0, 4, ";"),
                new Token(TokenType.EndLine, 0, 0, Environment.NewLine),
                new Token(TokenType.Control, 0, 0, "}")
            };

            #endregion Arrange Map Field Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var message = new Node(NodeType.Message, "message");
            var msgName = new Node(NodeType.Identifier, "Outer");
            var field = new Node(NodeType.Map, "map");
            var key = new Node(NodeType.MapKey, "string");
            var value = new Node(NodeType.MapValue, "Project");
            var mapName = new Node(NodeType.Identifier, "projects");
            var mapValue = new Node(NodeType.FieldNumber, "3");

            field.AddChildren(mapName, key, value, mapValue);
            message.AddChildren(msgName, field);
            root.AddChild(message);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
开发者ID:draylundy,项目名称:ProtobufGenerator,代码行数:45,代码来源:SyntaxTreeTests.cs

示例15: ShouldBuildRepeatedFieldNode

        public void ShouldBuildRepeatedFieldNode()
        {
            #region Arrange Repeated Field Token Input

            var tokenList = new List<Token>
            {
                new Token(TokenType.Id, 0, 0, "message"),
                new Token(TokenType.String, 0, 1, "Outer"),
                new Token(TokenType.Control, 0, 2, "{"),
                new Token(TokenType.EndLine, 0, 5, Environment.NewLine),
                new Token(TokenType.String, 0, 0 ,"repeated"),
                new Token(TokenType.String, 0, 0, "int32"),
                new Token(TokenType.String, 0, 1, "field_name"),
                new Token(TokenType.Control, 0, 2, "="),
                new Token(TokenType.Numeric, 0, 3, "2"),
                new Token(TokenType.Control, 0, 4, ";"),
                new Token(TokenType.EndLine, 0, 5, Environment.NewLine),
                new Token(TokenType.Control, 0, 4, "}")
            };

            #endregion Arrange Repeated Field Token Input

            #region Arrange Expected NodeTree Output

            var root = new RootNode();
            var message = new Node(NodeType.Message, "message");
            var msgName = new Node(NodeType.Identifier, "Outer");
            var field = new Node(NodeType.Field, "repeated");
            var repeated = new Node(NodeType.Repeated, "repeated");
            var type = new Node(NodeType.Type, "int32");
            var name = new Node(NodeType.Identifier, "field_name");
            var value = new Node(NodeType.FieldNumber, "2");
            field.AddChildren(repeated, type, name, value);
            message.AddChildren(msgName, field);
            root.AddChild(message);

            #endregion Arrange Expected NodeTree Output

            AssertSyntax(tokenList, root);
        }
开发者ID:draylundy,项目名称:ProtobufGenerator,代码行数:40,代码来源:SyntaxTreeTests.cs


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