Skip to content

Commit

Permalink
attributes with internall access will be emitted without assembly alias
Browse files Browse the repository at this point in the history
  • Loading branch information
beakona committed Mar 19, 2024
1 parent 54fc462 commit 22ce053
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 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.39</Version>
<Version>1.0.40</Version>
<IsRoslynComponent>true</IsRoslynComponent>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>
Expand Down
85 changes: 47 additions & 38 deletions BeaKona.AutoInterfaceGenerator/CSharpCodeTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void WriteParameterAttributes(SourceBuilder builder, ScopeInfo scope, IPa

foreach (var attribute in GetParameterAttributes(parameter))
{
this.WriteAttribute(builder, scope, attribute);
this.WriteAttribute(builder, scope, attribute, false);
any = true;
}

Expand Down Expand Up @@ -288,7 +288,7 @@ private void WriteForwardAttributes(SourceBuilder builder, ScopeInfo scope, ISym
foreach (var attribute in this.GetForwardAttributes(member))
{
builder.AppendIndentation();
this.WriteAttribute(builder, scope, attribute);
this.WriteAttribute(builder, scope, attribute, true);
builder.AppendLine();
}
}
Expand All @@ -300,60 +300,69 @@ private void WriteReturnAttributes(SourceBuilder builder, ScopeInfo scope, IEnum
foreach (var attribute in attributes)
{
builder.AppendIndentation();
this.WriteAttribute(builder, scope, attribute, true);
this.WriteAttribute(builder, scope, attribute, false, true);
builder.AppendLine();
}
}
}

private void WriteAttributeReference(SourceBuilder builder, ScopeInfo scope, AttributeData attribute)
private void WriteAttributeReference(SourceBuilder builder, ScopeInfo scope, AttributeData attribute, bool strict)
{
if (attribute.AttributeClass is INamedTypeSymbol attributeTypeSymbol)
if (attribute.AttributeClass is INamedTypeSymbol attributeClass)
{
if (Helpers.IsPublicAccess(attributeTypeSymbol) == false)
{
builder.MissingAttributesRegistry.Add(attributeTypeSymbol);
}
bool publicAccess = Helpers.IsPublicAccess(attributeClass);

this.WriteTypeReference(builder, attributeTypeSymbol, scope);

if (attribute.ConstructorArguments.Any() || attribute.NamedArguments.Any())
if (strict || publicAccess)
{
builder.Append('(');
if (publicAccess == false)
{
builder.MissingAttributesRegistry.Add(attributeClass);
}

bool first = true;
this.WriteTypeReference(builder, attributeClass, scope);

foreach (var constructorArgument in attribute.ConstructorArguments)
if (attribute.ConstructorArguments.Any() || attribute.NamedArguments.Any())
{
if (first)
{
first = false;
}
else
{
builder.Append(", ");
}
builder.Append('(');

builder.Append(constructorArgument.ToCSharpString());
}
bool first = true;

foreach (var namedArgument in attribute.NamedArguments)
{
if (first)
foreach (var constructorArgument in attribute.ConstructorArguments)
{
first = false;
if (first)
{
first = false;
}
else
{
builder.Append(", ");
}

builder.Append(constructorArgument.ToCSharpString());
}
else

foreach (var namedArgument in attribute.NamedArguments)
{
builder.Append(", ");
if (first)
{
first = false;
}
else
{
builder.Append(", ");
}

builder.Append(namedArgument.Key);
builder.Append(" = ");
builder.Append(namedArgument.Value.ToCSharpString());
}

builder.Append(namedArgument.Key);
builder.Append(" = ");
builder.Append(namedArgument.Value.ToCSharpString());
builder.Append(')');
}

builder.Append(')');
}
else
{
builder.Append(attribute.ToString());
}
}
else
Expand All @@ -362,14 +371,14 @@ private void WriteAttributeReference(SourceBuilder builder, ScopeInfo scope, Att
}
}

private void WriteAttribute(SourceBuilder builder, ScopeInfo scope, AttributeData attribute, bool isReturn = false)
private void WriteAttribute(SourceBuilder builder, ScopeInfo scope, AttributeData attribute, bool strict, bool isReturn = false)
{
builder.Append('[');
if (isReturn)
{
builder.Append("return: ");
}
this.WriteAttributeReference(builder, scope, attribute);
this.WriteAttributeReference(builder, scope, attribute, strict);
builder.Append(']');
}

Expand Down

0 comments on commit 22ce053

Please sign in to comment.