本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax类的典型用法代码示例。如果您正苦于以下问题:C# AccessorDeclarationSyntax类的具体用法?C# AccessorDeclarationSyntax怎么用?C# AccessorDeclarationSyntax使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessorDeclarationSyntax类属于Microsoft.CodeAnalysis.CSharp.Syntax命名空间,在下文中一共展示了AccessorDeclarationSyntax类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:riversky,项目名称:roslyn,代码行数:8,代码来源:LookupPosition.cs
示例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);
}
开发者ID:jjrdk,项目名称:ArchiMetrics,代码行数:12,代码来源:LinesOfCodeCalculator.cs
示例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;
}
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:9,代码来源:AutoPropertyRewriter.cs
示例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);
}
开发者ID:jeroenheijmans,项目名称:elasticsearch-net,代码行数:10,代码来源:DocumentationFileWalker.cs
示例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;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:15,代码来源:ExpansionChecker.cs
示例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;
}
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:13,代码来源:ValueParameterNotUsedAnalyzer.cs
示例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);
}
开发者ID:Drakonoffnet,项目名称:Blackmire,代码行数:14,代码来源:CppHeaderWalker.cs
示例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);
}
开发者ID:riversky,项目名称:roslyn,代码行数:47,代码来源:SourcePropertyAccessorSymbol.cs
示例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;
}
开发者ID:pgrefviau,项目名称:RefactoringEssentials,代码行数:22,代码来源:ValueParameterNotUsedAnalyzer.cs
示例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);
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:38,代码来源:SourcePropertyAccessorSymbol.cs
示例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);
}
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:19,代码来源:PropertyToAutoProperty.cs
示例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);
}
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:28,代码来源:PropertyToAutoProperty.cs
示例14: GetModifierKinds
private static IEnumerable<SyntaxKind> GetModifierKinds(AccessorDeclarationSyntax accessor)
{
return accessor.Modifiers.Select(m => m.Kind());
}
开发者ID:duncanpMS,项目名称:sonarlint-vs,代码行数:4,代码来源:PropertyToAutoProperty.cs
示例15: IsMultiline
private static bool IsMultiline(AccessorDeclarationSyntax accessorDeclaration)
{
var lineSpan = accessorDeclaration.GetLineSpan();
return lineSpan.StartLinePosition.Line != lineSpan.EndLinePosition.Line;
}
开发者ID:EdwinEngelen,项目名称:StyleCopAnalyzers,代码行数:5,代码来源:SA1516ElementsMustBeSeparatedByBlankLine.cs
示例16: MakeModifiers
private DeclarationModifiers MakeModifiers(AccessorDeclarationSyntax syntax, Location location, DiagnosticBag diagnostics, out bool modifierErrors)
{
// No default accessibility. If unset, accessibility
// will be inherited from the property.
const DeclarationModifiers defaultAccess = DeclarationModifiers.None;
// Check that the set of modifiers is allowed
const DeclarationModifiers allowedModifiers = DeclarationModifiers.AccessibilityMask;
var mods = ModifierUtils.MakeAndCheckNontypeMemberModifiers(syntax.Modifiers, defaultAccess, allowedModifiers, location, diagnostics, out modifierErrors);
// For interface, check there are no accessibility modifiers.
// (This check is handled outside of MakeAndCheckModifiers
// since a distinct error message is reported for interfaces.)
if (this.ContainingType.IsInterface)
{
if ((mods & DeclarationModifiers.AccessibilityMask) != 0)
{
diagnostics.Add(ErrorCode.ERR_PropertyAccessModInInterface, location, this);
mods = (mods & ~DeclarationModifiers.AccessibilityMask);
}
}
return mods;
}
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:24,代码来源:SourcePropertyAccessorSymbol.cs
示例17: GetDeclaredSymbol
public override IMethodSymbol GetDeclaredSymbol(AccessorDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
// Can't define accessor inside member.
return null;
}
开发者ID:orthoxerox,项目名称:roslyn,代码行数:5,代码来源:MemberSemanticModel.cs
示例18: ClassifyUpdate
private void ClassifyUpdate(AccessorDeclarationSyntax oldNode, AccessorDeclarationSyntax newNode)
{
if (!SyntaxFactory.AreEquivalent(oldNode.Modifiers, newNode.Modifiers))
{
ReportError(RudeEditKind.ModifiersUpdate);
return;
}
if (oldNode.Kind() != newNode.Kind())
{
ReportError(RudeEditKind.AccessorKindUpdate);
return;
}
Debug.Assert(newNode.Parent is AccessorListSyntax);
Debug.Assert(newNode.Parent.Parent is BasePropertyDeclarationSyntax);
ClassifyMethodBodyRudeUpdate(
oldNode.Body,
newNode.Body,
containingMethodOpt: null,
containingType: (TypeDeclarationSyntax)newNode.Parent.Parent.Parent);
}
开发者ID:GeertVL,项目名称:roslyn,代码行数:23,代码来源:CSharpEditAndContinueAnalyzer.cs
示例19: VisitAccessorDeclaration
public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
{
VisitBlock(node.Body);
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:4,代码来源:LocalBinderFactory.cs
示例20: GetDeclaredSymbol
/// <summary>
/// Given an syntax node that declares a property or member accessor, get the corresponding symbol.
/// </summary>
/// <param name="declarationSyntax">The syntax node that declares an accessor.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The symbol that was declared.</returns>
public override IMethodSymbol GetDeclaredSymbol(AccessorDeclarationSyntax declarationSyntax, CancellationToken cancellationToken = default(CancellationToken))
{
CheckSyntaxNode(declarationSyntax);
if (declarationSyntax.Kind() == SyntaxKind.UnknownAccessorDeclaration)
{
// this is not a real accessor, so we shouldn't return anything.
return null;
}
var propertyOrEventDecl = declarationSyntax.Parent.Parent;
switch (propertyOrEventDecl.Kind())
{
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.IndexerDeclaration:
case SyntaxKind.EventDeclaration:
case SyntaxKind.EventFieldDeclaration:
// NOTE: it's an error for field-like events to have accessors,
// but we want to bind them anyway for error tolerance reasons.
var container = GetDeclaredTypeMemberContainer(propertyOrEventDecl);
Debug.Assert((object)container != null);
Debug.Assert(declarationSyntax.Keyword.Kind() != SyntaxKind.IdentifierToken);
return this.GetDeclaredMember(container, declarationSyntax.Span) as MethodSymbol;
default:
throw ExceptionUtilities.UnexpectedValue(propertyOrEventDecl.Kind());
}
}
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:35,代码来源:SyntaxTreeSemanticModel.cs
注:本文中的Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论