[ilasm] Extend syntax of custom attribute constructor constants
[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                 PEAPI.Constant constant;
24                 public CustomAttr (BaseMethodRef method_ref, PEAPI.Constant constant)
25                 {
26                     this.method_ref = method_ref;
27                     this.constant = constant;
28                 }
29
30                 public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
31                 {
32                         method_ref.Resolve (code_gen);
33                         code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, constant, elem);
34                 }
35
36                 public bool IsSuppressUnmanaged (CodeGen codegen)
37                 {
38                         string asmname = "";
39                         
40                         BaseTypeRef owner = method_ref.Owner;
41                         if (owner == null)
42                                 return false;
43                                 
44                         ExternTypeRef etr = owner as ExternTypeRef;
45                         if (etr != null) {
46                                 ExternAssembly ea = etr.ExternRef as ExternAssembly;
47                                 if (ea != null)
48                                         asmname = ea.Name;
49                         }       
50
51                         return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute" 
52                                 && (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );
53                 }
54         }
55
56 }
57