2004-02-25 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection / Module.cs
1 //
2 // System.Reflection/Module.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11 using System.Reflection;
12 using System.Runtime.Serialization;
13 using System.Security.Cryptography.X509Certificates;
14 using System.Runtime.InteropServices;
15 using System.Runtime.CompilerServices;
16
17 namespace System.Reflection {
18
19         [Serializable]
20         public class Module : ISerializable, ICustomAttributeProvider {
21         
22                 public static readonly TypeFilter FilterTypeName;
23                 public static readonly TypeFilter FilterTypeNameIgnoreCase;
24         
25                 private IntPtr _impl; /* a pointer to a MonoImage */
26                 internal Assembly assembly;
27                 internal string fqname;
28                 internal string name;
29                 internal string scopename;
30                 internal bool is_resource;
31         
32                 internal Module () { }
33
34                 ~Module () {
35                         Close ();
36                 }
37         
38                 public Assembly Assembly {
39                         get { return assembly; }
40                 }
41         
42                 public virtual string FullyQualifiedName {
43                         get { return fqname; }
44                 }
45         
46                 public string Name {
47                         get { return name; }
48                 }
49         
50                 public string ScopeName {
51                         get { return scopename; }
52                 }
53         
54                 [MonoTODO]
55                 public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria) 
56                 {
57                         return null;
58                 }
59         
60                 public virtual object[] GetCustomAttributes(bool inherit) 
61                 {
62                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
63                 }
64         
65                 public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) 
66                 {
67                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
68                 }
69         
70                 public FieldInfo GetField (string name) 
71                 {
72                         if (IsResource ())
73                                 return null;
74
75                         return GetGlobalType ().GetField (name, BindingFlags.Public | BindingFlags.Static);
76                 }
77         
78                 public FieldInfo GetField (string name, BindingFlags flags) 
79                 {
80                         if (IsResource ())
81                                 return null;
82
83                         return GetGlobalType ().GetField (name, flags);
84                 }
85         
86                 public FieldInfo[] GetFields () 
87                 {
88                         if (IsResource ())
89                                 return new FieldInfo [0];
90
91                         return GetGlobalType ().GetFields (BindingFlags.Public | BindingFlags.Static);
92                 }
93         
94                 [MonoTODO]
95                 public MethodInfo GetMethod (string name) 
96                 {
97                         if (IsResource ())
98                                 return null;
99
100                         return null;
101                 }
102         
103                 [MonoTODO]
104                 public MethodInfo GetMethod (string name, Type[] types) 
105                 {
106                         if (IsResource ())
107                                 return null;
108
109                         return null;
110                 }
111         
112                 [MonoTODO]
113                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) 
114                 {
115                         if (IsResource ())
116                                 return null;
117
118                         return null;
119                 }
120         
121                 [MonoTODO]
122                 protected virtual MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) 
123                 {
124                         if (IsResource ())
125                                 return null;
126
127                         return null;
128                 }
129         
130                 [MonoTODO]
131                 public MethodInfo[] GetMethods () 
132                 {
133                         if (IsResource ())
134                                 return new MethodInfo [0];
135
136                         return null;
137                 }
138         
139                 [MonoTODO]
140                 public virtual void GetObjectData (SerializationInfo info, StreamingContext context) 
141                 {
142                 }
143         
144                 public X509Certificate GetSignerCertificate ()
145                 {
146                         try {
147                                 return X509Certificate.CreateFromSignedFile (assembly.Location);
148                         }
149                         catch {
150                                 return null;
151                         }
152                 }
153         
154                 public virtual Type GetType(string className) 
155                 {
156                         return GetType (className, false, false);
157                 }
158         
159                 public virtual Type GetType(string className, bool ignoreCase) 
160                 {
161                         return GetType (className, false, ignoreCase);
162                 }
163         
164                 public virtual Type GetType(string className, bool throwOnError, bool ignoreCase) 
165                 {
166                         if (className == null)
167                                 throw new ArgumentNullException ("className");
168                         if (className == String.Empty)
169                                 throw new ArgumentException ("Type name can't be empty");
170                         return assembly.InternalGetType (this, className, throwOnError, ignoreCase);
171                 }
172
173                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
174                 private extern Type[] InternalGetTypes ();
175         
176                 public virtual Type[] GetTypes() 
177                 {
178                         return InternalGetTypes ();
179                 }
180         
181                 public virtual bool IsDefined (Type attributeType, bool inherit) 
182                 {
183                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
184                 }
185         
186                 public bool IsResource()
187                 {
188                         return is_resource;
189                 }
190         
191                 public override string ToString () 
192                 {
193                         return "Reflection.Module: " + name;
194                 }
195
196                 // Mono Extension: returns the GUID of this module
197                 public Guid Mono_GetGuid ()
198                 {
199                         return new Guid (GetGuidInternal ());
200                 }
201
202                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
203                 private extern string GetGuidInternal ();
204
205                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
206                 private extern Type GetGlobalType ();
207
208                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
209                 private extern void Close ();
210         }
211 }