本文整理汇总了C#中InvocationExpression.GetParent方法的典型用法代码示例。如果您正苦于以下问题:C# InvocationExpression.GetParent方法的具体用法?C# InvocationExpression.GetParent怎么用?C# InvocationExpression.GetParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InvocationExpression
的用法示例。
在下文中一共展示了InvocationExpression.GetParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsConditionallyRemoved
public static bool IsConditionallyRemoved(InvocationExpression invocationExpression, IEntity entity)
{
if (entity == null)
{
return false;
}
var result = new List<string>();
foreach (var a in entity.Attributes)
{
var type = a.AttributeType.GetDefinition();
if (type != null && type.FullName.Equals("System.Diagnostics.ConditionalAttribute", StringComparison.Ordinal))
{
if (a.PositionalArguments.Count > 0)
{
var symbol = a.PositionalArguments[0].ConstantValue as string;
if (symbol != null)
{
result.Add(symbol);
}
}
}
}
if (result.Count > 0)
{
var syntaxTree = invocationExpression.GetParent<SyntaxTree>();
if (syntaxTree != null)
{
return !result.Intersect(syntaxTree.ConditionalSymbols).Any();
}
}
return false;
}
示例2: VisitInvocationExpression
public override void VisitInvocationExpression(InvocationExpression invocationExpression)
{
var match = this.m_Pattern.Match(invocationExpression);
if (match.Success)
{
var method = (invocationExpression.Target as MemberReferenceExpression).MemberName;
if (method == "Write" || method == "WriteLine")
{
// FIXME: Couldn't get a pattern matcher to work on the MethodDeclaration.
var declMethod = invocationExpression.GetParent<MethodDeclaration>();
if (declMethod == null)
{
base.VisitInvocationExpression(invocationExpression);
return;
}
var allowed = (
declMethod.Name == "Main" &&
declMethod.Modifiers == (Modifiers.Public | Modifiers.Static) &&
declMethod.ReturnType.ToString() == "void" &&
declMethod.Parameters.Count == 1 &&
declMethod.Parameters.ToList()[0].Type.ToString() == "string[]");
if (!allowed)
{
this.Results.Issues.Add(new LintIssue(invocationExpression)
{
Index = LintIssueIndex.ConsoleWriteUsedOutsideOfProgramMain,
Parameters = new[]
{
declMethod.GetParent<TypeDeclaration>().Name + "." + declMethod.Name
}
});
}
}
}
base.VisitInvocationExpression(invocationExpression);
}