diff --git a/AutoInterfaceSample/Program.cs b/AutoInterfaceSample/Program.cs index fa418c6..32ad0fa 100644 --- a/AutoInterfaceSample/Program.cs +++ b/AutoInterfaceSample/Program.cs @@ -41,13 +41,20 @@ interface ITestInterfaceObsolete [Obsolete] [DisallowNull] - ResObject? TestObsoleteProperty { get; } + ResObject? TestObsoleteProperty + { + get; + } + [DisallowNull] + ResObject? TestExpandedProperty + { + [return: MaybeNull] + get; + } } - [Obsolete] - class ResObject; [AttributeUsage(AttributeTargets.All)] diff --git a/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs b/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs index a3197a0..b112009 100644 --- a/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs +++ b/BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs @@ -319,9 +319,7 @@ private void WriteAttribute(SourceBuilder builder, AttributeData attribute, bool private IEnumerable GetParameterAttributes(IParameterSymbol parameter) { - var attributes = parameter.GetAttributes().Where(IsPublicAccess); - - foreach (var attribute in attributes) + foreach (var attribute in parameter.GetAttributes().Where(IsPublicAccess)) { if (attribute.AttributeClass is INamedTypeSymbol attributeClass) { @@ -335,9 +333,7 @@ private IEnumerable GetParameterAttributes(IParameterSymbol param private IEnumerable GetForwardAttributes(ISymbol symbol) { - var attributes = symbol.GetAttributes().Where(IsPublicAccess); - - foreach (var attribute in attributes) + foreach (var attribute in symbol.GetAttributes().Where(IsPublicAccess)) { if (attribute.AttributeClass is INamedTypeSymbol attributeClass) { @@ -353,19 +349,9 @@ private IEnumerable GetForwardAttributes(ISymbol symbol) } } - private IEnumerable GetReturnAttributes(ISymbol symbol) - { - return this.GetReturnAttributes(symbol.GetAttributes()); - } - private IEnumerable GetReturnAttributes(IMethodSymbol method) { - return this.GetReturnAttributes(method.GetReturnTypeAttributes()); - } - - private IEnumerable GetReturnAttributes(IEnumerable attributes) - { - foreach (var attribute in attributes) + foreach (var attribute in method.GetReturnTypeAttributes().Where(IsPublicAccess)) { if (attribute.AttributeClass is INamedTypeSymbol attributeClass) { @@ -601,7 +587,6 @@ 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, this.GetReturnAttributes(property)); builder.AppendIndentation(); this.WriteTypeReference(builder, property.Type, scope); @@ -653,7 +638,6 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope if (property.SetMethod is not null) { this.WriteForwardAttributes(builder, property.SetMethod); - this.WriteReturnAttributes(builder, this.GetReturnAttributes(property.SetMethod)); builder.AppendIndentation(); builder.Append("set => "); @@ -710,7 +694,6 @@ public void WritePropertyDefinition(SourceBuilder builder, IPropertySymbol prope if (property.SetMethod is not null) { this.WriteForwardAttributes(builder, property.SetMethod); - this.WriteReturnAttributes(builder, this.GetReturnAttributes(property.SetMethod)); builder.AppendIndentation(); builder.AppendLine("set"); @@ -770,7 +753,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco PartialTemplate? removerTemplate = this.GetMatchedTemplates(references, AutoInterfaceTargets.EventRemover, @event.Name); this.WriteForwardAttributes(builder, @event); - this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event)); builder.AppendIndentation(); builder.Append("event"); @@ -809,7 +791,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco if (@event.AddMethod != null) { this.WriteForwardAttributes(builder, @event.AddMethod); - this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event.AddMethod)); builder.AppendIndentation(); builder.AppendLine("add"); @@ -854,7 +835,6 @@ public void WriteEventDefinition(SourceBuilder builder, IEventSymbol @event, Sco if (@event.RemoveMethod != null) { this.WriteForwardAttributes(builder, @event.RemoveMethod); - this.WriteReturnAttributes(builder, this.GetReturnAttributes(@event.RemoveMethod)); builder.AppendIndentation(); builder.AppendLine("remove");