本文整理汇总了C#中ExpressionSyntax.Parents方法的典型用法代码示例。如果您正苦于以下问题:C# ExpressionSyntax.Parents方法的具体用法?C# ExpressionSyntax.Parents怎么用?C# ExpressionSyntax.Parents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionSyntax
的用法示例。
在下文中一共展示了ExpressionSyntax.Parents方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUsings
private static IEnumerable<Fields> GetUsings(ExpressionSyntax expression, ISymbol symbol, SutInfo suitableSut, SemanticModel semanticModel, Dictionary<string, ITypeSymbol> sutSubstitutions)
{
var syntax = expression.Parents(x => (x as UsingStatementSyntax)?.Declaration
.Variables
.Any(y => y.DescendantNodes()
.Any(z => z == expression)) == true) as UsingStatementSyntax;
if (syntax == null) return Enumerable.Empty<Fields>();
var methodSymbol = symbol as IMethodSymbol;
var propertySymbol = symbol as IPropertySymbol;
if (methodSymbol == null && propertySymbol == null)
return Enumerable.Empty<Fields>();
var containingType = (methodSymbol?.ReturnType ?? propertySymbol?.GetMethod?.ReturnType);
var disposable = containingType?.Interfaces.FirstOrDefault(x => x.Name == "IDisposable");
if(disposable == null)
return Enumerable.Empty<Fields>();
var disposeMethod = disposable.GetMembers("Dispose").First();
return syntax.Declaration.Variables.Select(x => new Fields
{
Expression = expression,
MethodOrPropertySymbol = disposeMethod,
FieldsToSetup = GetFieldsToSetup(suitableSut, semanticModel, containingType, sutSubstitutions)
});
}