New tests.
[mono.git] / mcs / class / corlib / System.Reflection / MonoAssembly.cs
1 //
2 // System.Reflection/MonoAssembly.cs
3 //
4 // Author:
5 //   Rodrigo Kumpera (rkumpera@novell.com)
6 //
7 // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
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 using System;
30 using System.Collections;
31 using System.Globalization;
32 using System.Runtime.InteropServices;
33
34
35 namespace System.Reflection {
36
37 #if NET_4_0
38         [ComVisible (true)]
39         [ComDefaultInterfaceAttribute (typeof (_Assembly))]
40         [Serializable]
41         [ClassInterface(ClassInterfaceType.None)]
42         class MonoAssembly : Assembly {
43 #else
44         public partial class Assembly {
45 #endif
46                 public
47 #if NET_4_0
48                 override
49 #endif
50                 Type GetType (string name, bool throwOnError, bool ignoreCase)
51                 {
52                         if (name == null)
53                                 throw new ArgumentNullException (name);
54                         if (name.Length == 0)
55                         throw new ArgumentException ("name", "Name cannot be empty");
56
57                         return InternalGetType (null, name, throwOnError, ignoreCase);
58                 }
59
60                 public
61 #if NET_4_0
62                 override
63 #endif
64                 Module GetModule (String name)
65                 {
66                         if (name == null)
67                                 throw new ArgumentNullException ("name");
68                         if (name.Length == 0)
69                                 throw new ArgumentException ("Name can't be empty");
70
71                         Module[] modules = GetModules (true);
72                         foreach (Module module in modules) {
73                                 if (module.ScopeName == name)
74                                         return module;
75                         }
76
77                         return null;
78                 }
79
80                 public
81 #if NET_4_0
82                 override
83 #endif
84                 AssemblyName[] GetReferencedAssemblies () {
85                         return GetReferencedAssemblies (this);
86                 }
87
88                 public
89 #if NET_4_0
90                 override
91 #endif
92                 Module[] GetModules (bool getResourceModules) {
93                         Module[] modules = GetModulesInternal ();
94
95                         if (!getResourceModules) {
96                                 ArrayList result = new ArrayList (modules.Length);
97                                 foreach (Module m in modules)
98                                         if (!m.IsResource ())
99                                                 result.Add (m);
100                                 return (Module[])result.ToArray (typeof (Module));
101                         }
102                         else
103                                 return modules;
104                 }
105
106                 [MonoTODO ("Always returns the same as GetModules")]
107                 public
108 #if NET_4_0
109                 override
110 #endif
111                 Module[] GetLoadedModules (bool getResourceModules)
112                 {
113                         return GetModules (getResourceModules);
114                 }
115
116                 public
117 #if NET_4_0
118                 override
119 #endif
120                 Assembly GetSatelliteAssembly (CultureInfo culture)
121                 {
122                         return GetSatelliteAssembly (culture, null, true);
123                 }
124
125                 public
126 #if NET_4_0
127                 override
128 #endif
129                 Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
130                 {
131                         return GetSatelliteAssembly (culture, version, true);
132                 }
133
134                 //FIXME remove GetManifestModule under v4, it's a v2 artifact
135                 [ComVisible (false)]
136                 public
137 #if NET_4_0
138                 override
139 #endif
140                 Module ManifestModule {
141                         get {
142                                 return GetManifestModule ();
143                         }
144                 }
145
146 #if !MOONLIGHT
147                 public
148 #if NET_4_0
149                 override
150 #endif
151                 bool GlobalAssemblyCache {
152                         get {
153                                 return get_global_assembly_cache ();
154                         }
155                 }
156 #endif
157
158         }
159 }
160
161