Skip to content

Commit

Permalink
bug: GetReturnAttributes for properties, indexes and events
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Mar 15, 2024
1 parent 11bf34c commit 7a45d90
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<RepositoryUrl>https://github.com/beakona/AutoInterface</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_AddAnalyzersToOutput</TargetsForTfmSpecificContentInPackage>
<Version>1.0.37</Version>
<Version>1.0.38</Version>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
Expand Down
27 changes: 4 additions & 23 deletions BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,28 +413,9 @@ private IEnumerable<AttributeData> GetForwardAttributes(ISymbol symbol)
}
}

private IEnumerable<AttributeData> GetReturnAttributes(IPropertySymbol method)
private IEnumerable<AttributeData> GetReturnAttributes(ISymbol symbol)
{
var attributes = method.GetAttributes().Where(IsPublicAccess).ToList();

foreach (var attribute in attributes)
{
if (attribute.AttributeClass is INamedTypeSymbol attributeClass)
{
foreach (var typeSymbol in this.returnAttributeSymbols)
{
if (attributeClass.Equals(typeSymbol, SymbolEqualityComparer.Default))
{
yield return attribute;
break;
}
}
}
}
}
private IEnumerable<AttributeData> GetReturnAttributes(IMethodSymbol method)
{
var attributes = method.GetReturnTypeAttributes().Where(IsPublicAccess).ToList();
var attributes = symbol.GetAttributes().Where(IsPublicAccess).ToList();

foreach (var attribute in attributes)
{
Expand Down Expand Up @@ -673,7 +654,7 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope
PartialTemplate? setterTemplate = this.GetMatchedTemplates(references, setterTarget, property.IsIndexer ? "this" : property.Name);

this.WriteForwardAttributes(builder, property);
this.WriteReturnAttributes(builder, GetReturnAttributes(property));
this.WriteReturnAttributes(builder, this.GetReturnAttributes(property));

builder.AppendIndentation();
this.WriteTypeReference(builder, property.Type, scope);
Expand Down Expand Up @@ -842,7 +823,7 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco
PartialTemplate? removerTemplate = this.GetMatchedTemplates(references, AutoInterfaceTargets.EventRemover, @event.Name);

this.WriteForwardAttributes(builder, @event);
this.WriteReturnAttributes(builder, @event.Type.GetAttributes());
this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event));

builder.AppendIndentation();
builder.Append("event");
Expand Down

0 comments on commit 7a45d90

Please sign in to comment.