/ICSharpCode.Decompiler/Tests/Helpers/RemoveCompilerAttribute.cs

http://github.com/icsharpcode/ILSpy · C# · 38 lines · 35 code · 3 blank · 0 comment · 19 complexity · bdd856e97b636839c633784765fd8d48 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSharpCode.Decompiler.Ast.Transforms;
  6. using ICSharpCode.NRefactory.CSharp;
  7. namespace ICSharpCode.Decompiler.Tests.Helpers
  8. {
  9. class RemoveCompilerAttribute : DepthFirstAstVisitor<object, object>, IAstTransform
  10. {
  11. public override object VisitAttribute(NRefactory.CSharp.Attribute attribute, object data)
  12. {
  13. var section = (AttributeSection)attribute.Parent;
  14. SimpleType type = attribute.Type as SimpleType;
  15. if (section.AttributeTarget == "assembly" &&
  16. (type.Identifier == "CompilationRelaxations" || type.Identifier == "RuntimeCompatibility" || type.Identifier == "SecurityPermission" || type.Identifier == "AssemblyVersion" || type.Identifier == "Debuggable"))
  17. {
  18. attribute.Remove();
  19. if (section.Attributes.Count == 0)
  20. section.Remove();
  21. }
  22. if (section.AttributeTarget == "module" && type.Identifier == "UnverifiableCode")
  23. {
  24. attribute.Remove();
  25. if (section.Attributes.Count == 0)
  26. section.Remove();
  27. }
  28. return null;
  29. }
  30. public void Run(AstNode node)
  31. {
  32. node.AcceptVisitor(this, null);
  33. }
  34. }
  35. }