2010-06-03 Jb Evain <jbevain@novell.com>
[mcs.git] / ilasm / codegen / CustomAttr.cs
blob964a2ff6b630a51f6e9d2a7ec0f04f7758d3377f
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 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public interface ICustomAttrTarget {
17 void AddCustomAttribute (CustomAttr customattr);
20 public class CustomAttr {
22 private BaseMethodRef method_ref;
23 private byte[] data;
25 public CustomAttr (BaseMethodRef method_ref, byte[] data)
27 this.method_ref = method_ref;
28 this.data = data;
31 public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem)
33 method_ref.Resolve (code_gen);
34 code_gen.PEFile.AddCustomAttribute (method_ref.PeapiMethod, data, elem);
37 public bool IsSuppressUnmanaged (CodeGen codegen)
39 string asmname = "";
41 BaseTypeRef owner = method_ref.Owner;
42 if (owner == null)
43 return false;
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;
52 return (owner.FullName == "System.Security.SuppressUnmanagedCodeSecurityAttribute"
53 && (asmname == "mscorlib" || codegen.IsThisAssembly ("mscorlib")) );