本文整理汇总了C#中SemanticModel.GetEnclosingNamedType方法的典型用法代码示例。如果您正苦于以下问题:C# SemanticModel.GetEnclosingNamedType方法的具体用法?C# SemanticModel.GetEnclosingNamedType怎么用?C# SemanticModel.GetEnclosingNamedType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SemanticModel
的用法示例。
在下文中一共展示了SemanticModel.GetEnclosingNamedType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanReplaceWithReducedName
private static bool CanReplaceWithReducedName(
this MemberAccessExpressionSyntax memberAccess,
ExpressionSyntax reducedName,
SemanticModel semanticModel,
CancellationToken cancellationToken)
{
if (!IsThisOrTypeOrNamespace(memberAccess, semanticModel))
{
return false;
}
var speculationAnalyzer = new SpeculationAnalyzer(memberAccess, reducedName, semanticModel, cancellationToken);
if (!speculationAnalyzer.SymbolsForOriginalAndReplacedNodesAreCompatible() ||
speculationAnalyzer.ReplacementChangesSemantics())
{
return false;
}
if (WillConflictWithExistingLocal(memberAccess, reducedName))
{
return false;
}
if (IsMemberAccessADynamicInvocation(memberAccess, semanticModel))
{
return false;
}
if (memberAccess.AccessMethodWithDynamicArgumentInsideStructConstructor(semanticModel))
{
return false;
}
if (memberAccess.Expression.Kind() == SyntaxKind.BaseExpression)
{
var enclosingNamedType = semanticModel.GetEnclosingNamedType(memberAccess.SpanStart, cancellationToken);
var symbol = semanticModel.GetSymbolInfo(memberAccess.Name, cancellationToken).Symbol;
if (enclosingNamedType != null &&
!enclosingNamedType.IsSealed &&
symbol != null &&
symbol.IsOverridable())
{
return false;
}
}
var invalidTransformation1 = ParserWouldTreatExpressionAsCast(reducedName, memberAccess);
return !invalidTransformation1;
}