本文整理汇总了C#中YieldStatementSyntax.GetAncestorOrThis方法的典型用法代码示例。如果您正苦于以下问题:C# YieldStatementSyntax.GetAncestorOrThis方法的具体用法?C# YieldStatementSyntax.GetAncestorOrThis怎么用?C# YieldStatementSyntax.GetAncestorOrThis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YieldStatementSyntax
的用法示例。
在下文中一共展示了YieldStatementSyntax.GetAncestorOrThis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferTypeInYieldStatement
private IEnumerable<ITypeSymbol> InferTypeInYieldStatement(YieldStatementSyntax yieldStatement, SyntaxToken? previousToken = null)
{
// If we are position based, then we have to be after the return keyword
if (previousToken.HasValue && (previousToken.Value != yieldStatement.ReturnOrBreakKeyword || yieldStatement.ReturnOrBreakKeyword.IsKind(SyntaxKind.BreakKeyword)))
{
return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
}
var memberSymbol = GetDeclaredMemberSymbolFromOriginalSemanticModel(this.semanticModel, yieldStatement.GetAncestorOrThis<MemberDeclarationSyntax>());
var memberType = memberSymbol.TypeSwitch(
(IMethodSymbol method) => method.ReturnType,
(IPropertySymbol property) => property.Type);
if (memberType is INamedTypeSymbol)
{
if (memberType.OriginalDefinition.SpecialType == SpecialType.System_Collections_Generic_IEnumerable_T ||
memberType.OriginalDefinition.SpecialType == SpecialType.System_Collections_Generic_IEnumerator_T)
{
return SpecializedCollections.SingletonEnumerable(((INamedTypeSymbol)memberType).TypeArguments[0]);
}
}
return SpecializedCollections.EmptyEnumerable<ITypeSymbol>();
}