diff --git a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs index d147fa87e5..2e4c34f0d0 100644 --- a/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs +++ b/ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs @@ -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) { var section = ConvertAttributeSection(attr); - if (section != null) - parent.AddChild (section, role); + if (section == null || section.AttributeTarget == "module" || section.AttributeTarget == "assembly") + continue; + parent.AddChild (section, role); } } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs index cd339dc575..5306bf70b6 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs @@ -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]