本文整理匯總了C#中System.Xml.Linq.XElement.NthElement方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.NthElement方法的具體用法?C# XElement.NthElement怎麽用?C# XElement.NthElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.NthElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateModule
public static UnifiedClassDefinition CreateModule(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "module");
return UnifiedClassDefinition.Create(
null, null, CreateSymbol(node.NthElement(0)), null,
null,
CreateScope(node.NthElement(1)));
}
示例2: CreateIf
public static UnifiedIf CreateIf(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "if");
return UnifiedIf.Create(
CreateExpresion(node.NthElement(0)),
CreateBlock(node.NthElement(1)),
CreateBlock(node.NthElement(2)));
}
示例3: CreateDefn
public static UnifiedExpression CreateDefn(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "defn");
return UnifiedFunctionDefinition.Create(
null, null, null, null,
CreateSymbol(node.NthElement(0)),
CreateArgs(node.NthElement(1)), null,
CreateScope(node.NthElement(2)));
}
示例4: CreateSclass
public static UnifiedEigenClassDefinition CreateSclass(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "sclass");
return UnifiedEigenClassDefinition.Create(
null, null, null, null,
UnifiedEigenConstrain.Create(
CreateExpresion(node.NthElement(0))).
ToSet<UnifiedTypeConstrain>(),
CreateScope(node.NthElement(1)));
}
示例5: CreateFor
public static UnifiedExpression CreateFor(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "for");
Contract.Assert(
node.NthElement(1).Name() == "lasgn"
|| node.NthElement(1).Name() == "masgn");
return UnifiedForeach.Create(
CreateExpresion(node.NthElement(0)),
CreateExpresion(node.NthElement(1).FirstElement()),
CreateBlock(node.NthElement(2)));
}
示例6: CreateClass
public static UnifiedClassDefinition CreateClass(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "class");
var constNode = node.NthElement(1);
var constrain = constNode.Name() != "nil"
? UnifiedExtendConstrain.Create(
UnifiedType.Create(constNode.Value))
: null;
return UnifiedClassDefinition.Create(
null, null, CreateSymbol(node.NthElement(0)), null,
constrain.ToSet<UnifiedTypeConstrain>(),
CreateScope(node.NthElement(2)));
}
示例7: CreateCall
public static UnifiedCall CreateCall(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "call");
// TODO: 演算子への変換
var receiver = CreateExpresion(node.NthElement(0));
var secondNode = node.NthElement(1);
return UnifiedCall.Create(
receiver != null
? UnifiedProperty.Create(
".", receiver, CreateExpresion(secondNode))
: CreateExpresion(secondNode),
CreateArglist(node.NthElement(2)));
}
示例8: CreateIter
public static UnifiedCall CreateIter(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "iter");
var call = CreateCall(node.NthElement(0));
var paramNode = node.NthElement(1);
Contract.Assert(
paramNode.Name() != "Fixnum" || paramNode.Value == "0");
var parameters = paramNode.Name() != "Fixnum"
? CreateLasgnOrMasgnOrNil(
node.NthElement(1))
.Select(e => e.ToParameter())
.ToSet()
: null;
var block = CreateBlock(node.NthElement(2));
call.Proc = UnifiedProc.Create(parameters, block);
return call;
}
示例9: CreateCase
public static UnifiedExpression CreateCase(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "case");
return UnifiedSwitch.Create(
CreateExpresion(node.NthElement(0)),
node.Elements().Skip(1)
.SelectMany(CreateWhenAndDefault)
.ToSet()
);
}
示例10: CreateDefs
private static UnifiedExpression CreateDefs(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "defs");
var owner = CreateExpresion(node.NthElement(0));
var target = UnifiedFunctionDefinition.Create(
null, null, null, null,
CreateSymbol(node.NthElement(1)),
CreateArgs(node.NthElement(2)), null,
CreateScope(node.NthElement(3)));
return UnifiedProperty.Create(".", owner, target);
}
示例11: 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;
}
示例12: CreateNormalInterfaceDeclaration
CreateNormalInterfaceDeclaration(
XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "normalInterfaceDeclaration");
/*
* normalInterfaceDeclaration
* : modifiers 'interface' IDENTIFIER (typeParameters)? ('extends' typeList)? interfaceBody
*/
var annotationsAndModifiers =
CreateModifiers(node.Element("modifiers"));
var name = UnifiedVariableIdentifier.Create(
node.NthElement(2).Value);
var typeParametersNode = node.Element("typeParameters");
var typeParameters = typeParametersNode != null
? CreateTypeParameters(
typeParametersNode)
: null;
var typeListNode = node.Element("typeList");
var constrains = typeListNode != null
? UnifiedSet<UnifiedTypeConstrain>.Create(
CreateTypeList(typeListNode).Select
(
UnifiedExtendConstrain
.Create))
: null;
var body = CreateInterfaceBody(node.Element("interfaceBody"));
return UnifiedInterfaceDefinition.Create(
annotationsAndModifiers.Item1,
annotationsAndModifiers.Item2,
name,
typeParameters,
constrains,
body);
}
示例13: 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);
}
示例14: CreateNormalClassDeclaration
public static UnifiedClassLikeDefinition CreateNormalClassDeclaration(
XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "normalClassDeclaration");
/*
* normalClassDeclaration
* : modifiers 'class' IDENTIFIER (typeParameters)? ('extends' type)? ('implements' typeList)? classBody
*/
var annotationsAndModifiers =
CreateModifiers(node.Element("modifiers"));
var name = node.NthElement(2).Value;
var typeParameters = node.HasElement("typeParameters")
? CreateTypeParameters(
node.Element("typeParameters"))
: null;
var constrains = UnifiedSet<UnifiedTypeConstrain>.Create();
if (node.HasElement("type")) {
constrains.Add(
UnifiedExtendConstrain.Create(
CreateType(node.Element("type"))));
}
if (node.HasElement("typeList")) {
foreach (var type in CreateTypeList(node.Element("typeList"))) {
constrains.Add(UnifiedImplementsConstrain.Create(type));
}
}
var body = CreateClassBody(node.Element("classBody"));
return UnifiedClassDefinition.Create(
annotationsAndModifiers.Item1,
annotationsAndModifiers.Item2,
UnifiedVariableIdentifier.Create(name), typeParameters,
constrains, body);
}
示例15: CreateEnumDeclaration
public static UnifiedClassLikeDefinition CreateEnumDeclaration(
XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "enumDeclaration");
/*
* enumDeclaration
* : modifiers ('enum') IDENTIFIER ('implements' typeList)? enumBody
*/
var annotationsAndModifiers = CreateModifiers(node.FirstElement());
var name = node.NthElement(2).Value;
var typeListNode = node.Element("typeList");
var constrains = typeListNode != null
? CreateTypeList(typeListNode)
.Select(
UnifiedImplementsConstrain
.Create)
.ToSet<UnifiedTypeConstrain>()
: null;
var enumBody = CreateEnumBody(node.Element("enumBody"));
return UnifiedEnumDefinition.Create(
annotationsAndModifiers.Item1,
annotationsAndModifiers.Item2,
UnifiedVariableIdentifier.Create(name),
null,
constrains,
enumBody);
}