2003-12-08 Patrik Torstensson <p@rxc.se>
[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                 public Assembly Assembly {
35                         get { return assembly; }
36                 }
37         
38                 public virtual string FullyQualifiedName {
39                         get { return fqname; }
40                 }
41         
42                 public string Name {
43                         get { return name; }
44                 }
45         
46                 public string ScopeName {
47                         get { return scopename; }
48                 }
49         
50                 [MonoTODO]
51                 public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria) 
52                 {
53                         return null;
54                 }
55         
56                 public virtual object[] GetCustomAttributes(bool inherit) 
57                 {
58                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
59                 }
60         
61                 public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) 
62                 {
63                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
64                 }
65         
66                 public FieldInfo GetField (string name) 
67                 {
68                         if (IsResource ())
69                                 return null;
70
71                         return GetGlobalType ().GetField (name, BindingFlags.Public | BindingFlags.Static);
72                 }
73         
74                 public FieldInfo GetField (string name, BindingFlags flags) 
75                 {
76                         if (IsResource ())
77                                 return null;
78
79                         return GetGlobalType ().GetField (name, flags);
80                 }
81         
82                 public FieldInfo[] GetFields () 
83                 {
84                         if (IsResource ())
85                                 return new FieldInfo [0];
86
87                         return GetGlobalType ().GetFields (BindingFlags.Public | BindingFlags.Static);
88                 }
89         
90                 [MonoTODO]
91                 public MethodInfo GetMethod (string name) 
92                 {
93                         if (IsResource ())
94                                 return null;
95
96                         return null;
97                 }
98         
99                 [MonoTODO]
100                 public MethodInfo GetMethod (string name, Type[] types) 
101                 {
102                         if (IsResource ())
103                                 return null;
104
105                         return null;
106                 }
107         
108                 [MonoTODO]
109                 public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) 
110                 {
111                         if (IsResource ())
112                                 return null;
113
114                         return null;
115                 }
116         
117                 [MonoTODO]
118                 protected virtual MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) 
119                 {
120                         if (IsResource ())
121                                 return null;
122
123                         return null;
124                 }
125         
126                 [MonoTODO]
127                 public MethodInfo[] GetMethods () 
128                 {
129                         if (IsResource ())
130                                 return new MethodInfo [0];
131
132                         return null;
133                 }
134         
135                 [MonoTODO]
136                 public virtual void GetObjectData (SerializationInfo info, StreamingContext context) 
137                 {
138                 }
139         
140                 public X509Certificate GetSignerCertificate ()
141                 {
142                         try {
143                                 return X509Certificate.CreateFromSignedFile (assembly.Location);
144                         }
145                         catch {
146                                 return null;
147                         }
148                 }
149         
150                 public virtual Type GetType(string className) 
151                 {
152                         return GetType (className, false, false);
153                 }
154         
155                 public virtual Type GetType(string className, bool ignoreCase) 
156                 {
157                         return GetType (className, false, ignoreCase);
158                 }
159         
160                 public virtual Type GetType(string className, bool throwOnError, bool ignoreCase) 
161                 {
162                         if (className == null)
163                                 throw new ArgumentNullException ("className");
164                         if (className == String.Empty)
165                                 throw new ArgumentException ("Type name can't be empty");
166                         return assembly.InternalGetType (this, className, throwOnError, ignoreCase);
167                 }
168
169                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
170                 private extern Type[] InternalGetTypes ();
171         
172                 public virtual Type[] GetTypes() 
173                 {
174                         return InternalGetTypes ();
175                 }
176         
177                 public virtual bool IsDefined (Type attributeType, bool inherit) 
178                 {
179                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
180                 }
181         
182                 public bool IsResource()
183                 {
184                         return is_resource;
185                 }
186         
187                 public override string ToString () 
188                 {
189                         return "Reflection.Module: " + name;
190                 }
191
192                 // Mono Extension: returns the GUID of this module
193                 public Guid Mono_GetGuid ()
194                 {
195                         return new Guid (GetGuidInternal ());
196                 }
197
198                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
199                 private extern string GetGuidInternal ();
200
201                 [MethodImplAttribute (MethodImplOptions.InternalCall)]
202                 private extern Type GetGlobalType ();
203         }
204 }