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


C# XElement.FirstElement方法代码示例

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


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

示例1: CreateIterationStatement

        public static UnifiedExpression CreateIterationStatement(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "iteration_statement");
            /*
            iteration_statement
            : 'while' '(' expression ')' statement
            | 'do' statement 'while' '(' expression ')' ';'
            | 'for' '(' expression_statement expression_statement expression? ')' statement
             */

            var first = node.FirstElement().Value;
            var body =
                    UnifiedBlock.Create(
                            CreateStatement(node.FirstElement("statement")));
            switch (first) {
            case "while":
                return UnifiedWhile.Create(CreateExpression(node.NthElement(2)), body);
            case "do":
                return UnifiedDoWhile.Create(CreateExpression(node.NthElement(4)), body);
            case "for":
                var step = node.Element("expression");
                var stepExp = step != null ? CreateExpression(step) : null;
                return UnifiedFor.Create(
                        CreateExpressionStatement(node.NthElement(2)),
                        CreateExpressionStatement(node.NthElement(3)),
                        stepExp, body);
            default:
                throw new InvalidOperationException();
            }
        }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:31,代码来源:CProgramGeneratorHelper.Statement.cs

示例2: CreateAlias

 public static UnifiedExpression CreateAlias(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "alias");
     return UnifiedAlias.Create(
             CreateExpresion(node.FirstElement()),
             CreateExpresion(node.LastElement()));
 }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:8,代码来源:Ruby18ProgramGeneratorHelper.Expressions.cs

示例3: CreateLit

 public static UnifiedExpression CreateLit(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "lit");
     var child = node.FirstElement();
     switch (child.Name()) {
     case "Symbol":
         return UnifiedSymbolLiteral.Create(child.Value);
     }
     return CreateExpresion(child);
 }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:11,代码来源:Ruby18ProgramGeneratorHelper.Literals.cs

示例4: CreateAsgn

 public static UnifiedBinaryExpression CreateAsgn(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(
             node.Name() == "lasgn" || node.Name() == "masgn"
             || node.Name() == "iasgn"
             || node.Name() == "gasgn" || node.Name() == "cvdecl"
             || node.Name() == "cdecl");
     return UnifiedBinaryExpression.Create(
             CreateExpresion(node.FirstElement()),
             UnifiedBinaryOperator.Create(
                     "=", UnifiedBinaryOperatorKind.Assign),
             CreateExpresion(node.LastElement()));
 }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:14,代码来源:Ruby18ProgramGeneratorHelper.Expressions.cs

示例5: CreateExpressionStatement

        public static UnifiedExpression CreateExpressionStatement(
                XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "expression_statement");
            /*
            expression_statement
            : ';'
            | expression ';'
            */

            var first = node.FirstElement();
            return first.Name == "expression" ? CreateExpression(first) : null;
        }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:14,代码来源:CProgramGeneratorHelper.Statement.cs

示例6: CreateCompilationUnit

		public static UnifiedProgram CreateCompilationUnit(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "compilationUnit");
			/*
			 * compilationUnit 
			 * :   ( (annotations)? packageDeclaration )? (importDeclaration)* (typeDeclaration)*
			 */
			var program = UnifiedProgram.Create(UnifiedBlock.Create());
			var expressions = program.Body;

			var first = node.FirstElementOrDefault();
			if (first.SafeName() == "annotations") {
				var annotations = CreateAnnotations(node.FirstElement());
				var packageDeclaration =
						CreatePackageDeclaration(node.NthElement(1));
				packageDeclaration.Annotations = annotations;
				expressions.Add(packageDeclaration);
				expressions = packageDeclaration.Body;
			} else if (first.SafeName() == "packageDeclaration") {
				var packageDeclaration = CreatePackageDeclaration(first);
				expressions.Add(packageDeclaration);
				expressions = packageDeclaration.Body;
			}
			foreach (var e in node.Elements("importDeclaration")) {
				var importDeclaration = CreateImportDeclaration(e);
				expressions.Add(importDeclaration);
			}
			foreach (var e in node.Elements("typeDeclaration")) {
				var typeDeclaration = CreateTypeDeclaration(e);
				expressions.AddRange(typeDeclaration);
			}
			// Pick up comment nodes which are in last children of the root node
			program.Comments = node.Elements(Code2XmlConstants.CommentName)
					.Select(CreateComment)
					.ToSet();

			return program;
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:38,代码来源:JavaProgramGeneratorHelper.cs

示例7: CreateExternalDeclaration

        public static UnifiedExpression CreateExternalDeclaration(
				XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "external_declaration");
            /*
             * external_declaration
             * options {k=1;}
             * : ( declaration_specifiers? declarator declaration* '{' )=> function_definition
             * | declaration
             * ;
             */
            // 前者が関数宣言のこと、後者がtypedefのこと

            var first = node.FirstElement();
            if (first.Name() == "function_definition") {
                return CreateFunctionDefinition(first);
            }
            if (first.Name() == "declaration") {
                return CreateDeclaration(first);
            }
            throw new InvalidOperationException();
        }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:23,代码来源:CProgramGeneratorHelper.cs

示例8: CreateWhenAndDefault

        private static IEnumerable<UnifiedCase> CreateWhenAndDefault(
            XElement node)
        {
            Contract.Requires(node != null);
            if (node.Name() == "nil") {
                yield break;
            }

            if (node.Name() != "when") {
                yield return UnifiedCase.CreateDefault(CreateSmartBlock(node));
            } else {
                var first = node.FirstElement();
                var caseConds = first.Elements()
                        .Select(CreateExpresion)
                        .ToList();
                int i;
                for (i = 0; i < caseConds.Count - 1; i++) {
                    yield return UnifiedCase.Create(caseConds[i]);
                }
                yield return
                        UnifiedCase.Create(
                                caseConds[i],
                                CreateSmartBlock(node.LastElement()));
            }
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:25,代码来源:Ruby18ProgramGeneratorHelper.cs

示例9: CreateDot3

 private static UnifiedExpression CreateDot3(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "dot3");
     return UnifiedRange.Create(
             CreateExpresion(node.FirstElement()),
             CreateExpresion(node.LastElement()));
 }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:8,代码来源:Ruby18ProgramGeneratorHelper.Literals.cs

示例10: CreateIf

		private static UnifiedIf CreateIf(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "statement");
			Contract.Requires(node.FirstElement().Name() == "IF");
			/*  
			 * 'if' parExpression statement ('else' statement)? 
			 */
			var trueBody = CreateStatement(node.Element("statement"))
					.ToBlock();

			UnifiedBlock falseBody = null;
			if (node.Elements("statement").Count() == 2) {
				var falseNode = node.Elements("statement").ElementAt(1);
				falseBody = CreateStatement(falseNode).ToBlock();
			}
			return UnifiedIf.Create(
					CreateParExpression(node.Element("parExpression")), trueBody,
					falseBody);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:19,代码来源:JavaProgramGeneratorHelper.cs

示例11: CreateLasgnOrMasgnOrNil

 public static IEnumerable<UnifiedVariableIdentifier> CreateLasgnOrMasgnOrNil(
     XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(
             node.Name() == "lasgn" || node.Name() == "masgn"
             || node.Name() == "nil");
     Contract.Requires(
             node.Name() == "nil" || node.Elements().Count() == 1);
     Contract.Requires(
             node.Name() == "nil" || node.Name() != "masgn"
             || node.FirstElement().Name() == "array");
     return node.Descendants("Symbol")
             .Select(CreateSymbol);
 }
开发者ID:macc704,项目名称:UNICOEN,代码行数:15,代码来源:Ruby18ProgramGeneratorHelper.cs

示例12: CreateStructOrUnionSpecifier

        public static UnifiedType CreateStructOrUnionSpecifier(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "struct_or_union_specifier");
            /*	struct_or_union_specifier
             * : struct_or_union IDENTIFIER? '{' struct_declaration_list '}'
             * | struct_or_union IDENTIFIER
             */
            // 構造体の定義と宣言の両方をこのメソッドで作成
            // 常に UnifiedType を返すが、
            // 構造体定義をしている場合だけ関数の呼び出し元で UnifiedType の中身をとりだす

            // typedef "struct {}" data; -> クラス?
            // "struct data {}"; -> クラス
            // "struct data" a; -> 型

            var isStruct = CreateStructOrUnion(node.FirstElement()) == "struct";
            var identifier = node.Element("IDENTIFIER");
            var typeName = identifier == null
                                   ? null
                                   : UnifiedVariableIdentifier.Create(
                                           identifier.Value);

            // 型の場合
            if (node.Elements().Count() == 2) {
                var baseType = UnifiedType.Create(typeName);
                return isStruct ? baseType.WrapStruct() : baseType.WrapUnion();
            }

            // struct or union の定義がある場合
            var body =
                    CreateStructDeclarationList(
                            node.Element("struct_declaration_list"));
            var structOrUnion = isStruct
                                        ? (UnifiedClassLikeDefinition)
                                          UnifiedStructDefinition.
                                                  Create(
                                                          name: typeName,
                                                          body: body)
                                        : UnifiedUnionDefinition.Create(
                                                name: typeName, body: body);

            // TODO struct or unionはあくまでもTypeとして返すののか?
            return UnifiedType.Create(structOrUnion);
        }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:45,代码来源:CProgramGeneratorHelper.cs

示例13: CreateTypeSpecifier

 public static UnifiedExpression CreateTypeSpecifier(XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "type_specifier");
     /*	type_specifier
      * : 'void'
      * | 'char'
      * | 'short'
      * | 'int'
      * | 'long'
      * | 'float'
      * | 'double'
      * | 'signed'
      * | 'unsigned'
      * | struct_or_union_specifier
      * | enum_specifier
      * | type_id
      */
     var first = node.FirstElement();
     switch (first.Name()) {
     case "struct_or_union_specifier":
         return CreateStructOrUnionSpecifier(first);
     case "enum_specifier":
         return CreateEnumSpecifier(first);
     case "type_id":
         return CreateTypeId(first);
     default:
         return
                 UnifiedType.Create(
                         UnifiedVariableIdentifier.Create(first.Value));
     }
 }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:32,代码来源:CProgramGeneratorHelper.cs

示例14: CreateLiteral

		public static UnifiedLiteral CreateLiteral(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "literal");
			/*
			 * literal 
			 * :   intLiteral
			 * |   longLiteral
			 * |   floatLiteral
			 * |   doubleLiteral
			 * |   charLiteral
			 * |   stringLiteral
			 * |   trueLiteral
			 * |   falseLiteral
			 * |   nullLiteral
			 */
			var first = node.FirstElement();
			switch (first.Name()) {
			case "intLiteral":
				return CreateIntLiteral(first);
			case "longLiteral":
				return CreateLongLiteral(first);
			case "floatLiteral":
				return CreateFloatLiteral(first);
			case "doubleLiteral":
				return CreateDoubleLiteral(first);
			case "charLiteral":
				return UnifiedCharLiteral.Create(first.Value);
			case "stringLiteral":
				return UnifiedStringLiteral.Create(first.Value);
			case "trueLiteral":
				return UnifiedBooleanLiteral.Create(true);
			case "falseLiteral":
				return UnifiedBooleanLiteral.Create(false);
			case "nullLiteral":
				return UnifiedNullLiteral.Create();
			}
			throw new InvalidOperationException();
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:38,代码来源:JavaProgramGeneratorHelper.cs

示例15: CreateParameterDeclaration

        public static UnifiedParameter CreateParameterDeclaration(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "parameter_declaration");
            /*
            parameter_declaration
            : declaration_specifiers (declarator|abstract_declarator)*
             */

            UnifiedIdentifier name;
            UnifiedSet<UnifiedParameter> parameters;

            var modifiersAndType =
                    CreateDeclarationSpecifiers(
                            node.Element("declaration_specifiers"));
            var modifiers = modifiersAndType.Item1;
            var type = (UnifiedType)modifiersAndType.Item2;

            var declarators = node.Elements("declarator");
            if (declarators.Count() == 0) {
                return UnifiedParameter.Create(null, modifiers, type);
            }
            var declarator = CreateDeclarator(node.FirstElement("declarator"));

            // abstract_declaratorはおそらく[]など=> よって、最初に現れることはないはず( // TODO 未検証)

            if (node.Element("abstract_declarator") != null) {
                // TODO (int y[])の場合は、[]はどこに付くのか?
                throw new NotImplementedException();
            }
                    // TODO 実際のところ、そこまで理解しきれていない
            else if (declarators.Count() == 1) {
                // 多分declarator自体は1つしか現れないはず( // TODO 未検証)
                return UnifiedParameter.Create(
                        null, modifiers, type, declarator.Item1.ToSet());
            } else if (node.Element("declarator") != null) {
                parameters = declarator.Item2;
                name = declarator.Item1;
                if (parameters != null && parameters.Count > 0) {
                    // この場合はパラメータが関数ポインタ
                    var returnType = type;
                    type = UnifiedType.Create(
                            UnifiedFunctionDefinition.Create(
                                    null, modifiers, returnType, null, null,
                                    parameters));
                    modifiers = null;
                }
                return UnifiedParameter.Create(
                        null, modifiers, type, name.ToSet(), null);
            }
            throw new InvalidOperationException();
        }
开发者ID:UnicoenProject,项目名称:UNICOEN,代码行数:52,代码来源:CProgramGeneratorHelper.cs


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