Version Used: 4.2.0-2.22128.1
Steps to Reproduce:
- Get a
SyntaxGenerator instance for a C# workspace (VB probably has the same bug) and name it gen.
- Run the following code snippet:
var root = gen.CompliationUnit();
root = gen.AddAttributes(root, gen.Attribute(gen.DottedName("Namespace.FirstAttribute")));
root = gen.AddAttributes(root, gen.Attribute(gen.DottedName("Namespace.SecondAttribute")));
Expected Behavior: Both attribute lists for FirstAttribute and SecondAttribute have the assembly: target specifier.
Actual Behavior: Only FirstAttribute has the target specifier.
This is bug is due to the fact that the path where CSharpSyntaxGenerator adds the specifier is only called when no attributes currently exist on the parent syntax node. In the provided code snippet, the WithAttributeLists method adds the target specifier; however, it is only called when there are no existing attributes.
|
private SyntaxNode InsertAttributesInternal(SyntaxNode declaration, int index, IEnumerable<SyntaxNode> attributes) |
|
{ |
|
var newAttributes = AsAttributeLists(attributes); |
|
|
|
var existingAttributes = this.GetAttributes(declaration); |
|
if (index >= 0 && index < existingAttributes.Count) |
|
{ |
|
return this.InsertNodesBefore(declaration, existingAttributes[index], newAttributes); |
|
} |
|
else if (existingAttributes.Count > 0) |
|
{ |
|
return this.InsertNodesAfter(declaration, existingAttributes[existingAttributes.Count - 1], newAttributes); |
|
} |
|
else |
|
{ |
|
var lists = declaration.GetAttributeLists(); |
|
var newList = lists.AddRange(newAttributes); |
|
return WithAttributeLists(declaration, newList); |
|
} |
|
} |
Version Used: 4.2.0-2.22128.1
Steps to Reproduce:
SyntaxGeneratorinstance for a C# workspace (VB probably has the same bug) and name itgen.Expected Behavior: Both attribute lists for
FirstAttributeandSecondAttributehave theassembly:target specifier.Actual Behavior: Only
FirstAttributehas the target specifier.This is bug is due to the fact that the path where
CSharpSyntaxGeneratoradds the specifier is only called when no attributes currently exist on the parent syntax node. In the provided code snippet, theWithAttributeListsmethod adds the target specifier; however, it is only called when there are no existing attributes.roslyn/src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
Lines 994 to 1013 in 696fe63