本文整理汇总了C#中System.Xml.Linq.XElement.LastElement方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.LastElement方法的具体用法?C# XElement.LastElement怎么用?C# XElement.LastElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.LastElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
示例2: 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()));
}
示例3: CreateArgs
public static UnifiedSet<UnifiedParameter> CreateArgs(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "args");
Contract.Requires(
node.Elements().All(
e => e.Name() == "Symbol" || e.Name() == "block"));
var args = node.Elements("Symbol")
.Select(e => e.Value.ToVariableIdentifier().ToParameter())
.ToSet();
if (args.Count > 0 && node.LastElement().Name() == "block") {
// デフォルト引数付き
var asgnNodes = node.LastElement().Elements();
foreach (var asgnNode in asgnNodes) {
var name = asgnNode.FirstElement().Value;
args.First(arg => arg.Names[0].Name == name)
.DefaultValue =
CreateExpresion(asgnNode.NthElement(1));
}
}
return args;
}
示例4: CreateDeclaratorSuffix
public static UnifiedSet<UnifiedParameter> CreateDeclaratorSuffix(
XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "declarator_suffix");
/* declarator_suffix
* : '[' constant_expression ']'
* | '[' ']'
* | '(' parameter_type_list ')'
* | '(' identifier_list ')'
* | '(' ')'
* ;
*/
// 空のパラメータリストを生成する
var parameters = UnifiedSet<UnifiedParameter>.Create();
// ()の場合
if (node.FirstElement().Value.Equals("(")
&& node.LastElement().Value.Equals(")")) {
if (node.Element("parameter_type_list") != null) {
parameters =
CreateParameterTypeList(
node.Element("parameter_type_list"));
} else if (node.Element("identifier_list") != null) {
// TODO どう考えてもargumentCollectionだが、対応するプログラムをまずは検証する
throw new NotImplementedException();
}
// []の場合
} else if (node.FirstElement().Value.Equals("[")
&& node.LastElement().Value.Equals("]")) {
// TODO []がくるケースがまだ未検証
throw new NotImplementedException();
} else {
throw new InvalidOperationException();
}
return parameters;
}
示例5: CreateTypeParameter
public static UnifiedGenericParameter CreateTypeParameter(XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "typeParameter");
/*
* typeParameter
* : IDENTIFIER ('extends' typeBound)?
*/
if (node.Elements().Count() == 1) {
return
UnifiedGenericParameter.Create(
UnifiedType.Create(node.FirstElement().Value));
}
return UnifiedGenericParameter.Create(
UnifiedType.Create(node.FirstElement().Value),
UnifiedSet<UnifiedTypeConstrain>.Create(
CreateTypeBound(node.LastElement())
.Select(UnifiedExtendConstrain.Create))
);
}
示例6: CreateCastExpression
public static UnifiedCast CreateCastExpression(XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "castExpression");
/*
* castExpression
* : '(' primitiveType ')' unaryExpression
* | '(' type ')' unaryExpressionNotPlusMinus
*/
if (node.LastElement().Name() == "unaryExpression") {
return UnifiedCast.Create(
CreatePrimitiveType(node.NthElement(1)),
CreateUnaryExpression(node.NthElement(3))
);
}
return UnifiedCast.Create(
CreateType(node.NthElement(1)),
CreateUnaryExpressionNotPlusMinus(node.NthElement(3))
);
}
示例7: CreateStatement
public static IEnumerable<UnifiedExpression> CreateStatement(
XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "statement");
/*
* statement
* : block
* | ('assert') expression (':' expression)? ';'
* | 'assert' expression (':' expression)? ';'
* | 'if' parExpression statement ('else' statement)?
* | forstatement
* | 'while' parExpression statement
* | 'do' statement 'while' parExpression ';'
* | trystatement
* | 'switch' parExpression '{' switchBlockStatementGroups '}'
* | 'synchronized' parExpression block
* | 'return' (expression )? ';'
* | 'throw' expression ';'
* | 'break' (IDENTIFIER)? ';'
* | 'continue' (IDENTIFIER)? ';'
* | expression ';'
* | IDENTIFIER ':' statement
* | ';'
*/
var first = node.FirstElement();
switch (first.Name()) {
case "block":
yield return CreateBlock(first);
yield break;
case "forstatement":
yield return CreateForstatement(first);
yield break;
case "trystatement":
yield return CreateTrystatement(first);
yield break;
case "expression":
yield return CreateExpression(first);
yield break;
case "IDENTIFIER":
yield return UnifiedLabel.Create(first.Value);
foreach (var stmt in CreateStatement(node.LastElement())) {
yield return stmt;
}
yield break;
}
switch (first.Value) {
case "assert":
var list = node.Elements("expression")
.Select(CreateExpression)
.ToList();
if (list.Count == 1) {
yield return UnifiedAssert.Create(list[0]);
} else {
yield return UnifiedAssert.Create(list[0], list[1]);
}
break;
case "if":
yield return CreateIf(node);
break;
case "while":
yield return CreateWhile(node);
break;
case "do":
yield return CreateDoWhile(node);
break;
case "switch":
yield return CreateSwitch(node);
break;
case "synchronized":
yield return CreateSynchronized(node);
break;
case "return":
yield return CreateReturn(node);
break;
case "throw":
yield return CreateThrow(node);
break;
case "break":
yield return CreateBreak(node);
break;
case "continue":
yield return CreateContinue(node);
break;
case ";":
break;
default:
throw new IndexOutOfRangeException();
}
}
示例8: CreateElementValuePair
public static UnifiedArgument CreateElementValuePair(XElement node) {
Contract.Requires(node != null);
Contract.Requires(node.Name() == "elementValuePair");
/*
* elementValuePair
* : IDENTIFIER '=' elementValue
*/
return UnifiedArgument.Create(
CreateElementValue(node.LastElement()),
UnifiedVariableIdentifier.Create(node.FirstElement().Value),
null);
}
示例9: CreateFor_stmt
public static UnifiedExpression CreateFor_stmt(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "for_stmt");
/*
* for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite]
*/
var exprlist = CreateExprlist(node.Element("exprlist"));
var testlist = CreateTestlist(node.Element("testlist"));
var suite = CreateSuite(node.Element("suite"));
var elseSuite = node.HasElementByContent("else")
? CreateSuite(node.LastElement())
: null;
return UnifiedForeach.Create(
exprlist.SelectMany(
e => e.DescendantsAndSelf<UnifiedIdentifier>())
.Select(
e =>
UnifiedVariableDefinition.Create(
name: e.DeepCopy()))
.ToVariableDefinitionList(),
testlist.ToSmartTupleLiteral(),
suite,
elseSuite);
}
示例10: CreateClassdef
public static UnifiedClassDefinition CreateClassdef(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "classdef");
/*
* classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
*/
var testlistNodes = node.Element("testlist");
var testlist = testlistNodes != null
? CreateTestlist(testlistNodes)
.Select(UnifiedType.Create)
.Select(
UnifiedExtendConstrain.
Create)
.ToSet<UnifiedTypeConstrain>()
: null;
return UnifiedClassDefinition.Create(
null, UnifiedSet<UnifiedModifier>.Create(),
UnifiedVariableIdentifier.Create(node.NthElement(1).Value),
null, testlist,
CreateSuite(node.LastElement()));
}
示例11: CreateYield_expr
public static UnifiedExpression CreateYield_expr(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "yield_expr");
/*
* yield_expr: 'yield' [testlist]
*/
if (node.Elements().Count() == 1) {
return
UnifiedYieldReturn.Create();
}
return
UnifiedYieldReturn.Create(
CreateTestlist(node.LastElement()).
ToSmartTupleLiteral());
}
示例12: CreateWhile_stmt
public static UnifiedExpression CreateWhile_stmt(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "while_stmt");
/*
* while_stmt: 'while' test ':' suite ['else' ':' suite]
*/
var test = CreateTest(node.Element("test"));
var suite = CreateSuite(node.Element("suite"));
var elseSuite = node.HasElementByContent("else")
? CreateSuite(node.LastElement())
: null;
return UnifiedWhile.Create(test, suite, elseSuite);
}
示例13: CreateTrailer
public static UnifiedExpression CreateTrailer(
UnifiedExpression prefix, XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "trailer");
/*
* trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
*/
switch (node.FirstElement().Value) {
case "(":
var arglistNode = node.Element("arglist");
return arglistNode != null
? UnifiedCall.Create(
prefix, CreateArglist(arglistNode))
: UnifiedCall.Create(
prefix,
UnifiedSet<UnifiedArgument>.Create());
case "[":
var second = node.NthElement(1);
return UnifiedIndexer.Create(
prefix, CreateSubscriptlist(second));
case ".":
return UnifiedProperty.Create(
".", prefix,
UnifiedVariableIdentifier.Create(
node.LastElement().Value));
default:
throw new IndexOutOfRangeException();
}
}
示例14: CreateTfpdef
public static UnifiedParameter CreateTfpdef(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "tfpdef");
/*
* tfpdef: NAME [':' test]
*/
var ret = UnifiedParameter.Create(
null, null, null,
UnifiedVariableIdentifier.Create(node.FirstElement().Value).ToSet<UnifiedIdentifier>());
if (node.Elements().Count() > 1) {
ret.AnnotationExpression = CreateTest(node.LastElement());
}
return ret;
}
示例15: CreateTest
public static UnifiedExpression CreateTest(XElement node)
{
Contract.Requires(node != null);
Contract.Requires(node.Name() == "test");
/*
* test: or_test ['if' or_test 'else' test] | lambdef
*/
var first = node.FirstElement();
if (first.Name() == "lambdef") {
return CreateLambdef(first);
}
var last = node.LastElement();
if (last.Name() != "test") {
return CreateOr_test(first);
}
return UnifiedTernaryExpression.Create(
CreateOr_test(node.NthElement(2)),
CreateOr_test(first),
CreateTest(last));
}