But needs to be fixed on parser level.
@ -103,7 +103,9 @@ namespace ICSharpCode.NRefactory.CSharp
first = false;
if (mc.OptAttributes != null) {
foreach (var attr in mc.OptAttributes.Sections) {
unit.AddChild (ConvertAttributeSection (attr), SyntaxTree.MemberRole);
var section = ConvertAttributeSection(attr);
if (section != null)
unit.AddChild (section, SyntaxTree.MemberRole);
}
@ -958,8 +960,9 @@ namespace ICSharpCode.NRefactory.CSharp
return;
foreach (var attr in attrs.Sections) {
parent.AddChild (section, role);
if (section == null || section.AttributeTarget == "module" || section.AttributeTarget == "assembly")
continue;
@ -99,6 +99,22 @@ namespace ICSharpCode.NRefactory.CSharp.Parser
Assert.IsTrue (field.IsConst);
Assert.IsNull (field.ConstantValue);
[Test]
public void AssemblyAndModuleAttributesDoNotAppearOnTypes()
{
var parser = new CSharpParser();
var cu = parser.Parse("[assembly: My1][module: My2][My3]class C {} public class My1Attribute : System.Attribute {} public class My2Attribute : System.Attribute {} public class My3Attribute : System.Attribute {}", "File.cs");
var ts = cu.ToTypeSystem();
var compilation = new CSharpProjectContent()
.UpdateProjectContent(null, ts)
.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
.CreateCompilation();
var type = ReflectionHelper.ParseReflectionName("C").Resolve(compilation).GetDefinition();
Assert.That(type.Attributes.Select(a => a.AttributeType.FullName).ToList(), Is.EqualTo(new[] { "My3Attribute" }));
[TestFixture]