2006-11-14 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / ilasm / codegen / CustomAttr.cs
index 0bfe7dcea5f371c5be7f733c549fe7b8b296e9df..964a2ff6b630a51f6e9d2a7ec0f04f7758d3377f 100644 (file)
@@ -9,16 +9,20 @@
 
 
 using System;
-
+using System.Collections;
 
 namespace Mono.ILASM {
 
+        public interface ICustomAttrTarget {
+                void AddCustomAttribute (CustomAttr customattr);
+        }
+
         public class CustomAttr {
 
-                private IMethodRef method_ref;
+                private BaseMethodRef method_ref;
                 private byte[] data;
 
-                public CustomAttr (IMethodRef method_ref, byte[] data)
+                public CustomAttr (BaseMethodRef method_ref, byte[] data)
                 {
                         this.method_ref = method_ref;
                         this.data = data;
@@ -27,10 +31,27 @@ namespace Mono.ILASM {
                 public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
                 {
                         method_ref.Resolve (code_gen);
-
-                        elem.AddCustomAttribute (method_ref.PeapiMethod, data);
+                        code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
                 }
 
+                public bool IsSuppressUnmanaged (CodeGen codegen)
+                {
+                       string asmname = "";
+                       
+                       BaseTypeRef owner = method_ref.Owner;
+                       if (owner == null)
+                               return false;
+                               
+                       ExternTypeRef etr = owner as ExternTypeRef;
+                       if (etr != null) {
+                               ExternAssembly ea = etr.ExternRef as ExternAssembly;
+                               if (ea != null)
+                                       asmname = ea.Name;
+                       }       
+
+                               return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute" 
+                               && (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );
+                }
         }
 
 }