本文整理汇总了C#中ExpressionSyntax.Match方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.Match方法的具体用法?C# ExpressionSyntax.Match怎么用?C# ExpressionSyntax.Match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.Match方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IntegerLiteral
public IntegerLiteral(ExpressionSyntax syntax, Package containingPackage)
: base(syntax, containingPackage)
{
Value = syntax.Match().Returning<BigInteger>()
.With<IntegerLiteralSyntax>(literal => literal.Value)
.Any(() =>
{
throw new ArgumentException("Must be an IntegerLiteralSyntax or a negated one", nameof(syntax));
});
}
示例2: Resolve
private static Expression Resolve(Package containingPackage, ExpressionSyntax syntax, IReadOnlyDictionary<SyntaxNode, Binder> binders)
{
return syntax.Match().Returning<Expression>()
.With<IntegerLiteralSyntax>(literal => new IntegerLiteral(literal, containingPackage))
.With<StringLiteralSyntax>(literal => new StringLiteral(literal, containingPackage))
.With<MemberAccessSyntax>(memberAccess =>
{
var expression = Resolve(containingPackage, memberAccess.Expression, binders);
return new MemberAccess(memberAccess, containingPackage, expression);
})
.With<CastSyntax>(cast =>
{
var expression = Resolve(containingPackage, cast.Expression, binders);
var type = Resolve(containingPackage, cast.Type, binders);
return new Cast(cast, containingPackage, expression, cast.CastType, type);
})
.With<CallSyntax>(call =>
{
var expression = Resolve(containingPackage, call.Expression, binders);
var arguments = call.Arguments.Select(arg => Resolve(containingPackage, arg, binders));
return new Call(call, containingPackage, expression, arguments);
})
.With<IdentifierNameSyntax>(identifierName =>
{
var binder = binders[identifierName];
var result = binder.Lookup(identifierName, containingPackage);
var declaration = result.Symbols.Single();
return new IdentifierName(identifierName, containingPackage, declaration);
})
.Exhaustive();
}
示例3: Build
private void Build(ExpressionSyntax expression, Binder containingScope)
{
expression.Match()
.With<AssignmentSyntax>(assignment =>
{
Build(assignment.LValue, containingScope);
Build(assignment.RValue, containingScope);
})
.With<MemberAccessSyntax>(memberExpression =>
{
Build(memberExpression.Expression, containingScope);
})
.With<SelfSyntax, IdentifierNameSyntax>(variableExpression =>
{
binders.Add(variableExpression, containingScope);
})
.With<CallSyntax>(call =>
{
Build(call.Expression, containingScope);
foreach(var argument in call.Arguments)
Build(argument, containingScope);
})
.With<CastSyntax>(cast =>
{
Build(cast.Expression, containingScope);
Build(cast.Type, containingScope);
})
.Ignore<LiteralSyntax>()
.Exhaustive();
}
开发者ID:adamant-deprecated,项目名称:AdamantExploratoryCompiler,代码行数:30,代码来源:CompilationUnitBindersBuilder.cs