2 Copyright (C) 2011 Jeroen Frijters
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.
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:
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.
25 using System.Collections.Generic;
26 using System.Runtime.InteropServices;
28 namespace IKVM.Reflection
31 public sealed class MissingAssemblyException : InvalidOperationException
34 private readonly MissingAssembly assembly;
36 internal MissingAssemblyException(MissingAssembly assembly)
37 : base("Assembly '" + assembly.FullName + "' is a missing assembly and does not support the requested operation.")
39 this.assembly = assembly;
42 private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
47 public Assembly Assembly
49 get { return assembly; }
54 public sealed class MissingModuleException : InvalidOperationException
57 private readonly MissingModule module;
59 internal MissingModuleException(MissingModule module)
60 : base("Module from missing assembly '" + module.Assembly.FullName + "' does not support the requested operation.")
65 private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
72 get { return module; }
77 public sealed class MissingMemberException : InvalidOperationException
80 private readonly MemberInfo member;
82 internal MissingMemberException(MemberInfo member)
83 : base("Member '" + member + "' is a missing member and does not support the requested operation.")
88 private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
93 public MemberInfo MemberInfo
95 get { return member; }
99 sealed class MissingAssembly : Assembly
101 private readonly MissingModule module;
102 private readonly string name;
104 internal MissingAssembly(Universe universe, string name)
107 module = new MissingModule(this);
111 public override Type[] GetTypes()
113 throw new MissingAssemblyException(this);
116 public override string FullName
121 public override AssemblyName GetName()
123 return new AssemblyName(name);
126 public override string ImageRuntimeVersion
128 get { throw new MissingAssemblyException(this); }
131 public override Module ManifestModule
133 get { return module; }
136 public override MethodInfo EntryPoint
138 get { throw new MissingAssemblyException(this); }
141 public override string Location
143 get { throw new MissingAssemblyException(this); }
146 public override AssemblyName[] GetReferencedAssemblies()
148 throw new MissingAssemblyException(this);
151 public override Module[] GetModules(bool getResourceModules)
153 throw new MissingAssemblyException(this);
156 public override Module[] GetLoadedModules(bool getResourceModules)
158 throw new MissingAssemblyException(this);
161 public override Module GetModule(string name)
163 throw new MissingAssemblyException(this);
166 public override string[] GetManifestResourceNames()
168 throw new MissingAssemblyException(this);
171 public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
173 throw new MissingAssemblyException(this);
176 public override System.IO.Stream GetManifestResourceStream(string resourceName)
178 throw new MissingAssemblyException(this);
181 public override bool __IsMissing
186 internal override Type FindType(TypeName typeName)
191 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
193 throw new MissingAssemblyException(this);
197 sealed class MissingModule : Module
199 private readonly MissingAssembly assembly;
201 internal MissingModule(MissingAssembly assembly)
202 : base(assembly.universe)
204 this.assembly = assembly;
207 public override int MDStreamVersion
209 get { throw new MissingModuleException(this); }
212 public override Assembly Assembly
214 get { return assembly; }
217 public override string FullyQualifiedName
219 get { throw new MissingModuleException(this); }
222 public override string Name
224 get { throw new MissingModuleException(this); }
227 public override Guid ModuleVersionId
229 get { throw new MissingModuleException(this); }
232 public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
234 throw new MissingModuleException(this);
237 public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
239 throw new MissingModuleException(this);
242 public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
244 throw new MissingModuleException(this);
247 public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
249 throw new MissingModuleException(this);
252 public override string ResolveString(int metadataToken)
254 throw new MissingModuleException(this);
257 public override Type[] __ResolveOptionalParameterTypes(int metadataToken)
259 throw new MissingModuleException(this);
262 public override string ScopeName
264 get { throw new MissingModuleException(this); }
267 internal override Type FindType(TypeName typeName)
272 internal override void GetTypesImpl(System.Collections.Generic.List<Type> list)
274 throw new MissingModuleException(this);
277 public override AssemblyName[] __GetReferencedAssemblies()
279 throw new MissingModuleException(this);
282 internal override Type GetModuleType()
284 throw new MissingModuleException(this);
287 internal override IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
289 throw new MissingModuleException(this);
292 public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
294 throw new MissingModuleException(this);
297 public override IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
299 throw new MissingModuleException(this);
302 public override long __RelativeVirtualAddressToFileOffset(int rva)
304 throw new MissingModuleException(this);
307 public override __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
309 throw new MissingModuleException(this);
312 public override int __Subsystem
314 get { throw new MissingModuleException(this); }
317 internal override void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
319 throw new MissingModuleException(this);
322 public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
324 throw new MissingModuleException(this);
327 public override bool __IsMissing
332 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
334 throw new MissingModuleException(this);
338 sealed class MissingType : Type
340 private readonly Module module;
341 private readonly Type declaringType;
342 private readonly string ns;
343 private readonly string name;
345 internal MissingType(Module module, Type declaringType, string ns, string name)
347 this.module = module;
348 this.declaringType = declaringType;
353 internal override Type FindNestedType(TypeName name)
358 public override Type DeclaringType
360 get { return declaringType; }
363 public override string __Name
368 public override string __Namespace
373 public override string Name
375 get { return TypeNameParser.Escape(name); }
378 public override string FullName
380 get { return GetFullName(); }
383 public override Module Module
385 get { return module; }
388 public override Type BaseType
390 get { throw new MissingMemberException(this); }
393 public override TypeAttributes Attributes
395 get { throw new MissingMemberException(this); }
398 public override Type[] __GetDeclaredTypes()
400 throw new MissingMemberException(this);
403 public override Type[] __GetDeclaredInterfaces()
405 throw new MissingMemberException(this);
408 public override MethodBase[] __GetDeclaredMethods()
410 throw new MissingMemberException(this);
413 public override __MethodImplMap __GetMethodImplMap()
415 throw new MissingMemberException(this);
418 public override FieldInfo[] __GetDeclaredFields()
420 throw new MissingMemberException(this);
423 public override EventInfo[] __GetDeclaredEvents()
425 throw new MissingMemberException(this);
428 public override PropertyInfo[] __GetDeclaredProperties()
430 throw new MissingMemberException(this);
433 public override Type[] __GetRequiredCustomModifiers()
435 throw new MissingMemberException(this);
438 public override Type[] __GetOptionalCustomModifiers()
440 throw new MissingMemberException(this);
443 public override Type[] GetGenericArguments()
445 throw new MissingMemberException(this);
448 public override Type[][] __GetGenericArgumentsRequiredCustomModifiers()
450 throw new MissingMemberException(this);
453 public override Type[][] __GetGenericArgumentsOptionalCustomModifiers()
455 throw new MissingMemberException(this);
458 public override StructLayoutAttribute StructLayoutAttribute
460 get { throw new MissingMemberException(this); }
463 public override bool IsGenericType
465 get { throw new MissingMemberException(this); }
468 public override bool IsGenericTypeDefinition
470 get { throw new MissingMemberException(this); }
473 internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
475 throw new MissingMemberException(this);
478 internal override Type BindTypeParameters(IGenericBinder binder)