提交 0cbfef79 编写于 作者: J Jason Malinowski

Strip inaccessible attributes when generating event handlers

上级 adfe8f0f
......@@ -265,17 +265,18 @@ private void GenerateAndAddEventHandler(ITextView textView, ITextBuffer subjectB
}
var syntaxFactory = semanticDocument.Document.GetLanguageService<SyntaxGenerator>();
var delegateInvokeMethod = delegateType.DelegateInvokeMethod.RemoveInaccessibleAttributesAndAttributesOfTypes(semanticDocument.SemanticModel.Compilation.Assembly);
return CodeGenerationSymbolFactory.CreateMethodSymbol(
attributes: default,
accessibility: Accessibility.Private,
modifiers: new DeclarationModifiers(isStatic: eventHookupExpression.IsInStaticContext()),
returnType: delegateType.DelegateInvokeMethod.ReturnType,
refKind: delegateType.DelegateInvokeMethod.RefKind,
returnType: delegateInvokeMethod.ReturnType,
refKind: delegateInvokeMethod.RefKind,
explicitInterfaceImplementations: default,
name: eventHandlerMethodName,
typeParameters: default,
parameters: delegateType.DelegateInvokeMethod.Parameters,
parameters: delegateInvokeMethod.Parameters,
statements: ImmutableArray.Create(
CodeGenerationHelpers.GenerateThrowStatement(syntaxFactory, semanticDocument, "System.NotImplementedException", cancellationToken)));
}
......
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -905,6 +906,59 @@ private void C_MyEvent()
testState.AssertCodeIs(expectedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.EventHookup)]
public async Task EventHookupRemovesInaccessibleAttributes()
{
var workspaceXml = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""A"" CommonReferences=""true"">
<Document>
using System;
public static class C
{
public static event DelegateType E;
public delegate void DelegateType([ShouldBeRemovedInternalAttribute] object o);
}
internal class ShouldBeRemovedInternalAttribute : Attribute { }
</Document>
</Project>
<Project Language=""C#"" CommonReferences=""true"">
<ProjectReference>A</ProjectReference>
<Document>
class D
{
void M()
{
C.E +$$
}
}</Document>
</Project>
</Workspace>";
using var testState = new EventHookupTestState(XElement.Parse(workspaceXml), options: null);
testState.SendTypeChar('=');
testState.SendTab();
await testState.WaitForAsynchronousOperationsAsync();
var expectedCode = @"
class D
{
void M()
{
C.E += C_E;
}
private void C_E(object o)
{
throw new System.NotImplementedException();
}
}";
testState.AssertCodeIs(expectedCode);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.EventHookup)]
public async Task EventHookupWithQualifiedMethodAccessAndNotificationOptionSilent()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册