public static MethodDeclarationSyntax MethodDeclaration( SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, SyntaxToken semicolonToken) { return SyntaxFactory.MethodDeclaration( attributeLists, modifiers, default(SyntaxToken), returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, default(ArrowExpressionClauseSyntax), semicolonToken); }
public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken) { return PropertyDeclaration( attributeLists, modifiers, refKeyword: default(SyntaxToken), type: type, explicitInterfaceSpecifier: explicitInterfaceSpecifier, identifier: identifier, accessorList: accessorList, expressionBody: expressionBody, initializer: initializer, semicolonToken: semicolonToken); }
public static IndexerDeclarationSyntax IndexerDeclaration( SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList) { return SyntaxFactory.IndexerDeclaration( attributeLists: attributeLists, modifiers: modifiers, type: type, explicitInterfaceSpecifier: explicitInterfaceSpecifier, parameterList: parameterList, accessorList: accessorList, expressionBody: default(ArrowExpressionClauseSyntax)); }
// TODO: CLSCompliantAttribute internal SourceEventSymbol( SourceMemberContainerTypeSymbol containingType, CSharpSyntaxNode syntax, SyntaxTokenList modifiers, ExplicitInterfaceSpecifierSyntax interfaceSpecifierSyntaxOpt, SyntaxToken nameTokenSyntax, DiagnosticBag diagnostics) { _location = nameTokenSyntax.GetLocation(); this.containingType = containingType; _syntaxRef = syntax.GetReference(); var isExplicitInterfaceImplementation = interfaceSpecifierSyntaxOpt != null; bool modifierErrors; _modifiers = MakeModifiers(modifiers, isExplicitInterfaceImplementation, _location, diagnostics, out modifierErrors); this.CheckAccessibility(_location, diagnostics); }
public static IndexerDeclarationSyntax Update( this IndexerDeclarationSyntax syntax, SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList ) { return(syntax.Update( attributeLists, modifiers, type, explicitInterfaceSpecifier, thisKeyword, parameterList, accessorList, expressionBody: null, semicolonToken: default )); }
public static IndexerDeclarationSyntax IndexerDeclaration( SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return SyntaxFactory.IndexerDeclaration( attributeLists: attributeLists, modifiers: modifiers, refKeyword: default(SyntaxToken), type: type, explicitInterfaceSpecifier: explicitInterfaceSpecifier, thisKeyword: thisKeyword, parameterList: parameterList, accessorList: accessorList, expressionBody: expressionBody, semicolonToken: semicolonToken); }
public static IndexerDeclarationSyntax Update( this IndexerDeclarationSyntax syntax, SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken refKeyword, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList) { return(syntax.Update( attributeLists, modifiers, refKeyword, type, explicitInterfaceSpecifier, thisKeyword, parameterList, accessorList, default(ArrowExpressionClauseSyntax), default(SyntaxToken))); }
public override SyntaxNode VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { node = (ExplicitInterfaceSpecifierSyntax)base.VisitExplicitInterfaceSpecifier(node); Classes.Add(node); return(node); }
public static MethodDeclarationSyntax Update( this MethodDeclarationSyntax syntax, SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken refKeyword, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax block, SyntaxToken semicolonToken) { return syntax.Update( attributeLists, modifiers, refKeyword, returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, block, default(ArrowExpressionClauseSyntax), semicolonToken); }
// 显示接口指定 public virtual void VisitExplicitInterfaceSpecifierSyntax(ExplicitInterfaceSpecifierSyntax value) { DefaultVisit(value); }
public TameExplicitInterfaceSpecifierSyntax(ExplicitInterfaceSpecifierSyntax node) { Node = node; AddChildren(); }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { node.Name?.Accept(this); base.VisitExplicitInterfaceSpecifier(node); }
public static BasePropertyDeclarationSyntax WithExplicitInterfaceSpecifier(this BasePropertyDeclarationSyntax node, ExplicitInterfaceSpecifierSyntax syntax) { switch (node.Kind()) { case SyntaxKind.IndexerDeclaration: return ((IndexerDeclarationSyntax)node).WithExplicitInterfaceSpecifier(syntax); case SyntaxKind.PropertyDeclaration: return (((PropertyDeclarationSyntax)node)).WithExplicitInterfaceSpecifier(syntax); } throw new NotImplementedException("WithExplicitInterfaceSpecifier " + node.Kind().ToString()); }
// // Summary: // Called when the visitor visits a ExplicitInterfaceSpecifierSyntax node. public virtual void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node);
public static MethodDeclarationSyntax MethodDeclaration(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return(SyntaxFactory.MethodDeclaration( attributeLists, modifiers, default(SyntaxToken), returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken)); }
public MethodDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return(Update(attributeLists, modifiers, this.RefKeyword, returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken)); }
public IndexerDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return Update(attributeLists, modifiers, this.RefKeyword, type, explicitInterfaceSpecifier, thisKeyword, parameterList, accessorList, expressionBody, semicolonToken); }
internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, Binder binder, EventDeclarationSyntax syntax, DiagnosticBag diagnostics) : base(containingType, syntax, syntax.Modifiers, isFieldLike: false, interfaceSpecifierSyntaxOpt: syntax.ExplicitInterfaceSpecifier, nameTokenSyntax: syntax.Identifier, diagnostics: diagnostics) { ExplicitInterfaceSpecifierSyntax interfaceSpecifier = syntax.ExplicitInterfaceSpecifier; SyntaxToken nameToken = syntax.Identifier; bool isExplicitInterfaceImplementation = interfaceSpecifier != null; string aliasQualifierOpt; _name = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(binder, interfaceSpecifier, nameToken.ValueText, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt); _type = BindEventType(binder, syntax.Type, diagnostics); var explicitlyImplementedEvent = this.FindExplicitlyImplementedEvent(_explicitInterfaceType, nameToken.ValueText, interfaceSpecifier, diagnostics); this.FindExplicitlyImplementedMemberVerification(explicitlyImplementedEvent, diagnostics); // The runtime will not treat the accessors of this event as overrides or implementations // of those of another event unless both the signatures and the custom modifiers match. // Hence, in the case of overrides and *explicit* implementations, we need to copy the custom // modifiers that are in the signatures of the overridden/implemented event accessors. // (From source, we know that there can only be one overridden/implemented event, so there // are no conflicts.) This is unnecessary for implicit implementations because, if the custom // modifiers don't match, we'll insert bridge methods for the accessors (explicit implementations // that delegate to the implicit implementations) with the correct custom modifiers // (see SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation). // Note: we're checking if the syntax indicates explicit implementation rather, // than if explicitInterfaceType is null because we don't want to look for an // overridden event if this is supposed to be an explicit implementation. if (!isExplicitInterfaceImplementation) { // If this event is an override, we may need to copy custom modifiers from // the overridden event (so that the runtime will recognize it as an override). // We check for this case here, while we can still modify the parameters and // return type without losing the appearance of immutability. if (this.IsOverride) { EventSymbol overriddenEvent = this.OverriddenEvent; if ((object)overriddenEvent != null) { CopyEventCustomModifiers(overriddenEvent, ref _type, ContainingAssembly); } } } else if ((object)explicitlyImplementedEvent != null) { CopyEventCustomModifiers(explicitlyImplementedEvent, ref _type, ContainingAssembly); } AccessorDeclarationSyntax addSyntax = null; AccessorDeclarationSyntax removeSyntax = null; if (syntax.AccessorList != null) { foreach (AccessorDeclarationSyntax accessor in syntax.AccessorList.Accessors) { bool checkBody = false; switch (accessor.Kind()) { case SyntaxKind.AddAccessorDeclaration: if (addSyntax == null) { addSyntax = accessor; checkBody = true; } else { diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation()); } break; case SyntaxKind.RemoveAccessorDeclaration: if (removeSyntax == null) { removeSyntax = accessor; checkBody = true; } else { diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation()); } break; case SyntaxKind.GetAccessorDeclaration: case SyntaxKind.SetAccessorDeclaration: diagnostics.Add(ErrorCode.ERR_AddOrRemoveExpected, accessor.Keyword.GetLocation()); break; case SyntaxKind.UnknownAccessorDeclaration: // Don't need to handle UnknownAccessorDeclaration. An error will have // already been produced for it in the parser. break; default: throw ExceptionUtilities.UnexpectedValue(accessor.Kind()); } if (checkBody && !IsAbstract && accessor.Body == null && accessor.ExpressionBody == null && accessor.SemicolonToken.Kind() == SyntaxKind.SemicolonToken) { diagnostics.Add(ErrorCode.ERR_AddRemoveMustHaveBody, accessor.SemicolonToken.GetLocation()); } } if (IsAbstract) { if (!syntax.AccessorList.OpenBraceToken.IsMissing) { diagnostics.Add(ErrorCode.ERR_AbstractEventHasAccessors, syntax.AccessorList.OpenBraceToken.GetLocation(), this); } } else if ((addSyntax == null || removeSyntax == null) && (!syntax.AccessorList.OpenBraceToken.IsMissing || !isExplicitInterfaceImplementation)) { diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this); } } else if (isExplicitInterfaceImplementation && !IsAbstract) { diagnostics.Add(ErrorCode.ERR_ExplicitEventFieldImpl, this.Locations[0]); } if (isExplicitInterfaceImplementation && IsAbstract && syntax.AccessorList == null) { Debug.Assert(containingType.IsInterface); Binder.CheckFeatureAvailability(syntax, MessageID.IDS_DefaultInterfaceImplementation, diagnostics, this.Locations[0]); if (!ContainingAssembly.RuntimeSupportsDefaultInterfaceImplementation) { diagnostics.Add(ErrorCode.ERR_RuntimeDoesNotSupportDefaultInterfaceImplementation, this.Locations[0]); } _addMethod = new SynthesizedEventAccessorSymbol(this, isAdder: true, explicitlyImplementedEvent, aliasQualifierOpt); _removeMethod = new SynthesizedEventAccessorSymbol(this, isAdder: false, explicitlyImplementedEvent, aliasQualifierOpt); } else { _addMethod = CreateAccessorSymbol(addSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics); _removeMethod = CreateAccessorSymbol(removeSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics); } _explicitInterfaceImplementations = (object)explicitlyImplementedEvent == null ? ImmutableArray <EventSymbol> .Empty : ImmutableArray.Create <EventSymbol>(explicitlyImplementedEvent); }
public void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { if (node == null) throw new ArgumentNullException("node"); node.Validate(); node.Name.Accept(this); _writer.WriteSyntax(Syntax.Dot); }
private static string ExpandExplicitInterfaceName(string identifier, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier) { if (explicitInterfaceSpecifier == null) { return identifier; } else { var builder = new StringBuilder(); ExpandTypeName(explicitInterfaceSpecifier.Name, builder); builder.Append('.'); builder.Append(identifier); return builder.ToString(); } }
public override Evaluation VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { node.Name?.Accept <Evaluation>(this); return(base.VisitExplicitInterfaceSpecifier(node)); }
public override string GetSyntaxContent(MemberType typeKind, ISymbol symbol, SyntaxNode syntaxNode) { string syntaxStr = null; switch (typeKind) { case MemberType.Class: { var typeSymbol = (INamedTypeSymbol)symbol; syntaxStr = SyntaxFactory.ClassDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)), SyntaxFactory.Identifier(typeSymbol.Name), GetTypeParameters(typeSymbol), GetBaseTypeList(typeSymbol), SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)), new SyntaxList <MemberDeclarationSyntax>()) .NormalizeWhitespace() .ToString(); syntaxStr = RemoveBraces(syntaxStr); break; } case MemberType.Enum: { var typeSymbol = (INamedTypeSymbol)symbol; syntaxStr = SyntaxFactory.EnumDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)), SyntaxFactory.Identifier(typeSymbol.Name), GetEnumBaseTypeList(typeSymbol), new SeparatedSyntaxList <EnumMemberDeclarationSyntax>()) .NormalizeWhitespace() .ToString(); syntaxStr = RemoveBraces(syntaxStr); break; } case MemberType.Interface: { var typeSymbol = (INamedTypeSymbol)symbol; syntaxStr = SyntaxFactory.InterfaceDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)), SyntaxFactory.Identifier(typeSymbol.Name), GetTypeParameters(typeSymbol), GetBaseTypeList(typeSymbol), SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)), new SyntaxList <MemberDeclarationSyntax>()) .NormalizeWhitespace() .ToString(); syntaxStr = RemoveBraces(syntaxStr); break; } case MemberType.Struct: { var typeSymbol = (INamedTypeSymbol)symbol; syntaxStr = SyntaxFactory.StructDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)), SyntaxFactory.Identifier(typeSymbol.Name), GetTypeParameters(typeSymbol), GetBaseTypeList(typeSymbol), SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol)), new SyntaxList <MemberDeclarationSyntax>()) .NormalizeWhitespace() .ToString(); syntaxStr = RemoveBraces(syntaxStr); break; } case MemberType.Delegate: { var typeSymbol = (INamedTypeSymbol)symbol; syntaxStr = SyntaxFactory.DelegateDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetTypeModifiers(typeSymbol)), GetTypeSyntax(typeSymbol.DelegateInvokeMethod.ReturnType), SyntaxFactory.Identifier(typeSymbol.Name), GetTypeParameters(typeSymbol), SyntaxFactory.ParameterList( SyntaxFactory.SeparatedList( from p in typeSymbol.DelegateInvokeMethod.Parameters select GetParameter(p))), SyntaxFactory.List(GetTypeParameterConstraints(typeSymbol))) .NormalizeWhitespace() .ToString(); break; } case MemberType.Method: { var methodSymbol = (IMethodSymbol)symbol; ExplicitInterfaceSpecifierSyntax eii = null; if (methodSymbol.ExplicitInterfaceImplementations.Length > 0) { eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(methodSymbol))); } syntaxStr = SyntaxFactory.MethodDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)), GetTypeSyntax(methodSymbol.ReturnType), eii, SyntaxFactory.Identifier(GetMemberName(methodSymbol)), GetTypeParameters(methodSymbol), SyntaxFactory.ParameterList( SyntaxFactory.SeparatedList( from p in methodSymbol.Parameters select GetParameter(p))), SyntaxFactory.List(GetTypeParameterConstraints(methodSymbol)), null, null) .NormalizeWhitespace() .ToString(); break; } case MemberType.Operator: { var methodSymbol = (IMethodSymbol)symbol; var operatorToken = GetOperatorToken(methodSymbol); if (operatorToken == null) { syntaxStr = "Not supported in c#"; } else if (operatorToken.Value.Kind() == SyntaxKind.ImplicitKeyword || operatorToken.Value.Kind() == SyntaxKind.ExplicitKeyword) { syntaxStr = SyntaxFactory.ConversionOperatorDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)), operatorToken.Value, GetTypeSyntax(methodSymbol.ReturnType), SyntaxFactory.ParameterList( SyntaxFactory.SeparatedList( from p in methodSymbol.Parameters select GetParameter(p))), null, null) .NormalizeWhitespace() .ToString(); } else { syntaxStr = SyntaxFactory.OperatorDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)), GetTypeSyntax(methodSymbol.ReturnType), operatorToken.Value, SyntaxFactory.ParameterList( SyntaxFactory.SeparatedList( from p in methodSymbol.Parameters select GetParameter(p))), null, null) .NormalizeWhitespace() .ToString(); } break; } case MemberType.Constructor: { var methodSymbol = (IMethodSymbol)symbol; syntaxStr = SyntaxFactory.ConstructorDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(methodSymbol)), SyntaxFactory.Identifier(methodSymbol.ContainingType.Name), SyntaxFactory.ParameterList( SyntaxFactory.SeparatedList( from p in methodSymbol.Parameters select GetParameter(p))), null, null) .NormalizeWhitespace() .ToString(); break; }; case MemberType.Field: { var fieldSymbol = (IFieldSymbol)symbol; syntaxStr = SyntaxFactory.FieldDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(fieldSymbol)), SyntaxFactory.VariableDeclaration( GetTypeSyntax(fieldSymbol.Type), SyntaxFactory.SingletonSeparatedList( SyntaxFactory.VariableDeclarator( SyntaxFactory.Identifier(fieldSymbol.Name))))) .NormalizeWhitespace() .ToString() .TrimEnd(';'); break; }; case MemberType.Event: { var eventSymbol = (IEventSymbol)symbol; ExplicitInterfaceSpecifierSyntax eii = null; if (eventSymbol.ExplicitInterfaceImplementations.Length > 0) { eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(eventSymbol))); } syntaxStr = SyntaxFactory.EventDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(eventSymbol)), SyntaxFactory.Token(SyntaxKind.EventKeyword), GetTypeSyntax(eventSymbol.Type), eii, SyntaxFactory.Identifier(GetMemberName(eventSymbol)), SyntaxFactory.AccessorList()) .NormalizeWhitespace() .ToString(); syntaxStr = RemoveBraces(syntaxStr); break; }; case MemberType.Property: { Debug.Assert(syntaxNode is PropertyDeclarationSyntax || syntaxNode is IndexerDeclarationSyntax); var propertySymbol = (IPropertySymbol)symbol; ExplicitInterfaceSpecifierSyntax eii = null; if (propertySymbol.ExplicitInterfaceImplementations.Length > 0) { eii = SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.ParseName(GetEiiContainerTypeName(propertySymbol))); } if (propertySymbol.IsIndexer) { syntaxStr = SyntaxFactory.IndexerDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(propertySymbol)), GetTypeSyntax(propertySymbol.Type), eii, SyntaxFactory.BracketedParameterList( SyntaxFactory.SeparatedList( from p in propertySymbol.Parameters select GetParameter(p))), SyntaxFactory.AccessorList(SyntaxFactory.List(GetPropertyAccessors(propertySymbol)))) .NormalizeWhitespace() .ToString(); } else { syntaxStr = SyntaxFactory.PropertyDeclaration( new SyntaxList <AttributeListSyntax>(), SyntaxFactory.TokenList(GetMemberModifiers(propertySymbol)), GetTypeSyntax(propertySymbol.Type), eii, SyntaxFactory.Identifier(GetMemberName(propertySymbol)), SyntaxFactory.AccessorList(SyntaxFactory.List(GetPropertyAccessors(propertySymbol)))) .NormalizeWhitespace() .ToString(); } break; }; } if (string.IsNullOrEmpty(syntaxStr)) { syntaxStr = syntaxNode.NormalizeWhitespace().ToString().Trim(); } return(syntaxStr); }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { Debug.Fail(node.ToString()); base.VisitExplicitInterfaceSpecifier(node); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { this.OnNodeVisited(node); if (!this.traverseRootOnly) base.VisitExplicitInterfaceSpecifier(node); }
public static BasePropertyDeclarationSyntax WithExplicitInterfaceSpecifier(this BasePropertyDeclarationSyntax node, ExplicitInterfaceSpecifierSyntax syntax) { switch (node.Kind()) { case SyntaxKind.IndexerDeclaration: return(((IndexerDeclarationSyntax)node).WithExplicitInterfaceSpecifier(syntax)); case SyntaxKind.PropertyDeclaration: return((((PropertyDeclarationSyntax)node)).WithExplicitInterfaceSpecifier(syntax)); } throw new NotImplementedException("WithExplicitInterfaceSpecifier " + node.Kind().ToString()); }
public static bool MatchExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax x, ExplicitInterfaceSpecifierSyntax y) { if (x == y) { return(true); } if (x == null || y == null) { return(false); } return(x.Name.GetName() == y.Name.GetName()); }
public PropertyDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken) { return Update(attributeLists, modifiers, this.RefKeyword, type, explicitInterfaceSpecifier, identifier, accessorList, expressionBody, initializer, semicolonToken); }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { Debug.Fail($"{nameof(UnusedMemberWalker)}.{nameof(VisitExplicitInterfaceSpecifier)}"); }
public MethodDeclarationSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax returnType, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, TypeParameterListSyntax typeParameterList, ParameterListSyntax parameterList, SyntaxList<TypeParameterConstraintClauseSyntax> constraintClauses, BlockSyntax body, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return Update(attributeLists, modifiers, this.RefKeyword, returnType, explicitInterfaceSpecifier, identifier, typeParameterList, parameterList, constraintClauses, body, expressionBody, semicolonToken); }
private static void ComputeRefactoring( RefactoringContext context, MemberDeclarationSyntax memberDeclaration, SyntaxTokenList modifiers, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SemanticModel semanticModel) { if (!modifiers.Contains(SyntaxKind.PublicKeyword)) { return; } if (modifiers.Contains(SyntaxKind.StaticKeyword)) { return; } BaseListSyntax baseList = GetBaseList(memberDeclaration.Parent); if (baseList == null) { return; } SeparatedSyntaxList <BaseTypeSyntax> types = baseList.Types; if (!types.Any()) { return; } NameSyntax explicitInterfaceName = explicitInterfaceSpecifier?.Name; ITypeSymbol explicitInterfaceSymbol = (explicitInterfaceName != null) ? semanticModel.GetTypeSymbol(explicitInterfaceName, context.CancellationToken)?.OriginalDefinition : null; ISymbol memberSymbol = (memberDeclaration is EventFieldDeclarationSyntax eventFieldDeclaration) ? semanticModel.GetDeclaredSymbol(eventFieldDeclaration.Declaration.Variables.First()) : semanticModel.GetDeclaredSymbol(memberDeclaration); if (memberSymbol == null) { return; } int count = 0; foreach (BaseTypeSyntax baseType in types) { if (ComputeRefactoring(context, memberDeclaration, baseType, explicitInterfaceSymbol, memberSymbol, semanticModel)) { count++; if (count == 10) { break; } } } }
public static IndexerDeclarationSyntax Update( this IndexerDeclarationSyntax syntax, SyntaxList<AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList) { return syntax.Update( attributeLists, modifiers, default(SyntaxToken), type, explicitInterfaceSpecifier, thisKeyword, parameterList, accessorList, default(ArrowExpressionClauseSyntax), default(SyntaxToken)); }
private static Symbol FindExplicitlyImplementedMember( Symbol implementingMember, TypeSymbol explicitInterfaceType, string interfaceMemberName, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierSyntax, DiagnosticBag diagnostics) { if ((object)explicitInterfaceType == null) { return(null); } var memberLocation = implementingMember.Locations[0]; var containingType = implementingMember.ContainingType; switch (containingType.TypeKind) { case TypeKind.Class: case TypeKind.Struct: case TypeKind.Interface: break; default: diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationInNonClassOrStruct, memberLocation, implementingMember); return(null); } if (!explicitInterfaceType.IsInterfaceType()) { //we'd like to highlight just the type part of the name var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explicitInterfaceSyntax); diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationNotInterface, location, explicitInterfaceType); return(null); } var explicitInterfaceNamedType = (NamedTypeSymbol)explicitInterfaceType; // 13.4.1: "For an explicit interface member implementation to be valid, the class or struct must name an // interface in its base class list that contains a member ..." MultiDictionary <NamedTypeSymbol, NamedTypeSymbol> .ValueSet set = containingType.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics[explicitInterfaceNamedType]; int setCount = set.Count; if (setCount == 0 || !set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.ObliviousNullableModifierMatchesAny)) { //we'd like to highlight just the type part of the name var explicitInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explicitInterfaceSyntax); if (setCount > 0 && set.Contains(explicitInterfaceNamedType, Symbols.SymbolEqualityComparer.IgnoringNullable)) { diagnostics.Add(ErrorCode.WRN_NullabilityMismatchInExplicitlyImplementedInterface, location); } else { diagnostics.Add(ErrorCode.ERR_ClassDoesntImplementInterface, location, implementingMember, explicitInterfaceNamedType); } //do a lookup anyway } // Do not look in itself if (containingType == (object)explicitInterfaceNamedType.OriginalDefinition) { // An error will be reported elsewhere. // Either the interface is not implemented, or it causes a cycle in the interface hierarchy. return(null); } var hasParamsParam = implementingMember.HasParamsParameter(); // Setting this flag to true does not imply that an interface member has been successfully implemented. // It just indicates that a corresponding interface member has been found (there may still be errors). var foundMatchingMember = false; Symbol implementedMember = null; foreach (Symbol interfaceMember in explicitInterfaceNamedType.GetMembers(interfaceMemberName)) { // At this point, we know that explicitInterfaceNamedType is an interface. // However, metadata interface members can be static - we ignore them, as does Dev10. if (interfaceMember.Kind != implementingMember.Kind || !interfaceMember.IsImplementableInterfaceMember()) { continue; } if (MemberSignatureComparer.ExplicitImplementationComparer.Equals(implementingMember, interfaceMember)) { foundMatchingMember = true; // Cannot implement accessor directly unless // the accessor is from an indexed property. if (interfaceMember.IsAccessor() && !((MethodSymbol)interfaceMember).IsIndexedPropertyAccessor()) { diagnostics.Add(ErrorCode.ERR_ExplicitMethodImplAccessor, memberLocation, implementingMember, interfaceMember); } else { if (interfaceMember.MustCallMethodsDirectly()) { diagnostics.Add(ErrorCode.ERR_BogusExplicitImpl, memberLocation, implementingMember, interfaceMember); } else if (hasParamsParam && !interfaceMember.HasParamsParameter()) { // Note: no error for !hasParamsParam && interfaceMethod.HasParamsParameter() // Still counts as an implementation. diagnostics.Add(ErrorCode.ERR_ExplicitImplParams, memberLocation, implementingMember, interfaceMember); } implementedMember = interfaceMember; break; } } } if (!foundMatchingMember) { // CONSIDER: we may wish to suppress this error in the event that another error // has been reported about the signature. diagnostics.Add(ErrorCode.ERR_InterfaceMemberNotFound, memberLocation, implementingMember); } // Make sure implemented member is accessible if ((object)implementedMember != null) { HashSet <DiagnosticInfo> useSiteDiagnostics = null; if (!AccessCheck.IsSymbolAccessible(implementedMember, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null)) { diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, implementedMember); } else { switch (implementedMember.Kind) { case SymbolKind.Property: var propertySymbol = (PropertySymbol)implementedMember; checkAccessorIsAccessibleIfImplementable(propertySymbol.GetMethod); checkAccessorIsAccessibleIfImplementable(propertySymbol.SetMethod); break; case SymbolKind.Event: var eventSymbol = (EventSymbol)implementedMember; checkAccessorIsAccessibleIfImplementable(eventSymbol.AddMethod); checkAccessorIsAccessibleIfImplementable(eventSymbol.RemoveMethod); break; } void checkAccessorIsAccessibleIfImplementable(MethodSymbol accessor) { if (accessor.IsImplementable() && !AccessCheck.IsSymbolAccessible(accessor, implementingMember.ContainingType, ref useSiteDiagnostics, throughTypeOpt: null)) { diagnostics.Add(ErrorCode.ERR_BadAccess, memberLocation, accessor); } } } diagnostics.Add(memberLocation, useSiteDiagnostics); } return(implementedMember); }
public IndexerDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken thisKeyword, BracketedParameterListSyntax parameterList, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, SyntaxToken semicolonToken) { return(Update(attributeLists, modifiers, this.RefKeyword, type, explicitInterfaceSpecifier, thisKeyword, parameterList, accessorList, expressionBody, semicolonToken)); }
/// <summary> /// /// </summary> /// <param name="node"></param> public override sealed void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { this.OnNodeVisited(node, this.type.IsInstanceOfType(node)); base.VisitExplicitInterfaceSpecifier(node); }
public EventDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, SyntaxToken eventKeyword, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, SyntaxToken semicolonToken) { return(Update(attributeLists, modifiers, eventKeyword, type, explicitInterfaceSpecifier, identifier, accessorList: null, semicolonToken)); }
private static string ExpandExplicitInterfaceName(string identifier, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier) { return explicitInterfaceSpecifier == null ? identifier : $"{explicitInterfaceSpecifier.Name.GetNameToken().ValueText}.{identifier}"; }
internal SourceCustomEventSymbol(SourceMemberContainerTypeSymbol containingType, Binder binder, EventDeclarationSyntax syntax, DiagnosticBag diagnostics) : base(containingType, syntax, syntax.Modifiers, syntax.ExplicitInterfaceSpecifier, syntax.Identifier, diagnostics) { ExplicitInterfaceSpecifierSyntax interfaceSpecifier = syntax.ExplicitInterfaceSpecifier; SyntaxToken nameToken = syntax.Identifier; bool isExplicitInterfaceImplementation = interfaceSpecifier != null; string aliasQualifierOpt; _name = ExplicitInterfaceHelpers.GetMemberNameAndInterfaceSymbol(binder, interfaceSpecifier, nameToken.ValueText, diagnostics, out _explicitInterfaceType, out aliasQualifierOpt); _type = BindEventType(binder, syntax.Type, diagnostics); var explicitlyImplementedEvent = this.FindExplicitlyImplementedEvent(_explicitInterfaceType, nameToken.ValueText, interfaceSpecifier, diagnostics); this.FindExplicitlyImplementedMemberVerification(explicitlyImplementedEvent, diagnostics); // The runtime will not treat the accessors of this event as overrides or implementations // of those of another event unless both the signatures and the custom modifiers match. // Hence, in the case of overrides and *explicit* implementations, we need to copy the custom // modifiers that are in the signatures of the overridden/implemented event accessors. // (From source, we know that there can only be one overridden/implemented event, so there // are no conflicts.) This is unnecessary for implicit implementations because, if the custom // modifiers don't match, we'll insert bridge methods for the accessors (explicit implementations // that delegate to the implicit implementations) with the correct custom modifiers // (see SourceMemberContainerTypeSymbol.SynthesizeInterfaceMemberImplementation). // Note: we're checking if the syntax indicates explicit implementation rather, // than if explicitInterfaceType is null because we don't want to look for an // overridden event if this is supposed to be an explicit implementation. if (!isExplicitInterfaceImplementation) { // If this event is an override, we may need to copy custom modifiers from // the overridden event (so that the runtime will recognize it as an override). // We check for this case here, while we can still modify the parameters and // return type without losing the appearance of immutability. if (this.IsOverride) { EventSymbol overriddenEvent = this.OverriddenEvent; if ((object)overriddenEvent != null) { CopyEventCustomModifiers(overriddenEvent, ref _type, ContainingAssembly); } } } else if ((object)explicitlyImplementedEvent != null) { CopyEventCustomModifiers(explicitlyImplementedEvent, ref _type, ContainingAssembly); } AccessorDeclarationSyntax addSyntax = null; AccessorDeclarationSyntax removeSyntax = null; foreach (AccessorDeclarationSyntax accessor in syntax.AccessorList.Accessors) { switch (accessor.Kind()) { case SyntaxKind.AddAccessorDeclaration: if (addSyntax == null) { addSyntax = accessor; } else { diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation()); } break; case SyntaxKind.RemoveAccessorDeclaration: if (removeSyntax == null) { removeSyntax = accessor; } else { diagnostics.Add(ErrorCode.ERR_DuplicateAccessor, accessor.Keyword.GetLocation()); } break; case SyntaxKind.GetAccessorDeclaration: case SyntaxKind.SetAccessorDeclaration: diagnostics.Add(ErrorCode.ERR_AddOrRemoveExpected, accessor.Keyword.GetLocation()); break; case SyntaxKind.UnknownAccessorDeclaration: // Don't need to handle UnknownAccessorDeclaration. An error will have // already been produced for it in the parser. break; default: throw ExceptionUtilities.UnexpectedValue(accessor.Kind()); } } _addMethod = CreateAccessorSymbol(addSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics); _removeMethod = CreateAccessorSymbol(removeSyntax, explicitlyImplementedEvent, aliasQualifierOpt, diagnostics); if (containingType.IsInterfaceType()) { if (addSyntax == null && removeSyntax == null) //NOTE: AND - different error code produced if one is present { // CONSIDER: we're matching dev10, but it would probably be more helpful to give // an error like ERR_EventPropertyInInterface. diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this); } } else { if (addSyntax == null || removeSyntax == null) { diagnostics.Add(ErrorCode.ERR_EventNeedsBothAccessors, this.Locations[0], this); } } _explicitInterfaceImplementations = (object)explicitlyImplementedEvent == null ? ImmutableArray <EventSymbol> .Empty : ImmutableArray.Create <EventSymbol>(explicitlyImplementedEvent); }
public PropertyDeclarationSyntax Update(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken) { return(Update(attributeLists, modifiers, this.RefKeyword, type, explicitInterfaceSpecifier, identifier, accessorList, expressionBody, initializer, semicolonToken)); }
private static Symbol FindExplicitlyImplementedMember( Symbol implementingMember, TypeSymbol explicitInterfaceType, string interfaceMemberName, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierSyntax, DiagnosticBag diagnostics) { if ((object)explicitInterfaceType == null) { return(null); } var memberLocation = implementingMember.Locations[0]; var containingType = implementingMember.ContainingType; var containingTypeKind = containingType.TypeKind; if (containingTypeKind != TypeKind.Class && containingTypeKind != TypeKind.Struct) { diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationInNonClassOrStruct, memberLocation, implementingMember); return(null); } if (!explicitInterfaceType.IsInterfaceType()) { //we'd like to highlight just the type part of the name var explictInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explictInterfaceSyntax); diagnostics.Add(ErrorCode.ERR_ExplicitInterfaceImplementationNotInterface, location, explicitInterfaceType); return(null); } var explicitInterfaceNamedType = (NamedTypeSymbol)explicitInterfaceType; // 13.4.1: "For an explicit interface member implementation to be valid, the class or struct must name an // interface in its base class list that contains a member ..." if (!containingType.InterfacesAndTheirBaseInterfacesNoUseSiteDiagnostics.Contains(explicitInterfaceNamedType)) { //we'd like to highlight just the type part of the name var explictInterfaceSyntax = explicitInterfaceSpecifierSyntax.Name; var location = new SourceLocation(explictInterfaceSyntax); diagnostics.Add(ErrorCode.ERR_ClassDoesntImplementInterface, location, implementingMember, explicitInterfaceNamedType); //do a lookup anyway } var hasParamsParam = implementingMember.HasParamsParameter(); // Setting this flag to true does not imply that an interface member has been successfully implemented. // It just indicates that a corresponding interface member has been found (there may still be errors). var foundMatchingMember = false; Symbol implementedMember = null; foreach (Symbol interfaceMember in explicitInterfaceNamedType.GetMembers(interfaceMemberName)) { // At this point, we know that explicitInterfaceNamedType is an interface, so candidate must be public // and, therefore, accessible. So we don't need to check that. // However, metadata interface members can be static - we ignore them, as does Dev10. if (interfaceMember.Kind != implementingMember.Kind || interfaceMember.IsStatic) { continue; } if (MemberSignatureComparer.ExplicitImplementationComparer.Equals(implementingMember, interfaceMember)) { foundMatchingMember = true; // Cannot implement accessor directly unless // the accessor is from an indexed property. if (interfaceMember.IsAccessor() && !((MethodSymbol)interfaceMember).IsIndexedPropertyAccessor()) { diagnostics.Add(ErrorCode.ERR_ExplicitMethodImplAccessor, memberLocation, implementingMember, interfaceMember); } else { if (interfaceMember.MustCallMethodsDirectly()) { diagnostics.Add(ErrorCode.ERR_BogusExplicitImpl, memberLocation, implementingMember, interfaceMember); } else if (hasParamsParam && !interfaceMember.HasParamsParameter()) { // Note: no error for !hasParamsParam && interfaceMethod.HasParamsParameter() // Still counts as an implementation. diagnostics.Add(ErrorCode.ERR_ExplicitImplParams, memberLocation, implementingMember, interfaceMember); } implementedMember = interfaceMember; break; } } } if (!foundMatchingMember) { // CONSIDER: we may wish to suppress this error in the event that another error // has been reported about the signature. diagnostics.Add(ErrorCode.ERR_InterfaceMemberNotFound, memberLocation, implementingMember); } // In constructed types, it is possible that two method signatures could differ by only ref/out // after substitution. We look for this as part of explicit implementation because, if someone // tried to implement the ambiguous interface implicitly, we would separately raise an error about // the implicit implementation methods differing by only ref/out. FindExplicitImplementationCollisions(implementingMember, implementedMember, diagnostics); return(implementedMember); }
public static PropertyDeclarationSyntax PropertyDeclaration(SyntaxList <AttributeListSyntax> attributeLists, SyntaxTokenList modifiers, TypeSyntax type, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifier, SyntaxToken identifier, AccessorListSyntax accessorList, ArrowExpressionClauseSyntax expressionBody, EqualsValueClauseSyntax initializer, SyntaxToken semicolonToken) { return(PropertyDeclaration( attributeLists, modifiers, refKeyword: default(SyntaxToken), type: type, explicitInterfaceSpecifier: explicitInterfaceSpecifier, identifier: identifier, accessorList: accessorList, expressionBody: expressionBody, initializer: initializer, semicolonToken: semicolonToken)); }
private string GetDeclarationName(CSharpSyntaxNode declaration, ExplicitInterfaceSpecifierSyntax explicitInterfaceSpecifierOpt, string memberName) { if (explicitInterfaceSpecifierOpt == null) { return memberName; } // For an explicit interface implementation, we actually have several options: // Option 1: do nothing - it will retry without the name // Option 2: detect explicit impl and return null // Option 3: get a binder and figure out the name // For now, we're going with Option 3 return ExplicitInterfaceHelpers.GetMemberName(_binderFactory.GetBinder(declaration), explicitInterfaceSpecifierOpt, memberName); }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { throw new NotImplementedException(); }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { }
public override void VisitExplicitInterfaceSpecifier(ExplicitInterfaceSpecifierSyntax node) { _stack.Push(SyntaxElement.ExplicitInterfaceSpecifier); base.VisitExplicitInterfaceSpecifier(node); _stack.Pop(); }