Merge pull request #1857 from slluis/fix-assembly-resolver
[mono.git] / mcs / ilasm / codegen / CustomAttr.cs
index ca34849d1aae0afee667abec88798d107b3331f6..f6b17700acaa9307169843bbf1978424899a935c 100644 (file)
@@ -19,21 +19,38 @@ namespace Mono.ILASM {
 
         public class CustomAttr {
 
-                private IMethodRef method_ref;
-                private byte[] data;
-
-                public CustomAttr (IMethodRef method_ref, byte[] data)
+                private BaseMethodRef method_ref;
+                PEAPI.Constant constant;
+                public CustomAttr (BaseMethodRef method_ref, PEAPI.Constant constant)
                 {
-                        this.method_ref = method_ref;
-                        this.data = data;
+                    this.method_ref = method_ref;
+                    this.constant = constant;
                 }
 
                 public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
                 {
                         method_ref.Resolve (code_gen);
-                        code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
+                        code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, constant, 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")) );
+                }
         }
 
 }