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


C# XElement.HasElement方法代码示例

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


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

示例1: CreateInnerCreator

		public static UnifiedExpression CreateInnerCreator(
				UnifiedExpression prefix,
				XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "innerCreator");
			/*
			 * innerCreator  
			 * :   '.' 'new' (nonWildcardTypeArguments)? IDENTIFIER (typeArguments)? classCreatorRest 
			 */

			//コード例
			// X . new <T> Sample <E> (1,2){}

			var typeArguments = node.HasElement("typeArguments")
										? CreateTypeArguments(
												node.Element("typeArguments"))
										: null;
			var type = UnifiedType.Create(
					node.Element("IDENTIFIER").Value).WrapGeneric(typeArguments);
			var creatorRest =
					CreateClassCreatorRest(node.Element("classCreatorRest"));
			var typeParameters = node.HasElement("nonWildcardTypeArguments")
										? CreateNonWildcardTypeArguments(
												node.Element(
														"nonWildcardTypeArguments"))
										: null;
			var prop = UnifiedNew.Create(
					type, creatorRest.Item1, typeParameters, null,
					creatorRest.Item2);

			return UnifiedProperty.Create(".", prefix, prop);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:32,代码来源:JavaProgramGeneratorHelper.cs

示例2: CreateConditionalExpression

		public static UnifiedExpression CreateConditionalExpression(
				XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "conditionalExpression");
			/*
			 * conditionalExpression 
			 * :   conditionalOrExpression ('?' expression ':' conditionalExpression)?
			 */

			if (node.HasElement("expression")) {
				return UnifiedTernaryExpression.Create(
						CreateConditionalOrExpression(node.NthElement(0)),
						CreateExpression(node.NthElement(2)),
						CreateConditionalExpression(node.NthElement(4))
						);
			}
			return CreateConditionalOrExpression(node.FirstElement());
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:18,代码来源:JavaProgramGeneratorHelper.cs

示例3: CreateArrayCreator

		public static UnifiedNew CreateArrayCreator(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "arrayCreator");
			/*
			 * arrayCreator 
			 * :   'new' createdName '[' ']' ('[' ']')* arrayInitializer
			 * |   'new' createdName '[' expression ']' ( '[' expression ']' )* ('[' ']')* 
			 */

			var type = CreateCreatedName(node.NthElement(1));

			if (node.HasElement("arrayInitializer")) {
				var initVal =
						CreateArrayInitializer(node.Element("arrayInitializer"));
				var dimension = node.ElementsByContent("[").Count();
				type = type.WrapArrayRepeatedly(dimension);
				return UnifiedNew.Create(type, null, null, initVal);
			}

			type = node.Elements("expression")
					.Aggregate(
							type, (current, exp) => current
															.WrapArray(
																	CreateExpression
																			(
																					exp)
																			.
																			ToArgument
																			()));
			{
				var dimension = node.ElementsByContent("[")
						.Where(e => e.NextElement().Value == "]")
						.Count();
				type = type.WrapArrayRepeatedly(dimension);
			}
			return UnifiedNew.Create(type);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:37,代码来源:JavaProgramGeneratorHelper.cs

示例4: CreateTryStatement

        public static UnifiedExpression CreateTryStatement(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "tryStatement");
            /*
             * tryStatement
             *		: 'try' LT!* statementBlock LT!* (finallyClause | catchClause (LT!* finallyClause)?)
             */

            var body = CreateStatementBlock(node.Element("statementBlock"));
            var catches = node.HasElement("catchClause")
                                  ? CreateCatchClause(
                                          node.Element("catchClause")) : null;
            var finallyBody = node.HasElement("finallyClause")
                                      ? CreateFinallyClause(
                                              node.Element("finallyClause"))
                                      : null;

            return UnifiedTry.Create(body, catches, null, finallyBody);
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:20,代码来源:JavaScriptProgramGeneratorHelper.cs

示例5: CreateForstatement

		public static UnifiedExpression CreateForstatement(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "forstatement");
			/*
			 * forstatement 
			 * // enhanced for loop
			 *     'for' '(' variableModifiers type IDENTIFIER ':' expression ')' statement
			 * // normal for loop
			 * |   'for' '(' (forInit)? ';' (expression)? ';' (expressionList)? ')' statement 
			 */
			if (node.NthElement(2).Name() == "variableModifiers") {
				var annotationsAndModifiers =
						CreateVariableModifiers(
								node.Element("variableModifiers"));
				return UnifiedForeach.Create(
						UnifiedVariableDefinition.Create(
								annotationsAndModifiers.Item1,
								annotationsAndModifiers.Item2,
								CreateType(node.Element("type")),
								UnifiedVariableIdentifier.Create(
										node.Element("IDENTIFIER").Value)
								).ToVariableDefinitionList(),
						CreateExpression(node.Element("expression")),
						CreateStatement(node.Element("statement")).ToBlock()
						);
			}
			var forInit = node.HasElement("forInit")
								? CreateForInit(node.Element("forInit"))
								: null;
			var condition = node.HasElement("expression")
									? CreateExpression(
											node.Element("expression"))
									: null;
			var step = node.HasElement("expressionList")
					   // TODO tuple?
							? CreateExpressionList(
									node.Element("expressionList"))
									.ToTupleLiteral()
							: null;
			var body =
					UnifiedBlock.Create(
							CreateStatement(node.Element("statement")));

			return UnifiedFor.Create(forInit, condition, step, body);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:45,代码来源:JavaProgramGeneratorHelper.cs

示例6: CreateBlock

		public static IEnumerable<UnifiedExpression> CreateClassBodyDeclaration
				(
				XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "classBodyDeclaration");
			/*
			 * classBodyDeclaration 
			 * :   ';'
			 * |   ('static')? block
			 * |   memberDecl 
			 */
			if (node.HasElement("block")) {
				//case static initializer
				var modifier = node.HasContent("static")
									? UnifiedModifier.Create("static")
									: null;
				yield return UnifiedStaticInitializer.Create(
						CreateBlock(node.Element("block")), null,
						UnifiedSet<UnifiedModifier>.Create(modifier));
			}
			if (node.HasElement("memberDecl")) {
				yield return CreateMemberDecl(node.Element("memberDecl"));
			}
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:24,代码来源:JavaProgramGeneratorHelper.cs

示例7: CreateVariableInitializer

		public static UnifiedVariableDefinition CreateVariableDeclarator
				(
				XElement node, UnifiedSet<UnifiedAnnotation> annotations,
				UnifiedSet<UnifiedModifier> modifiers, UnifiedType type) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "variableDeclarator");
			/*
			 * variableDeclarator 
			 * :   IDENTIFIER ('[' ']')* ('=' variableInitializer)? 
			 */
			var initializer = node.HasElement("variableInitializer")
									? CreateVariableInitializer(
											node.Element(
													"variableInitializer"))
									: null;
			var dimension = node.ElementsByContent("[").Count();
			type = type.WrapArrayRepeatedly(dimension);

			return UnifiedVariableDefinition.Create(
					annotations, modifiers, type,
					UnifiedVariableIdentifier.Create(node.FirstElement().Value),
					initializer
					);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:24,代码来源:JavaProgramGeneratorHelper.cs

示例8: CreateForStatement

        public static UnifiedFor CreateForStatement(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "forStatement");
            /*
             * forStatement
             *		: 'for' LT!* '(' (LT!* forStatementInitialiserPart)? LT!* ';' (LT!* expression)? LT!* ';' (LT!* expression)? LT!* ')' LT!* statement
             */

            var init = node.HasElement("forStatementInitialiserPart")
                               ? CreateForStatementInitialiserPart(
                                       node.Element(
                                               "forStatementInitialiserPart"))
                               : null;

            //expressionを区別できないので、セミコロンの位置から条件なのかステップなのかを判断
            var semicolons = node.Elements().Where(e => e.Value == ";");
            var first = semicolons.ElementAt(0).NextElement();
            var second = semicolons.ElementAt(1).NextElement();

            var cond = first.Name() == "expression"
                               ? CreateExpression(first) : null;
            var step = second.Name() == "expression"
                               ? CreateExpression(second) : null;
            var body =
                    UnifiedBlock.Create(
                            CreateStatement(node.Element("statement")));

            return UnifiedFor.Create(init, cond, step, body);
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:30,代码来源:JavaScriptProgramGeneratorHelper.cs

示例9: CreateForStatementInitialiserPart

        public static UnifiedExpression CreateForStatementInitialiserPart(
            XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "forStatementInitialiserPart");
            /*
             * forStatementInitialiserPart
             *		: expressionNoIn
             *		| 'var' LT!* variableDeclarationListNoIn
             */

            if (node.NthElement(0).Name() == "expressionNoIn") {
                return CreateExpressionNoIn(node.NthElement(0));
            }
            if (node.HasElement("variableDeclarationListNoIn")) {
                return
                        CreateVariableDeclarationListNoIn(
                                node.Element("variableDeclarationListNoIn"));
            }
            throw new InvalidOperationException();
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:21,代码来源:JavaScriptProgramGeneratorHelper.cs

示例10: CreateDefaultClause

        public static UnifiedCase CreateDefaultClause(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "defaultClause");
            /*
             * defaultClause
             *		: 'default' LT!* ':' LT!* statementList?
             */
            var body = node.HasElement("statementList")
                               ? CreateStatementList(
                                       node.Element("statementList")) : null;

            return UnifiedCase.Create(null, UnifiedBlock.Create(body));
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:14,代码来源:JavaScriptProgramGeneratorHelper.cs

示例11: CreateForInStatementInitialiserPart

        public static UnifiedExpression CreateForInStatementInitialiserPart(
            XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "forInStatementInitialiserPart");
            /*
             * forInStatementInitialiserPart
             *		: leftHandSideExpression
             *		| 'var' LT!* variableDeclarationNoIn
             */

            //左辺がCall or Newになる場合のコードはまだ未確認
            if (node.NthElement(0).Name() == "leftHandSideExpression") {
                return CreateLeftHandSideExpression(node.NthElement(0));
            }

            if (node.HasElement("variableDeclarationNoIn")) {
                return CreateVariableDeclarationNoIn(
                        node.Element("variableDeclarationNoIn"))
                        .ToVariableDefinitionList();
            }
            throw new InvalidOperationException();
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:23,代码来源:JavaScriptProgramGeneratorHelper.cs

示例12: CreateContinueStatement

        public static UnifiedExpression CreateContinueStatement(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "continueStatement");
            /*
             * continueStatement
             *		: 'continue' Identifier? statementEnd
             */

            var identifier = node.HasElement("Identifier")
                                     ? UnifiedVariableIdentifier.Create(
                                             node.Element("Identifier").Value)
                                     : null;

            return UnifiedContinue.Create(identifier);
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:16,代码来源:JavaScriptProgramGeneratorHelper.cs

示例13: CreateConditionalExpressionNoIn

 public static UnifiedExpression CreateConditionalExpressionNoIn(
     XElement node)
 {
     Contract.Requires(node != null);
     Contract.Requires(node.Name() == "conditionalExpressionNoIn");
     /*
      * conditionalExpressionNoIn
      *		: logicalORExpressionNoIn (LT!* '?' LT!* assignmentExpressionNoIn LT!* ':' LT!* assignmentExpressionNoIn)?
      */
     if (node.HasElement("assignmentExpressionNoIn")) {
         return UnifiedTernaryExpression.Create(
                 CreateLogicalORExpressionNoIn(
                         node.Element("logicalORExpressionNoIn")),
                 CreateAssignmentExpressionNoIn(
                         node.Element("assignmentExpressionNoIn")),
                 CreateAssignmentExpressionNoIn(
                         node.Elements("assignmentExpressionNoIn").
                                 ElementAt(1)));
     }
     return CreateLogicalORExpressionNoIn(node.NthElement(0));
 }
开发者ID:macc704,项目名称:UNICOEN,代码行数:21,代码来源:JavaScriptProgramGeneratorHelper.cs

示例14: CreateCaseClause

        public static UnifiedCase CreateCaseClause(XElement node)
        {
            Contract.Requires(node != null);
            Contract.Requires(node.Name() == "caseClause");
            /*
             * caseClause
             *		: 'case' LT!* expression LT!* ':' LT!* statementList?
             */
            var cond = CreateExpression(node.Element("expression"));
            var body = node.HasElement("statementList")
                               ? CreateStatementList(
                                       node.Element("statementList")) : null;

            return UnifiedCase.Create(cond, UnifiedBlock.Create(body));
        }
开发者ID:macc704,项目名称:UNICOEN,代码行数:15,代码来源:JavaScriptProgramGeneratorHelper.cs

示例15: CreateClassCreatorRest

				CreateClassCreatorRest(XElement node) {
			Contract.Requires(node != null);
			Contract.Requires(node.Name() == "classCreatorRest");
			/*
			 * classCreatorRest 
			 * :   arguments (classBody)? 
			 */

			var body = node.HasElement("classBody")
							? CreateClassBody(node.Element("classBody"))
							: null;
			return
					new Tuple<UnifiedSet<UnifiedArgument>, UnifiedBlock>(
							CreateArguments(node.Element("arguments")), body);
		}
开发者ID:macc704,项目名称:UNICOEN,代码行数:15,代码来源:JavaProgramGeneratorHelper.cs


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