提交 1e55ad19 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14371 from CyrusNajmabadi/eventParameters3

Use immutable arrays inside our special codegen events.
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Generic
Imports System.Collections.Immutable
Imports System.Globalization
Imports System.Runtime.InteropServices
......@@ -8,7 +7,6 @@ Imports System.Threading
Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.Symbols
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports TypeKind = Microsoft.CodeAnalysis.TypeKind
Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Class SourceEventSymbol
......
......@@ -17,14 +17,6 @@ public WrappedEventSymbol(IEventSymbol eventSymbol, bool canImplementImplicitly,
_symbol = eventSymbol;
}
public IMethodSymbol AddMethod
{
get
{
return _symbol.AddMethod;
}
}
public ImmutableArray<IEventSymbol> ExplicitInterfaceImplementations
{
get
......@@ -35,53 +27,14 @@ public ImmutableArray<IEventSymbol> ExplicitInterfaceImplementations
}
}
public bool IsWindowsRuntimeEvent
{
get
{
return _symbol.IsWindowsRuntimeEvent;
}
}
public new IEventSymbol OriginalDefinition
{
get
{
return this;
}
}
public IEventSymbol OverriddenEvent
{
get
{
return _symbol.OverriddenEvent;
}
}
public IMethodSymbol RaiseMethod
{
get
{
return _symbol.RaiseMethod;
}
}
public IMethodSymbol RemoveMethod
{
get
{
return _symbol.RemoveMethod;
}
}
public new IEventSymbol OriginalDefinition => this;
public ITypeSymbol Type
{
get
{
return _symbol.Type;
}
}
public IMethodSymbol AddMethod => _symbol.AddMethod;
public bool IsWindowsRuntimeEvent => _symbol.IsWindowsRuntimeEvent;
public IEventSymbol OverriddenEvent => _symbol.OverriddenEvent;
public IMethodSymbol RaiseMethod => _symbol.RaiseMethod;
public IMethodSymbol RemoveMethod => _symbol.RemoveMethod;
public ITypeSymbol Type => _symbol.Type;
}
}
}
\ No newline at end of file
......@@ -14,20 +14,17 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Private ReadOnly _generatedEvent As IEventSymbol
Private ReadOnly _codeGenerationOptions As CodeGenerationOptions
Private ReadOnly _codeGenService As ICodeGenerationService
Private ReadOnly _generatedType As INamedTypeSymbol
Public Sub New(solution As Solution,
targetSymbol As INamedTypeSymbol,
generatedEvent As IEventSymbol,
generatedType As INamedTypeSymbol,
codeGenService As ICodeGenerationService,
codeGenerationOptions As CodeGenerationOptions)
Me._solution = solution
Me._targetSymbol = targetSymbol
Me._generatedEvent = generatedEvent
Me._generatedType = generatedType
Me._codeGenService = codeGenService
Me._codeGenerationOptions = codeGenerationOptions
_solution = solution
_targetSymbol = targetSymbol
_generatedEvent = generatedEvent
_codeGenService = codeGenService
_codeGenerationOptions = codeGenerationOptions
End Sub
Public Overrides ReadOnly Property Title As String
......@@ -36,19 +33,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
End Get
End Property
Protected Overrides Async Function GetChangedDocumentAsync(cancellationToken As CancellationToken) As Task(Of Document)
Dim withEvent = Await _codeGenService.AddEventAsync(_solution, _targetSymbol, _generatedEvent, _codeGenerationOptions, cancellationToken).ConfigureAwait(False)
If _generatedType IsNot Nothing Then
Dim compilation = Await withEvent.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(False)
Dim newTargetSymbol = _targetSymbol.GetSymbolKey().Resolve(compilation).Symbol
If newTargetSymbol.ContainingType IsNot Nothing Then
Return Await _codeGenService.AddNamedTypeAsync(withEvent.Project.Solution, newTargetSymbol.ContainingType, _generatedType, _codeGenerationOptions, cancellationToken).ConfigureAwait(False)
ElseIf newTargetSymbol.ContainingNamespace IsNot Nothing Then
Return Await _codeGenService.AddNamedTypeAsync(withEvent.Project.Solution, newTargetSymbol.ContainingNamespace, _generatedType, _codeGenerationOptions, cancellationToken).ConfigureAwait(False)
End If
End If
Return Await _codeGenService.AddEventAsync(_solution, _targetSymbol, _generatedEvent, _codeGenerationOptions, cancellationToken).ConfigureAwait(False)
Protected Overrides Function GetChangedDocumentAsync(cancellationToken As CancellationToken) As Task(Of Document)
Return _codeGenService.AddEventAsync(
_solution, _targetSymbol, _generatedEvent,
_codeGenerationOptions, cancellationToken)
End Function
End Class
End Class
......
......@@ -104,7 +104,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Private Shared Async Function GenerateCodeAction(document As Document, semanticModel As SemanticModel, delegateSymbol As IMethodSymbol, actualEventName As String, targetType As INamedTypeSymbol, cancellationToken As CancellationToken) As Task(Of CodeAction)
Dim codeGenService = document.Project.Solution.Workspace.Services.GetLanguageServices(targetType.Language).GetService(Of ICodeGenerationService)
Dim semanticFactService = document.Project.Solution.Workspace.Services.GetLanguageServices(targetType.Language).GetService(Of ISemanticFactsService)
Dim syntaxFactService = document.Project.Solution.Workspace.Services.GetLanguageServices(targetType.Language).GetService(Of ISyntaxFactsService)
Dim eventHandlerName As String = actualEventName + "Handler"
......@@ -117,30 +116,25 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Return Nothing
End If
If semanticFactService.SupportsParameterizedEvents Then
' We also need to generate the delegate type
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(Nothing, Accessibility.Public, Nothing,
semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=eventHandlerName,
parameters:=delegateSymbol.GetParameters())
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=eventHandlerName, parameters:=delegateSymbol.GetParameters())
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(
attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
accessibility:=Accessibility.Public, modifiers:=Nothing,
explicitInterfaceSymbol:=Nothing,
type:=delegateType, name:=actualEventName,
parameterList:=TryCast(delegateSymbol, IMethodSymbol).Parameters)
type:=delegateType, name:=actualEventName)
Return New GenerateEventCodeAction(document.Project.Solution, targetType, generatedEvent, delegateType, codeGenService, CodeGenerationOptions.Default)
Else
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
accessibility:=Accessibility.Public, modifiers:=Nothing,
explicitInterfaceSymbol:=Nothing,
type:=Nothing, name:=actualEventName,
parameterList:=delegateSymbol.GetParameters())
' Point the delegate back at the event symbol. This way the generators know to generate parameters
' instead of an 'As' clause.
delegateType.AssociatedSymbol = generatedEvent
Return New GenerateEventCodeAction(document.Project.Solution, TryCast(targetType, INamedTypeSymbol), generatedEvent, Nothing, codeGenService, CodeGenerationOptions.Default)
End If
Return New GenerateEventCodeAction(
document.Project.Solution, targetType, generatedEvent,
codeGenService, CodeGenerationOptions.Default)
End Function
Private Function GetHandlerExpression(handlerStatement As AddRemoveHandlerStatementSyntax) As ExpressionSyntax
......@@ -230,7 +224,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
End If
' We must be trying to implement an event
If node.IsParentKind(SyntaxKind.ImplementsClause) AndAlso node.Parent.IsParentKind(SyntaxKind.EventStatement) Then
If Not node.IsParentKind(SyntaxKind.ImplementsClause) OrElse Not node.Parent.IsParentKind(SyntaxKind.EventStatement) Then
Return Nothing
End If
' Does this name already bind?
Dim semanticModel = Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False)
Dim nameToGenerate = semanticModel.GetSymbolInfo(node).Symbol
......@@ -253,9 +250,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Dim actualEventName = node.Right.Identifier.ValueText
Dim semanticFactService = document.Project.Solution.Workspace.Services.GetLanguageServices(targetType.Language).GetService(Of ISemanticFactsService)
If semanticFactService.SupportsParameterizedEvents Then
' If we support parameterized events (C#) and it's an event declaration with a parameter list
' (not a type), we need to generate a delegate type in the C# file.
Dim eventSyntax = node.GetAncestor(Of EventStatementSyntax)()
......@@ -274,28 +268,30 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
eventType.DelegateInvokeMethod.Parameters,
SpecializedCollections.EmptyList(Of IParameterSymbol)())
Dim eventHandlerType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(eventType.GetAttributes(),
eventType.DeclaredAccessibility,
Nothing,
returnType,
actualEventName + "EventHandler",
eventType.TypeParameters,
parameters)
Dim eventHandlerType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
eventType.GetAttributes(), eventType.DeclaredAccessibility,
modifiers:=Nothing, returnType:=returnType,
name:=actualEventName + "EventHandler",
typeParameters:=eventType.TypeParameters, parameters:=parameters)
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(boundEvent.GetAttributes(), boundEvent.DeclaredAccessibility,
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(
boundEvent.GetAttributes(), boundEvent.DeclaredAccessibility,
modifiers:=Nothing, type:=eventHandlerType, explicitInterfaceSymbol:=Nothing,
name:=actualEventName,
parameterList:=boundEvent.GetParameters())
Return New GenerateEventCodeAction(document.Project.Solution, targetType, generatedEvent, eventHandlerType, codeGenService, New CodeGenerationOptions())
End If
End If
name:=actualEventName)
' C# with no delegate type or VB
' Point the delegate back at the event symbol. This way the generators know to generate parameters
' instead of an 'As' clause.
eventHandlerType.AssociatedSymbol = generatedEvent
Return New GenerateEventCodeAction(
document.Project.Solution, targetType, generatedEvent,
codeGenService, New CodeGenerationOptions())
Else
' Event with no parameters.
Dim generatedMember = CodeGenerationSymbolFactory.CreateEventSymbol(boundEvent, name:=actualEventName)
Return New GenerateEventCodeAction(document.Project.Solution, targetType, generatedMember, Nothing, codeGenService, New CodeGenerationOptions())
Return New GenerateEventCodeAction(
document.Project.Solution, targetType, generatedMember, codeGenService, New CodeGenerationOptions())
End If
Return Nothing
End Function
Private Async Function GenerateEventFromHandlesAsync(document As Document, handlesClauseItem As HandlesClauseItemSyntax, cancellationToken As CancellationToken) As Task(Of CodeAction)
......@@ -374,30 +370,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeFixes.GenerateEvent
Dim actualEventName = handlesClauseItem.EventMember.Identifier.ValueText
Dim semanticFactService = document.Project.Solution.Workspace.Services.GetLanguageServices(originalTargetType.Language).GetService(Of ISemanticFactsService)
If semanticFactService.SupportsParameterizedEvents Then
' We need to generate the delegate, too.
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(Nothing, Accessibility.Public, Nothing, semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=actualEventName + "Handler",
parameters:=boundMethod.GetParameters())
Dim delegateType = CodeGenerationSymbolFactory.CreateDelegateTypeSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
returnType:=semanticModel.Compilation.GetSpecialType(SpecialType.System_Void),
name:=actualEventName + "Handler", parameters:=boundMethod.GetParameters())
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
accessibility:=Accessibility.Public, modifiers:=Nothing,
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(
attributes:=Nothing, accessibility:=Accessibility.Public, modifiers:=Nothing,
explicitInterfaceSymbol:=Nothing,
type:=delegateType, name:=actualEventName,
parameterList:=TryCast(boundMethod, IMethodSymbol).Parameters)
type:=delegateType, name:=actualEventName)
Return New GenerateEventCodeAction(document.Project.Solution, originalTargetType, generatedEvent, delegateType, codeGenService, New CodeGenerationOptions())
Else
Dim generatedEvent = CodeGenerationSymbolFactory.CreateEventSymbol(attributes:=SpecializedCollections.EmptyList(Of AttributeData)(),
accessibility:=Accessibility.Public, modifiers:=Nothing,
explicitInterfaceSymbol:=Nothing,
type:=Nothing, name:=actualEventName,
parameterList:=boundMethod.GetParameters())
' Point the delegate back at the event symbol. This way the generators know to generate parameters
' instead of an 'As' clause.
delegateType.AssociatedSymbol = generatedEvent
Return New GenerateEventCodeAction(document.Project.Solution, TryCast(originalTargetType, INamedTypeSymbol), generatedEvent, Nothing, codeGenService, CodeGenerationOptions.Default)
End If
Return New GenerateEventCodeAction(
document.Project.Solution, originalTargetType, generatedEvent,
codeGenService, New CodeGenerationOptions())
End Function
End Class
End Namespace
\ No newline at end of file
......@@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.CSharp;
......@@ -58,6 +59,38 @@ private IList<bool> GetInsertionIndices(TypeDeclarationSyntax destination, Cance
return destination.GetInsertionIndices(cancellationToken);
}
public override async Task<Document> AddEventAsync(
Solution solution, INamedTypeSymbol destination, IEventSymbol @event,
CodeGenerationOptions options, CancellationToken cancellationToken)
{
var newDocument = await base.AddEventAsync(
solution, destination, @event, options, cancellationToken).ConfigureAwait(false);
var namedType = @event.Type as INamedTypeSymbol;
if (namedType?.AssociatedSymbol != null)
{
// This is a VB event that declares its own type. i.e. "Public Event E(x As Object)"
// We also have to generate "public void delegate EEventHandler(object x)"
var compilation = await newDocument.Project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
var newDestinationSymbol = destination.GetSymbolKey().Resolve(compilation).Symbol;
if (newDestinationSymbol?.ContainingType != null)
{
return await this.AddNamedTypeAsync(
newDocument.Project.Solution, newDestinationSymbol.ContainingType,
namedType, options, cancellationToken).ConfigureAwait(false);
}
else if (newDestinationSymbol?.ContainingNamespace != null)
{
return await this.AddNamedTypeAsync(
newDocument.Project.Solution, newDestinationSymbol.ContainingNamespace,
namedType, options, cancellationToken).ConfigureAwait(false);
}
}
return newDocument;
}
protected override TDeclarationNode AddEvent<TDeclarationNode>(TDeclarationNode destination, IEventSymbol @event, CodeGenerationOptions options, IList<bool> availableIndices)
{
CheckDeclarationNode<TypeDeclarationSyntax>(destination);
......
......@@ -77,7 +77,8 @@ internal static class EventGenerator
var declaration = GenerateEventDeclaration(@event, GetDestination(destination), options);
var members = Insert(destination.Members, declaration, options, availableIndices,
after: list => AfterMember(list, declaration), before: list => BeforeMember(list, declaration));
after: list => AfterMember(list, declaration),
before: list => BeforeMember(list, declaration));
// Find the best place to put the field. It should go after the last field if we already
// have fields, or at the beginning of the file if we don't.
......
......@@ -162,14 +162,6 @@ public bool SupportsParameterizedProperties
}
}
public bool SupportsParameterizedEvents
{
get
{
return true;
}
}
public bool TryGetSpeculativeSemanticModel(SemanticModel oldSemanticModel, SyntaxNode oldNode, SyntaxNode newNode, out SemanticModel speculativeModel)
{
Contract.Requires(oldNode.Kind() == newNode.Kind());
......
......@@ -305,7 +305,9 @@ protected static CodeGenerationOptions CreateOptionsForMultipleMembers(CodeGener
return options;
}
public Task<Document> AddEventAsync(Solution solution, INamedTypeSymbol destination, IEventSymbol @event, CodeGenerationOptions options, CancellationToken cancellationToken)
public virtual Task<Document> AddEventAsync(
Solution solution, INamedTypeSymbol destination, IEventSymbol @event,
CodeGenerationOptions options, CancellationToken cancellationToken)
{
return GetEditAsync(
solution,
......
......@@ -26,9 +26,13 @@ public static bool IsCodeGenerationSymbol(this ISymbol symbol)
/// <summary>
/// Creates an event symbol that can be used to describe an event declaration.
/// </summary>
public static IEventSymbol CreateEventSymbol(IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol type, IEventSymbol explicitInterfaceSymbol, string name, IMethodSymbol addMethod = null, IMethodSymbol removeMethod = null, IMethodSymbol raiseMethod = null, IList<IParameterSymbol> parameterList = null)
public static IEventSymbol CreateEventSymbol(
IList<AttributeData> attributes, Accessibility accessibility,
DeclarationModifiers modifiers, ITypeSymbol type,
IEventSymbol explicitInterfaceSymbol, string name,
IMethodSymbol addMethod = null, IMethodSymbol removeMethod = null, IMethodSymbol raiseMethod = null)
{
var result = new CodeGenerationEventSymbol(null, attributes, accessibility, modifiers, type, explicitInterfaceSymbol, name, addMethod, removeMethod, raiseMethod, parameterList);
var result = new CodeGenerationEventSymbol(null, attributes, accessibility, modifiers, type, explicitInterfaceSymbol, name, addMethod, removeMethod, raiseMethod);
CodeGenerationEventInfo.Attach(result, modifiers.IsUnsafe);
return result;
}
......@@ -274,7 +278,14 @@ public static INamedTypeSymbol CreateNamedTypeSymbol(IList<AttributeData> attrib
/// <summary>
/// Creates a method type symbol that can be used to describe a delegate type declaration.
/// </summary>
public static INamedTypeSymbol CreateDelegateTypeSymbol(IList<AttributeData> attributes, Accessibility accessibility, DeclarationModifiers modifiers, ITypeSymbol returnType, string name, IList<ITypeParameterSymbol> typeParameters = null, IList<IParameterSymbol> parameters = null)
public static CodeGenerationNamedTypeSymbol CreateDelegateTypeSymbol(
IList<AttributeData> attributes,
Accessibility accessibility,
DeclarationModifiers modifiers,
ITypeSymbol returnType,
string name,
IList<ITypeParameterSymbol> typeParameters = null,
IList<IParameterSymbol> parameters = null)
{
var invokeMethod = CreateMethodSymbol(
attributes: null,
......
......@@ -84,13 +84,7 @@ public override string MetadataName
}
}
public ISymbol AssociatedSymbol
{
get
{
return null;
}
}
public ISymbol AssociatedSymbol { get; internal set; }
public bool MightContainExtensionMethods
{
......
......@@ -11,20 +11,11 @@ internal class CodeGenerationEventSymbol : CodeGenerationSymbol, IEventSymbol
{
public ITypeSymbol Type { get; }
public bool IsWindowsRuntimeEvent
{
get
{
return false;
}
}
public ImmutableArray<IEventSymbol> ExplicitInterfaceImplementations { get; }
public IMethodSymbol AddMethod { get; }
public IMethodSymbol RemoveMethod { get; }
public IMethodSymbol RaiseMethod { get; }
public IList<IParameterSymbol> ParameterList { get; }
public CodeGenerationEventSymbol(
INamedTypeSymbol containingType,
......@@ -36,8 +27,7 @@ public bool IsWindowsRuntimeEvent
string name,
IMethodSymbol addMethod,
IMethodSymbol removeMethod,
IMethodSymbol raiseMethod,
IList<IParameterSymbol> parameterList)
IMethodSymbol raiseMethod)
: base(containingType, attributes, declaredAccessibility, modifiers, name)
{
this.Type = type;
......@@ -47,7 +37,6 @@ public bool IsWindowsRuntimeEvent
this.AddMethod = addMethod;
this.RemoveMethod = removeMethod;
this.RaiseMethod = raiseMethod;
this.ParameterList = parameterList;
}
protected override CodeGenerationSymbol Clone()
......@@ -55,49 +44,23 @@ protected override CodeGenerationSymbol Clone()
return new CodeGenerationEventSymbol(
this.ContainingType, this.GetAttributes(), this.DeclaredAccessibility,
this.Modifiers, this.Type, this.ExplicitInterfaceImplementations.FirstOrDefault(),
this.Name, this.AddMethod, this.RemoveMethod, this.RaiseMethod, this.ParameterList);
this.Name, this.AddMethod, this.RemoveMethod, this.RaiseMethod);
}
public override SymbolKind Kind
{
get
{
return SymbolKind.Event;
}
}
public override SymbolKind Kind => SymbolKind.Event;
public override void Accept(SymbolVisitor visitor)
{
visitor.VisitEvent(this);
}
=> visitor.VisitEvent(this);
public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor)
{
return visitor.VisitEvent(this);
}
=> visitor.VisitEvent(this);
public new IEventSymbol OriginalDefinition
{
get
{
return this;
}
}
public new IEventSymbol OriginalDefinition => this;
public IEventSymbol OverriddenEvent
{
get
{
return null;
}
}
public bool IsWindowsRuntimeEvent => false;
public ImmutableArray<CustomModifier> TypeCustomModifiers
{
get
{
return ImmutableArray.Create<CustomModifier>();
}
}
public IEventSymbol OverriddenEvent => null;
public ImmutableArray<CustomModifier> TypeCustomModifiers => ImmutableArray.Create<CustomModifier>();
}
}
\ No newline at end of file
......@@ -74,8 +74,6 @@ internal interface ISemanticFactsService : ILanguageService
bool LastEnumValueHasInitializer(INamedTypeSymbol namedTypeSymbol);
bool SupportsParameterizedEvents { get; }
/// <summary>
/// return speculative semantic model for supported node. otherwise, it will return null
/// </summary>
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.CodeGeneration
Imports Microsoft.CodeAnalysis.CodeGeneration.CodeGenerationHelpers
......@@ -80,30 +81,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
' have a type that is unmentionable. So we should not generate it as "Event E() As
' SomeType", but should instead inline the delegate type into the event itself.
Return SyntaxFactory.EventStatement(
attributeLists:=AttributeGenerator.GenerateAttributeBlocks([event].GetAttributes(), options),
attributeLists:=GenerateAttributeBlocks([event].GetAttributes(), options),
modifiers:=GenerateModifiers([event], destination, options),
identifier:=[event].Name.ToIdentifierToken,
parameterList:=ParameterGenerator.GenerateParameterList(eventType.DelegateInvokeMethod.Parameters.Select(Function(p) RemoveOptionalOrParamArray(p)).ToList(), options),
asClause:=Nothing,
implementsClause:=GenerateImplementsClause([event].ExplicitInterfaceImplementations.FirstOrDefault()))
ElseIf TypeOf [event] Is CodeGenerationEventSymbol AndAlso TryCast([event], CodeGenerationEventSymbol).ParameterList IsNot Nothing Then
' We'll try to generate a parameter list
Return SyntaxFactory.EventStatement(
attributeLists:=AttributeGenerator.GenerateAttributeBlocks([event].GetAttributes(), options),
modifiers:=GenerateModifiers([event], destination, options),
identifier:=[event].Name.ToIdentifierToken,
parameterList:=ParameterGenerator.GenerateParameterList(TryCast([event], CodeGenerationEventSymbol).ParameterList.Select(Function(p) RemoveOptionalOrParamArray(p)).ToArray(), options),
asClause:=Nothing,
implementsClause:=GenerateImplementsClause([event].ExplicitInterfaceImplementations.FirstOrDefault()))
Else
End If
Return SyntaxFactory.EventStatement(
attributeLists:=AttributeGenerator.GenerateAttributeBlocks([event].GetAttributes(), options),
attributeLists:=GenerateAttributeBlocks([event].GetAttributes(), options),
modifiers:=GenerateModifiers([event], destination, options),
identifier:=[event].Name.ToIdentifierToken,
parameterList:=Nothing,
asClause:=GenerateAsClause([event]),
implementsClause:=GenerateImplementsClause([event].ExplicitInterfaceImplementations.FirstOrDefault()))
End If
End Function
Private Function GenerateModifiers([event] As IEventSymbol,
......
......@@ -79,7 +79,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
options As CodeGenerationOptions,
availableIndices As IList(Of Boolean)) As TDeclarationNode
CheckDeclarationNode(Of TypeBlockSyntax)(destinationType)
Return Cast(Of TDeclarationNode)(EventGenerator.AddEventTo(Cast(Of TypeBlockSyntax)(destinationType), [event], options, availableIndices))
Return Cast(Of TDeclarationNode)(AddEventTo(Cast(Of TypeBlockSyntax)(destinationType), [event], options, availableIndices))
End Function
Protected Overrides Function AddField(Of TDeclarationNode As SyntaxNode)(
......
......@@ -146,12 +146,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Public ReadOnly Property SupportsParameterizedEvents As Boolean Implements ISemanticFactsService.SupportsParameterizedEvents
Get
Return False
End Get
End Property
Public Function TryGetSpeculativeSemanticModel(oldSemanticModel As SemanticModel, oldNode As SyntaxNode, newNode As SyntaxNode, <Out> ByRef speculativeModel As SemanticModel) As Boolean Implements ISemanticFactsService.TryGetSpeculativeSemanticModel
Contract.Requires(oldNode.Kind = newNode.Kind)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册