本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# AccessorDeclarationSyntax类的具体用法?C# AccessorDeclarationSyntax怎么用?C# AccessorDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessorDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了AccessorDeclarationSyntax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsInMethodDeclaration
internal static bool IsInMethodDeclaration(int position, AccessorDeclarationSyntax accessorDecl)
{
Debug.Assert(accessorDecl != null);
var body = accessorDecl.Body;
SyntaxToken lastToken = body == null ? accessorDecl.SemicolonToken : body.CloseBraceToken;
return IsBeforeToken(position, accessorDecl, lastToken);
}
示例2: VisitAccessorDeclaration
/// <summary>
/// Called when the visitor visits a AccessorDeclarationSyntax node.
/// </summary>
public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
{
if (node.Body == null)
{
_counter++;
}
base.VisitAccessorDeclaration(node);
}
示例3: GetBackingFieldFromGetter
private IFieldSymbol GetBackingFieldFromGetter(AccessorDeclarationSyntax getter)
{
if (getter.Body?.Statements.Count != 1) return null;
var statement = getter.Body.Statements.Single() as ReturnStatementSyntax;
if (statement?.Expression == null) return null;
return _semanticModel.GetSymbolInfo(statement.Expression).Symbol as IFieldSymbol;
}
示例4: GetActions
protected IEnumerable<CodeAction> GetActions(Document document, SyntaxNode root, MethodDeclarationSyntax methodNode, AccessorDeclarationSyntax getterNode)
{
if (methodNode != null)
return GetActions(document, root, methodNode);
if (getterNode != null)
return GetActions(document, root, getterNode);
return Enumerable.Empty<CodeAction>();
}
开发者ID:alecor191,项目名称:RefactoringEssentials,代码行数:10,代码来源:ContractEnsuresNotNullReturnRefactoringProvider.cs
示例5: VisitAccessorDeclaration
public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
{
if (!this.InsideFluentOrInitializerExample) return;
var syntaxNode = node?.ChildNodes()?.LastOrDefault()?.WithAdditionalAnnotations() as BlockSyntax;
if (syntaxNode == null) return;
var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line;
var walker = new CodeWithDocumentationWalker(ClassDepth, line);
walker.VisitBlock(syntaxNode);
this.Blocks.AddRange(walker.Blocks);
}
示例6: TryGetAccessors
/// <summary>
/// Retrieves the get and set accessor declarations of the specified property.
/// Returns true if both get and set accessors exist; otherwise false.
/// </summary>
internal static bool TryGetAccessors(
PropertyDeclarationSyntax property,
out AccessorDeclarationSyntax getter,
out AccessorDeclarationSyntax setter)
{
var accessors = property.AccessorList.Accessors;
getter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.GetAccessorDeclaration);
setter = accessors.FirstOrDefault(ad => ad.Kind() == SyntaxKind.SetAccessorDeclaration);
return accessors.Count == 2 && getter != null && setter != null;
}
示例7: GetMessageArgument
static string GetMessageArgument(AccessorDeclarationSyntax node)
{
switch (node.Kind())
{
case SyntaxKind.SetAccessorDeclaration:
return GettextCatalog.GetString("setter");
case SyntaxKind.AddAccessorDeclaration:
return GettextCatalog.GetString("add accessor");
case SyntaxKind.RemoveAccessorDeclaration:
return GettextCatalog.GetString("remove accessor");
}
return null;
}
示例8: VisitAccessorDeclaration
public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
{
if (node.Body != null && node.Parent is BasePropertyDeclarationSyntax)
{
var z = model.GetDeclaredSymbol(node.Parent as PropertyDeclarationSyntax);
cb.AppendWithIndent(z.Type.ToCppType())
.Append(" ")
.Append(settings.GetPrefix)
.Append(z.Name)
.AppendLine("() const");
}
base.VisitAccessorDeclaration(node);
}
示例9: CreateAccessorSymbol
public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
NamedTypeSymbol containingType,
SourcePropertySymbol property,
DeclarationModifiers propertyModifiers,
string propertyName,
AccessorDeclarationSyntax syntax,
PropertySymbol explicitlyImplementedPropertyOpt,
string aliasQualifierOpt,
bool isAutoPropertyAccessor,
DiagnosticBag diagnostics)
{
Debug.Assert(syntax.Kind == SyntaxKind.GetAccessorDeclaration || syntax.Kind == SyntaxKind.SetAccessorDeclaration);
bool isGetMethod = (syntax.Kind == SyntaxKind.GetAccessorDeclaration);
bool isWinMd = property.IsCompilationOutputWinMdObj();
string name;
ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
if ((object)explicitlyImplementedPropertyOpt == null)
{
name = GetAccessorName(propertyName, isGetMethod, isWinMd);
explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
}
else
{
MethodSymbol implementedAccessor = isGetMethod ? explicitlyImplementedPropertyOpt.GetMethod : explicitlyImplementedPropertyOpt.SetMethod;
string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name
: GetAccessorName(explicitlyImplementedPropertyOpt.MetadataName, isGetMethod, isWinMd); //Not name - could be indexer placeholder
name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedPropertyOpt.ContainingType, aliasQualifierOpt);
explicitInterfaceImplementations =
(object)implementedAccessor == null ?
ImmutableArray<MethodSymbol>.Empty :
ImmutableArray.Create<MethodSymbol>(implementedAccessor);
}
var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
return new SourcePropertyAccessorSymbol(
containingType,
name,
property,
propertyModifiers,
explicitInterfaceImplementations,
syntax.Keyword.GetLocation(),
syntax,
methodKind,
isAutoPropertyAccessor,
diagnostics);
}
示例10: FindIssuesInAccessor
static bool FindIssuesInAccessor(SemanticModel semanticModel, AccessorDeclarationSyntax accessor)
{
var body = accessor.Body;
if (!IsEligible(body))
return false;
if (body.Statements.Any())
{
var foundValueSymbol = semanticModel.LookupSymbols(body.Statements.First().SpanStart, null, "value").FirstOrDefault();
if (foundValueSymbol == null)
return false;
foreach (var valueRef in body.DescendantNodes().OfType<IdentifierNameSyntax>().Where(ins => ins.Identifier.ValueText == "value"))
{
var valueRefSymbol = semanticModel.GetSymbolInfo(valueRef).Symbol;
if (foundValueSymbol.Equals(valueRefSymbol))
return false;
}
}
return true;
}
示例11: CreateAccessorSymbol
public static SourcePropertyAccessorSymbol CreateAccessorSymbol(
NamedTypeSymbol containingType,
SourcePropertySymbol property,
DeclarationModifiers propertyModifiers,
string propertyName,
AccessorDeclarationSyntax syntax,
PropertySymbol explicitlyImplementedPropertyOpt,
string aliasQualifierOpt,
bool isAutoPropertyAccessor,
DiagnosticBag diagnostics)
{
Debug.Assert(syntax.Kind() == SyntaxKind.GetAccessorDeclaration || syntax.Kind() == SyntaxKind.SetAccessorDeclaration);
bool isGetMethod = (syntax.Kind() == SyntaxKind.GetAccessorDeclaration);
string name;
ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
GetNameAndExplicitInterfaceImplementations(
explicitlyImplementedPropertyOpt,
propertyName,
property.IsCompilationOutputWinMdObj(),
aliasQualifierOpt,
isGetMethod,
out name,
out explicitInterfaceImplementations);
var methodKind = isGetMethod ? MethodKind.PropertyGet : MethodKind.PropertySet;
return new SourcePropertyAccessorSymbol(
containingType,
name,
property,
propertyModifiers,
explicitInterfaceImplementations,
syntax.Keyword.GetLocation(),
syntax,
methodKind,
isAutoPropertyAccessor,
diagnostics);
}
示例12: TryGetFieldFromGetter
private static bool TryGetFieldFromGetter(AccessorDeclarationSyntax getter, SemanticModel semanticModel, out IFieldSymbol getterField)
{
getterField = null;
if (getter.Body == null ||
getter.Body.Statements.Count != 1)
{
return false;
}
var statement = getter.Body.Statements[0] as ReturnStatementSyntax;
if (statement == null ||
statement.Expression == null)
{
return false;
}
return TryGetField(statement.Expression, semanticModel.GetDeclaredSymbol(getter).ContainingType,
semanticModel, out getterField);
}
示例13: TryGetFieldFromSetter
private static bool TryGetFieldFromSetter(AccessorDeclarationSyntax setter, SemanticModel semanticModel, out IFieldSymbol setterField)
{
setterField = null;
if (setter.Body == null ||
setter.Body.Statements.Count != 1)
{
return false;
}
var statement = setter.Body.Statements[0] as ExpressionStatementSyntax;
var assignment = statement?.Expression as AssignmentExpressionSyntax;
if (assignment == null ||
!assignment.IsKind(SyntaxKind.SimpleAssignmentExpression))
{
return false;
}
var parameter = semanticModel.GetSymbolInfo(assignment.Right).Symbol as IParameterSymbol;
if (parameter == null ||
parameter.Name != "value" ||
!parameter.IsImplicitlyDeclared)
{
return false;
}
return TryGetField(assignment.Left, semanticModel.GetDeclaredSymbol(setter).ContainingType,
semanticModel, out setterField);
}
示例14: GetModifierKinds
private static IEnumerable<SyntaxKind> GetModifierKinds(AccessorDeclarationSyntax accessor)
{
return accessor.Modifiers.Select(m => m.Kind());
}
示例15: IsMultiline
private static bool IsMultiline(AccessorDeclarationSyntax accessorDeclaration)
{
var lineSpan = accessorDeclaration.GetLineSpan();
return lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line;
}