New test.
[mono.git] / mcs / ilasm / codegen / CustomAttr.cs
1 //
2 // Mono.ILASM.CustomAttr
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public interface ICustomAttrTarget {
17                 void AddCustomAttribute (CustomAttr customattr);
18         }
19
20         public class CustomAttr {
21
22                 private BaseMethodRef method_ref;
23                 private byte[] data;
24
25                 public CustomAttr (BaseMethodRef method_ref, byte[] data)
26                 {
27                         this.method_ref = method_ref;
28                         this.data = data;
29                 }
30
31                 public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
32                 {
33                         method_ref.Resolve (code_gen);
34                         code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
35                 }
36
37                 public bool IsSuppressUnmanaged (CodeGen codegen)
38                 {
39                         string asmname = "";
40                         
41                         BaseTypeRef owner = method_ref.Owner;
42                         if (owner == null)
43                                 return false;
44                                 
45                         ExternTypeRef etr = owner as ExternTypeRef;
46                         if (etr != null) {
47                                 ExternAssembly ea = etr.ExternRef as ExternAssembly;
48                                 if (ea != null)
49                                         asmname = ea.Name;
50                         }       
51
52                         return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute" 
53                                 && (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );
54                 }
55         }
56
57 }
58