本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax.Kind方法的典型用法代码示例。如果您正苦于以下问题:C# AccessorDeclarationSyntax.Kind方法的具体用法?C# AccessorDeclarationSyntax.Kind怎么用?C# AccessorDeclarationSyntax.Kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.AccessorDeclarationSyntax
的用法示例。
在下文中一共展示了AccessorDeclarationSyntax.Kind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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);
}
示例4: 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());
}
}
示例5: VisitAccessorDeclaration
/// <summary>
/// Normalizes the <paramref name="accessor" />.
/// </summary>
public override SyntaxNode VisitAccessorDeclaration(AccessorDeclarationSyntax accessor)
{
var originalAccessor = accessor;
var methodSymbol = accessor.GetMethodSymbol(SemanticModel);
if (!methodSymbol.ContainingType.IsFaultEffect(SemanticModel) || !methodSymbol.IsOverride)
return accessor;
SyntaxNode baseExpression;
if (((IPropertySymbol)methodSymbol.AssociatedSymbol).IsIndexer)
{
var parameterCount = methodSymbol.Parameters.Length - (accessor.Kind() != SyntaxKind.GetAccessorDeclaration ? 1 : 0);
var parameters = methodSymbol.Parameters.Take(parameterCount);
baseExpression = Syntax.ElementAccessExpression(Syntax.BaseExpression(), CreateInvocationArguments(parameters));
}
else
baseExpression = Syntax.MemberAccessExpression(Syntax.BaseExpression(), methodSymbol.GetPropertySymbol().Name);
if (accessor.Kind() != SyntaxKind.GetAccessorDeclaration)
baseExpression = Syntax.AssignmentStatement(baseExpression, Syntax.IdentifierName("value"));
accessor = accessor.WithBody(CreateBody(methodSymbol, accessor.Body, baseExpression));
return accessor.EnsureLineCount(originalAccessor);
}
示例6: SourceCustomEventAccessorSymbol
internal SourceCustomEventAccessorSymbol(
SourceEventSymbol @event,
AccessorDeclarationSyntax syntax,
EventSymbol explicitlyImplementedEventOpt,
string aliasQualifierOpt,
DiagnosticBag diagnostics)
: base(@event,
syntax.GetReference(),
syntax.Body?.GetReference(),
ImmutableArray.Create(syntax.Keyword.GetLocation()))
{
Debug.Assert(syntax != null);
Debug.Assert(syntax.Kind() == SyntaxKind.AddAccessorDeclaration || syntax.Kind() == SyntaxKind.RemoveAccessorDeclaration);
bool isAdder = syntax.Kind() == SyntaxKind.AddAccessorDeclaration;
string name;
ImmutableArray<MethodSymbol> explicitInterfaceImplementations;
if ((object)explicitlyImplementedEventOpt == null)
{
name = SourceEventSymbol.GetAccessorName(@event.Name, isAdder);
explicitInterfaceImplementations = ImmutableArray<MethodSymbol>.Empty;
}
else
{
MethodSymbol implementedAccessor = isAdder ? explicitlyImplementedEventOpt.AddMethod : explicitlyImplementedEventOpt.RemoveMethod;
string accessorName = (object)implementedAccessor != null ? implementedAccessor.Name : SourceEventSymbol.GetAccessorName(explicitlyImplementedEventOpt.Name, isAdder);
name = ExplicitInterfaceHelpers.GetMemberName(accessorName, explicitlyImplementedEventOpt.ContainingType, aliasQualifierOpt);
explicitInterfaceImplementations = (object)implementedAccessor == null ? ImmutableArray<MethodSymbol>.Empty : ImmutableArray.Create<MethodSymbol>(implementedAccessor);
}
_explicitInterfaceImplementations = explicitInterfaceImplementations;
_name = name;
this.MakeFlags(
isAdder ? MethodKind.EventAdd : MethodKind.EventRemove,
@event.Modifiers,
returnsVoid: false, // until we learn otherwise (in LazyMethodChecks).
isExtensionMethod: false,
isMetadataVirtualIgnoringModifiers: explicitInterfaceImplementations.Any());
if (@event.ContainingType.IsInterface)
{
diagnostics.Add(ErrorCode.ERR_EventPropertyInInterface, this.Location);
}
else
{
var bodyOpt = syntax.Body;
if (bodyOpt != null)
{
if (IsExtern && !IsAbstract)
{
diagnostics.Add(ErrorCode.ERR_ExternHasBody, this.Location, this);
}
else if (IsAbstract && !IsExtern)
{
diagnostics.Add(ErrorCode.ERR_AbstractHasBody, this.Location, this);
}
// Do not report error for IsAbstract && IsExtern. Dev10 reports CS0180 only
// in that case ("member cannot be both extern and abstract").
}
}
_name = GetOverriddenAccessorName(@event, isAdder) ?? _name;
}
示例7: 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))
{
using (Logger.LogBlock(FunctionId.CSharp_SemanticModel_GetDeclaredSymbol, message: this.SyntaxTree.FilePath, cancellationToken: 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:
Debug.Assert(false, "Accessor unexpectedly attached to " + propertyOrEventDecl.Kind());
return null;
}
}
}
示例8: VisitAccessorDeclaration
public override SyntaxNode VisitAccessorDeclaration(AccessorDeclarationSyntax node)
{
var propName = node.FirstAncestorOrSelf<PropertyDeclarationSyntax>().Identifier.Text;
var fieldName = "_" + propName;
BlockSyntax body;
if (node.IsKind(SyntaxKind.GetAccessorDeclaration))
{
body = SyntaxFactory.Block(SyntaxFactory.ReturnStatement(SyntaxFactory.IdentifierName(fieldName)).NormalizeWhitespace());
}
else
{
var setField = SyntaxFactory.ExpressionStatement(
SyntaxFactory.AssignmentExpression(
SyntaxKind.SimpleAssignmentExpression, SyntaxFactory.IdentifierName(fieldName), SyntaxFactory.IdentifierName(@"value")));
var raiseEvent = SyntaxFactory.ExpressionStatement(
SyntaxFactory.InvocationExpression(
SyntaxFactory.IdentifierName("OnPropertyChanged"),
SyntaxFactory.ArgumentList(
SyntaxFactory.SingletonSeparatedList(
SyntaxFactory.Argument(
SyntaxFactory.LiteralExpression(
SyntaxKind.StringLiteralExpression,
SyntaxFactory.Literal(propName)))))));
body = SyntaxFactory.Block(SyntaxFactory.SeparatedList<StatementSyntax>(new StatementSyntax[] { setField, raiseEvent }));
}
var newDecl = SyntaxFactory.AccessorDeclaration(node.Kind(), body);
return newDecl;
}