Merge pull request #1931 from kasthack/system.web-fixes
[mono.git] / mcs / ilasm / codegen / Assembly.cs
1 //
2 // Mono.ILASM.Assembly
3 //
4 // Represents .assembly { }
5 //
6 // Author(s):
7 //  Ankit Jain  <JAnkit@novell.com>
8 //
9 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31
32 using System.Collections;
33
34 namespace Mono.ILASM {
35
36         public class Assembly : IDeclSecurityTarget, ICustomAttrTarget 
37         {
38                 private DeclSecurity decl_sec;
39                 private ArrayList customattr_list;
40
41                 private string name;
42                 private byte [] public_key;
43                 private int major_version;
44                 private int minor_version;
45                 private int build_version;
46                 private int revision_version;
47                 private string locale;
48                 private int hash_algorithm;
49                 private PEAPI.AssemAttr attr;
50
51                 public Assembly (string name)
52                 {
53                         this.name = name;
54                 }
55
56                 public string Name {
57                         get { return name; }
58                 }
59
60                 public DeclSecurity DeclSecurity {
61                         get { 
62                                 if (decl_sec == null)
63                                         decl_sec = new DeclSecurity ();
64                                 return decl_sec; 
65                         }
66                 }
67
68                 public void SetVersion (int major, int minor, int build, int revision)
69                 {
70                         this.major_version = major;
71                         this.minor_version = minor;
72                         this.build_version = build;
73                         this.revision_version = revision;
74                 }
75
76                 public void SetLocale (string locale)
77                 {
78                         this.locale = locale;
79                 }
80
81                 public void SetHashAlgorithm (int algorithm)
82                 {
83                         hash_algorithm = algorithm;
84                 }
85
86                 public void SetPublicKey (byte [] public_key)
87                 {
88                         this.public_key = public_key;
89                 }
90
91                 public void SetAssemblyAttr (PEAPI.AssemAttr attr)
92                 {
93                         this.attr = attr;
94                 }
95
96                 public void AddCustomAttribute (CustomAttr customattr)
97                 {
98                         if (customattr_list == null)
99                                 customattr_list = new ArrayList ();
100
101                         customattr_list.Add (customattr);
102                 }
103
104                 public void Resolve (CodeGen code_gen, PEAPI.Assembly asm)
105                 {
106                         if (customattr_list != null)
107                                 foreach (CustomAttr customattr in customattr_list) {
108                                         customattr.AddTo (code_gen, asm);
109                                 }
110                         
111                         if (decl_sec != null)
112                                 decl_sec.AddTo (code_gen, asm);
113
114
115                         asm.AddAssemblyInfo(major_version,
116                                 minor_version, build_version,
117                                 revision_version, public_key,
118                                 (uint) hash_algorithm, locale);
119
120                         asm.AddAssemblyAttr (attr);
121                 }
122         }
123 }