Browse Source

Added work around for issue #73.

But needs to be fixed on parser level.
pull/45/merge
Mike Krüger 12 years ago
parent
commit
a1bdce98ef
  1. 9
      ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs
  2. 16
      ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

9
ICSharpCode.NRefactory.CSharp/Parser/CSharpParser.cs

@ -103,7 +103,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -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 @@ -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);
}
}

16
ICSharpCode.NRefactory.Tests/CSharp/Parser/TypeSystemConvertVisitorTests.cs

@ -99,6 +99,22 @@ namespace ICSharpCode.NRefactory.CSharp.Parser @@ -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]

Loading…
Cancel
Save