本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax.GetEffectiveAccessibility方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyDeclarationSyntax.GetEffectiveAccessibility方法的具体用法?C# PropertyDeclarationSyntax.GetEffectiveAccessibility怎么用?C# PropertyDeclarationSyntax.GetEffectiveAccessibility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.PropertyDeclarationSyntax
的用法示例。
在下文中一共展示了PropertyDeclarationSyntax.GetEffectiveAccessibility方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeSummaryElement
private static void AnalyzeSummaryElement(SyntaxNodeAnalysisContext context, XmlNodeSyntax syntax, Location diagnosticLocation, PropertyDeclarationSyntax propertyDeclaration, string startingTextGets, string startingTextSets, string startingTextGetsOrSets)
{
var diagnosticProperties = ImmutableDictionary.CreateBuilder<string, string>();
ArrowExpressionClauseSyntax expressionBody = propertyDeclaration.ExpressionBody;
AccessorDeclarationSyntax getter = null;
AccessorDeclarationSyntax setter = null;
if (propertyDeclaration.AccessorList != null)
{
foreach (var accessor in propertyDeclaration.AccessorList.Accessors)
{
switch (accessor.Keyword.Kind())
{
case SyntaxKind.GetKeyword:
getter = accessor;
break;
case SyntaxKind.SetKeyword:
setter = accessor;
break;
}
}
}
XmlElementSyntax summaryElement = (XmlElementSyntax)syntax;
if (summaryElement == null)
{
// This is reported by SA1604.
return;
}
// Add a no code fix tag when the summary element is empty.
// This will only impact SA1623, because SA1624 cannot trigger with an empty summary.
if (summaryElement.Content.Count == 0)
{
diagnosticProperties.Add(NoCodeFixKey, string.Empty);
}
var textElement = summaryElement.Content.FirstOrDefault() as XmlTextSyntax;
var text = textElement == null ? string.Empty : XmlCommentHelper.GetText(textElement, true).TrimStart();
if (getter != null || expressionBody != null)
{
bool startsWithGetOrSet = text.StartsWith(startingTextGetsOrSets, StringComparison.Ordinal);
if (setter != null)
{
// There is no way getter is null (can't have expression body and accessor list)
bool getterVisible;
bool setterVisible;
if (!getter.Modifiers.Any() && !setter.Modifiers.Any())
{
// Case 1: The getter and setter have the same declared accessibility
getterVisible = true;
setterVisible = true;
}
else if (getter.Modifiers.Any(SyntaxKind.PrivateKeyword))
{
// Case 3
getterVisible = false;
setterVisible = true;
}
else if (setter.Modifiers.Any(SyntaxKind.PrivateKeyword))
{
// Case 3
getterVisible = true;
setterVisible = false;
}
else
{
var propertyAccessibility = propertyDeclaration.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
bool propertyOnlyInternal = propertyAccessibility == Accessibility.Internal
|| propertyAccessibility == Accessibility.ProtectedAndInternal
|| propertyAccessibility == Accessibility.Private;
if (propertyOnlyInternal)
{
// Case 2: Property only internal and no accessor is explicitly private
getterVisible = true;
setterVisible = true;
}
else
{
var getterAccessibility = getter.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
var setterAccessibility = setter.GetEffectiveAccessibility(context.SemanticModel, context.CancellationToken);
switch (getterAccessibility)
{
case Accessibility.Public:
case Accessibility.ProtectedOrInternal:
case Accessibility.Protected:
// Case 4
getterVisible = true;
break;
case Accessibility.Internal:
case Accessibility.ProtectedAndInternal:
case Accessibility.Private:
default:
// The property is externally accessible, so the setter must be more accessible.
//.........这里部分代码省略.........