PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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