本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax.IsEquivalentTo方法的典型用法代码示例。如果您正苦于以下问题:C# TypeSyntax.IsEquivalentTo方法的具体用法?C# TypeSyntax.IsEquivalentTo怎么用?C# TypeSyntax.IsEquivalentTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax
的用法示例。
在下文中一共展示了TypeSyntax.IsEquivalentTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchWhereSelect
// internal static readonly AstNode wherePatternCase1 =
// new InvocationExpression(
// new MemberReferenceExpression(
// new InvocationExpression(
// new MemberReferenceExpression(new AnyNode("target"), "Where"),
// new LambdaExpression {
// Parameters = { PatternHelper.NamedParameter ("param1", PatternHelper.AnyType ("paramType", true), Pattern.AnyString) },
// Body = PatternHelper.OptionalParentheses (new IsExpression(new AnyNode("expr1"), new AnyNode("type")))
// }
// ), "Select"),
// new LambdaExpression {
// Parameters = { PatternHelper.NamedParameter ("param2", PatternHelper.AnyType ("paramType", true), Pattern.AnyString) },
// Body = PatternHelper.OptionalParentheses (new AsExpression(PatternHelper.OptionalParentheses (new AnyNode("expr2")), new Backreference("type")))
// }
// );
//
// internal static readonly AstNode wherePatternCase2 =
// new InvocationExpression(
// new MemberReferenceExpression(
// new InvocationExpression(
// new MemberReferenceExpression(new AnyNode("target"), "Where"),
// new LambdaExpression {
// Parameters = { PatternHelper.NamedParameter ("param1", PatternHelper.AnyType ("paramType", true), Pattern.AnyString) },
// Body = PatternHelper.OptionalParentheses (new IsExpression(PatternHelper.OptionalParentheses (new AnyNode("expr1")), new AnyNode("type")))
// }
// ), "Select"),
// new LambdaExpression {
// Parameters = { PatternHelper.NamedParameter ("param2", PatternHelper.AnyType ("paramType", true), Pattern.AnyString) },
// Body = PatternHelper.OptionalParentheses (new CastExpression(new Backreference("type"), PatternHelper.OptionalParentheses (new AnyNode("expr2"))))
// }
// );
static bool MatchWhereSelect(InvocationExpressionSyntax selectInvoke, out ExpressionSyntax target, out TypeSyntax type)
{
target = null;
type = null;
if (selectInvoke.ArgumentList.Arguments.Count != 1)
return false;
var anyInvokeBase = selectInvoke.Expression as MemberAccessExpressionSyntax;
if (anyInvokeBase == null || anyInvokeBase.Name.Identifier.Text != "Select")
return false;
var whereInvoke = anyInvokeBase.Expression as InvocationExpressionSyntax;
if (whereInvoke == null || whereInvoke.ArgumentList.Arguments.Count != 1)
return false;
var baseMember = whereInvoke.Expression as MemberAccessExpressionSyntax;
if (baseMember == null || baseMember.Name.Identifier.Text != "Where")
return false;
target = baseMember.Expression;
ParameterSyntax param1, param2;
ExpressionSyntax expr1, expr2;
if (!ExtractLambda(whereInvoke.ArgumentList.Arguments[0], out param1, out expr1))
return false;
if (!ExtractLambda(selectInvoke.ArgumentList.Arguments[0], out param2, out expr2))
return false;
if (!expr1.IsKind(SyntaxKind.IsExpression))
return false;
type = (expr1 as BinaryExpressionSyntax)?.Right as TypeSyntax;
if (type == null)
return false;
if (expr2.IsKind(SyntaxKind.AsExpression))
{
if (!CompareNames(param2, (expr2 as BinaryExpressionSyntax).Left as IdentifierNameSyntax))
return false;
if (!type.IsEquivalentTo((expr2 as BinaryExpressionSyntax)?.Right))
return false;
}
else if (expr2.IsKind(SyntaxKind.CastExpression))
{
if (!CompareNames(param2, (expr2 as CastExpressionSyntax)?.Expression.SkipParens() as IdentifierNameSyntax))
return false;
if (!type.IsEquivalentTo((expr2 as CastExpressionSyntax)?.Type))
return false;
}
else
return false;
if (!CompareNames(param1, (expr1 as BinaryExpressionSyntax)?.Left as IdentifierNameSyntax))
return false;
return target != null;
}