Debian Codegraph @

mcs/tools/cil-strip/Mono.Cecil/AssemblyDefinition.cs

raw
1 //
2 // AssemblyDefinition.cs
3 //
4 // Author:
5 // Jb Evain ([email protected])
6 //
7 // (C) 2005 Jb Evain
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 namespace Mono.Cecil {
30
31 using System;
32 using System.Collections;
33
34 using Mono.Cecil.Metadata;
35
36 internal class AssemblyDefinition : ICustomAttributeProvider,
37 IHasSecurity, IAnnotationProvider, IReflectionStructureVisitable {
38
39 MetadataToken m_token;
40 AssemblyNameDefinition m_asmName;
41 ModuleDefinitionCollection m_modules;
42 SecurityDeclarationCollection m_secDecls;
43 CustomAttributeCollection m_customAttrs;
44 MethodDefinition m_ep;
45 TargetRuntime m_runtime;
46 AssemblyKind m_kind;
47
48 ModuleDefinition m_mainModule;
49 StructureReader m_reader;
50
51 IAssemblyResolver m_resolver;
52 IDictionary m_annotations;
53
54 public MetadataToken MetadataToken {
55 get { return m_token; }
56 set { m_token = value; }
57 }
58
59 public AssemblyNameDefinition Name {
60 get { return m_asmName; }
61 }
62
63 public ModuleDefinitionCollection Modules {
64 get { return m_modules; }
65 }
66
67 public bool HasSecurityDeclarations {
68 get { return (m_secDecls == null) ? false : (m_secDecls.Count > 0); }
69 }
70
71 public SecurityDeclarationCollection SecurityDeclarations {
72 get {
73 if (m_secDecls == null)
74 m_secDecls = new SecurityDeclarationCollection (this);
75
76 return m_secDecls;
77 }
78 }
79
80 public bool HasCustomAttributes {
81 get { return (m_customAttrs == null) ? false : (m_customAttrs.Count > 0); }
82 }
83
84 public CustomAttributeCollection CustomAttributes {
85 get {
86 if (m_customAttrs == null)
87 m_customAttrs = new CustomAttributeCollection (this);
88
89 return m_customAttrs;
90 }
91 }
92
93 public MethodDefinition EntryPoint {
94 get { return m_ep; }
95 set { m_ep = value; }
96 }
97
98 public TargetRuntime Runtime {
99 get { return m_runtime; }
100 set { m_runtime = value; }
101 }
102
103 public AssemblyKind Kind {
104 get { return m_kind; }
105 set { m_kind = value; }
106 }
107
108 public ModuleDefinition MainModule {
109 get {
110 if (m_mainModule == null) {
111 foreach (ModuleDefinition module in m_modules) {
112 if (module.Main) {
113 m_mainModule = module;
114 break;
115 }
116 }
117 }
118 return m_mainModule;
119 }
120 }
121
122 internal StructureReader Reader {
123 get { return m_reader; }
124 }
125
126 public IAssemblyResolver Resolver {
127 get { return m_resolver; }
128 set { m_resolver = value; }
129 }
130
131 IDictionary IAnnotationProvider.Annotations {
132 get {
133 if (m_annotations == null)
134 m_annotations = new Hashtable ();
135 return m_annotations;
136 }
137 }
138
139 internal AssemblyDefinition (AssemblyNameDefinition name)
140 {
141 if (name == null)
142 throw new ArgumentNullException ("name");
143
144 m_asmName = name;
145 m_modules = new ModuleDefinitionCollection (this);
146 m_resolver = new DefaultAssemblyResolver ();
147 }
148
149 internal AssemblyDefinition (AssemblyNameDefinition name, StructureReader reader) : this (name)
150 {
151 m_reader = reader;
152 }
153
154 public void Accept (IReflectionStructureVisitor visitor)
155 {
156 visitor.VisitAssemblyDefinition (this);
157
158 m_asmName.Accept (visitor);
159 m_modules.Accept (visitor);
160
161 visitor.TerminateAssemblyDefinition (this);
162 }
163
164 public override string ToString ()
165 {
166 return m_asmName.FullName;
167 }
168 }
169 }