Merge branch 'sgen-android'
[mono.git] / mcs / class / IKVM.Reflection / Missing.cs
1 /*
2   Copyright (C) 2011 Jeroen Frijters
3
4   This software is provided 'as-is', without any express or implied
5   warranty.  In no event will the authors be held liable for any damages
6   arising from the use of this software.
7
8   Permission is granted to anyone to use this software for any purpose,
9   including commercial applications, and to alter it and redistribute it
10   freely, subject to the following restrictions:
11
12   1. The origin of this software must not be misrepresented; you must not
13      claim that you wrote the original software. If you use this software
14      in a product, an acknowledgment in the product documentation would be
15      appreciated but is not required.
16   2. Altered source versions must be plainly marked as such, and must not be
17      misrepresented as being the original software.
18   3. This notice may not be removed or altered from any source distribution.
19
20   Jeroen Frijters
21   jeroen@frijters.net
22   
23 */
24 using System;
25 using System.Collections.Generic;
26 using System.Runtime.InteropServices;
27
28 namespace IKVM.Reflection
29 {
30         [Serializable]
31         public sealed class MissingAssemblyException : InvalidOperationException
32         {
33                 [NonSerialized]
34                 private readonly MissingAssembly assembly;
35
36                 internal MissingAssemblyException(MissingAssembly assembly)
37                         : base("Assembly '" + assembly.FullName + "' is a missing assembly and does not support the requested operation.")
38                 {
39                         this.assembly = assembly;
40                 }
41
42                 private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
43                         : base(info, context)
44                 {
45                 }
46
47                 public Assembly Assembly
48                 {
49                         get { return assembly; }
50                 }
51         }
52
53         [Serializable]
54         public sealed class MissingModuleException : InvalidOperationException
55         {
56                 [NonSerialized]
57                 private readonly MissingModule module;
58
59                 internal MissingModuleException(MissingModule module)
60                         : base("Module from missing assembly '" + module.Assembly.FullName + "' does not support the requested operation.")
61                 {
62                         this.module = module;
63                 }
64
65                 private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
66                         : base(info, context)
67                 {
68                 }
69
70                 public Module Module
71                 {
72                         get { return module; }
73                 }
74         }
75
76         [Serializable]
77         public sealed class MissingMemberException : InvalidOperationException
78         {
79                 [NonSerialized]
80                 private readonly MemberInfo member;
81
82                 internal MissingMemberException(MemberInfo member)
83                         : base("Member '" + member + "' is a missing member and does not support the requested operation.")
84                 {
85                         this.member = member;
86                 }
87
88                 private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
89                         : base(info, context)
90                 {
91                 }
92
93                 public MemberInfo MemberInfo
94                 {
95                         get { return member; }
96                 }
97         }
98
99         sealed class MissingAssembly : Assembly
100         {
101                 private readonly MissingModule module;
102                 private readonly string name;
103
104                 internal MissingAssembly(Universe universe, string name)
105                         : base(universe)
106                 {
107                         module = new MissingModule(this);
108                         this.name = name;
109                 }
110
111                 public override Type[] GetTypes()
112                 {
113                         throw new MissingAssemblyException(this);
114                 }
115
116                 public override string FullName
117                 {
118                         get { return name; }
119                 }
120
121                 public override AssemblyName GetName()
122                 {
123                         return new AssemblyName(name);
124                 }
125
126                 public override string ImageRuntimeVersion
127                 {
128                         get { throw new MissingAssemblyException(this); }
129                 }
130
131                 public override Module ManifestModule
132                 {
133                         get { return module; }
134                 }
135
136                 public override MethodInfo EntryPoint
137                 {
138                         get { throw new MissingAssemblyException(this); }
139                 }
140
141                 public override string Location
142                 {
143                         get { throw new MissingAssemblyException(this); }
144                 }
145
146                 public override AssemblyName[] GetReferencedAssemblies()
147                 {
148                         throw new MissingAssemblyException(this);
149                 }
150
151                 public override Module[] GetModules(bool getResourceModules)
152                 {
153                         throw new MissingAssemblyException(this);
154                 }
155
156                 public override Module[] GetLoadedModules(bool getResourceModules)
157                 {
158                         throw new MissingAssemblyException(this);
159                 }
160
161                 public override Module GetModule(string name)
162                 {
163                         throw new MissingAssemblyException(this);
164                 }
165
166                 public override string[] GetManifestResourceNames()
167                 {
168                         throw new MissingAssemblyException(this);
169                 }
170
171                 public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
172                 {
173                         throw new MissingAssemblyException(this);
174                 }
175
176                 public override System.IO.Stream GetManifestResourceStream(string resourceName)
177                 {
178                         throw new MissingAssemblyException(this);
179                 }
180
181                 public override bool __IsMissing
182                 {
183                         get { return true; }
184                 }
185
186                 internal override Type FindType(TypeName typeName)
187                 {
188                         return null;
189                 }
190
191                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
192                 {
193                         throw new MissingAssemblyException(this);
194                 }
195         }
196
197         sealed class MissingModule : Module
198         {
199                 private readonly MissingAssembly assembly;
200
201                 internal MissingModule(MissingAssembly assembly)
202                         : base(assembly.universe)
203                 {
204                         this.assembly = assembly;
205                 }
206
207                 public override int MDStreamVersion
208                 {
209                         get { throw new MissingModuleException(this); }
210                 }
211
212                 public override Assembly Assembly
213                 {
214                         get { return assembly; }
215                 }
216
217                 public override string FullyQualifiedName
218                 {
219                         get { throw new MissingModuleException(this); }
220                 }
221
222                 public override string Name
223                 {
224                         get { throw new MissingModuleException(this); }
225                 }
226
227                 public override Guid ModuleVersionId
228                 {
229                         get { throw new MissingModuleException(this); }
230                 }
231
232                 public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
233                 {
234                         throw new MissingModuleException(this);
235                 }
236
237                 public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
238                 {
239                         throw new MissingModuleException(this);
240                 }
241
242                 public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
243                 {
244                         throw new MissingModuleException(this);
245                 }
246
247                 public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
248                 {
249                         throw new MissingModuleException(this);
250                 }
251
252                 public override string ResolveString(int metadataToken)
253                 {
254                         throw new MissingModuleException(this);
255                 }
256
257                 public override Type[] __ResolveOptionalParameterTypes(int metadataToken)
258                 {
259                         throw new MissingModuleException(this);
260                 }
261
262                 public override string ScopeName
263                 {
264                         get { throw new MissingModuleException(this); }
265                 }
266
267                 internal override Type FindType(TypeName typeName)
268                 {
269                         return null;
270                 }
271
272                 internal override void GetTypesImpl(System.Collections.Generic.List<Type> list)
273                 {
274                         throw new MissingModuleException(this);
275                 }
276
277                 public override AssemblyName[] __GetReferencedAssemblies()
278                 {
279                         throw new MissingModuleException(this);
280                 }
281
282                 internal override Type GetModuleType()
283                 {
284                         throw new MissingModuleException(this);
285                 }
286
287                 internal override IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
288                 {
289                         throw new MissingModuleException(this);
290                 }
291
292                 public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
293                 {
294                         throw new MissingModuleException(this);
295                 }
296
297                 public override IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
298                 {
299                         throw new MissingModuleException(this);
300                 }
301
302                 public override long __RelativeVirtualAddressToFileOffset(int rva)
303                 {
304                         throw new MissingModuleException(this);
305                 }
306
307                 public override __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
308                 {
309                         throw new MissingModuleException(this);
310                 }
311
312                 public override int __Subsystem
313                 {
314                         get { throw new MissingModuleException(this); }
315                 }
316
317                 internal override void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
318                 {
319                         throw new MissingModuleException(this);
320                 }
321
322                 public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
323                 {
324                         throw new MissingModuleException(this);
325                 }
326
327                 public override bool __IsMissing
328                 {
329                         get { return true; }
330                 }
331
332                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
333                 {
334                         throw new MissingModuleException(this);
335                 }
336         }
337
338         sealed class MissingType : Type
339         {
340                 private readonly Module module;
341                 private readonly Type declaringType;
342                 private readonly string ns;
343                 private readonly string name;
344
345                 internal MissingType(Module module, Type declaringType, string ns, string name)
346                 {
347                         this.module = module;
348                         this.declaringType = declaringType;
349                         this.ns = ns;
350                         this.name = name;
351                 }
352
353                 internal override Type FindNestedType(TypeName name)
354                 {
355                         return null;
356                 }
357
358                 public override Type DeclaringType
359                 {
360                         get { return declaringType; }
361                 }
362
363                 public override string __Name
364                 {
365                         get { return name; }
366                 }
367
368                 public override string __Namespace
369                 {
370                         get { return ns; }
371                 }
372
373                 public override string Name
374                 {
375                         get { return TypeNameParser.Escape(name); }
376                 }
377
378                 public override string FullName
379                 {
380                         get { return GetFullName(); }
381                 }
382
383                 public override Module Module
384                 {
385                         get { return module; }
386                 }
387
388                 public override Type BaseType
389                 {
390                         get { throw new MissingMemberException(this); }
391                 }
392
393                 public override TypeAttributes Attributes
394                 {
395                         get { throw new MissingMemberException(this); }
396                 }
397
398                 public override Type[] __GetDeclaredTypes()
399                 {
400                         throw new MissingMemberException(this);
401                 }
402
403                 public override Type[] __GetDeclaredInterfaces()
404                 {
405                         throw new MissingMemberException(this);
406                 }
407
408                 public override MethodBase[] __GetDeclaredMethods()
409                 {
410                         throw new MissingMemberException(this);
411                 }
412
413                 public override __MethodImplMap __GetMethodImplMap()
414                 {
415                         throw new MissingMemberException(this);
416                 }
417
418                 public override FieldInfo[] __GetDeclaredFields()
419                 {
420                         throw new MissingMemberException(this);
421                 }
422
423                 public override EventInfo[] __GetDeclaredEvents()
424                 {
425                         throw new MissingMemberException(this);
426                 }
427
428                 public override PropertyInfo[] __GetDeclaredProperties()
429                 {
430                         throw new MissingMemberException(this);
431                 }
432
433                 public override Type[] __GetRequiredCustomModifiers()
434                 {
435                         throw new MissingMemberException(this);
436                 }
437
438                 public override Type[] __GetOptionalCustomModifiers()
439                 {
440                         throw new MissingMemberException(this);
441                 }
442
443                 public override Type[] GetGenericArguments()
444                 {
445                         throw new MissingMemberException(this);
446                 }
447
448                 public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
449                 {
450                         throw new MissingMemberException(this);
451                 }
452
453                 public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
454                 {
455                         throw new MissingMemberException(this);
456                 }
457
458                 public override StructLayoutAttribute StructLayoutAttribute
459                 {
460                         get { throw new MissingMemberException(this); }
461                 }
462
463                 public override bool IsGenericType
464                 {
465                         get { throw new MissingMemberException(this); }
466                 }
467
468                 public override bool IsGenericTypeDefinition
469                 {
470                         get { throw new MissingMemberException(this); }
471                 }
472
473                 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
474                 {
475                         throw new MissingMemberException(this);
476                 }
477
478                 internal override Type BindTypeParameters(IGenericBinder binder)
479                 {
480                         return this;
481                 }
482         }
483 }