Submodule ikvm reflection
authorMarek Safar <marek.safar@gmail.com>
Wed, 21 Nov 2012 16:06:43 +0000 (17:06 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 21 Nov 2012 16:07:41 +0000 (17:07 +0100)
99 files changed:
.gitmodules
external/ikvm [new submodule]
mcs/class/IKVM.Reflection/AmbiguousMatchException.cs [deleted file]
mcs/class/IKVM.Reflection/Assembly.cs [deleted file]
mcs/class/IKVM.Reflection/AssemblyName.cs [deleted file]
mcs/class/IKVM.Reflection/BadImageFormatException.cs [deleted file]
mcs/class/IKVM.Reflection/Binder.cs [deleted file]
mcs/class/IKVM.Reflection/ConstructorInfo.cs [deleted file]
mcs/class/IKVM.Reflection/CustomAttributeData.cs [deleted file]
mcs/class/IKVM.Reflection/CustomAttributeNamedArgument.cs [deleted file]
mcs/class/IKVM.Reflection/CustomAttributeTypedArgument.cs [deleted file]
mcs/class/IKVM.Reflection/CustomModifiers.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/AssemblyBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/ConstructorBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/CustomAttributeBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/CustomModifiersBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/EnumBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/Enums.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/EventBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/ExceptionHandler.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/FieldBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/ILGenerator.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/ModuleBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/OpCode.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/OpCodes.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/ParameterBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/PropertyBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/SignatureHelper.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/Tokens.cs [deleted file]
mcs/class/IKVM.Reflection/Emit/TypeBuilder.cs [deleted file]
mcs/class/IKVM.Reflection/Enums.cs [deleted file]
mcs/class/IKVM.Reflection/EventInfo.cs [deleted file]
mcs/class/IKVM.Reflection/ExceptionHandlingClause.cs [deleted file]
mcs/class/IKVM.Reflection/FieldInfo.cs [deleted file]
mcs/class/IKVM.Reflection/FieldSignature.cs [deleted file]
mcs/class/IKVM.Reflection/Fusion.cs [deleted file]
mcs/class/IKVM.Reflection/GenericWrappers.cs [deleted file]
mcs/class/IKVM.Reflection/IKVM.Reflection.csproj [deleted file]
mcs/class/IKVM.Reflection/Impl/ITypeOwner.cs [deleted file]
mcs/class/IKVM.Reflection/Impl/MdbWriter.cs [deleted file]
mcs/class/IKVM.Reflection/Impl/PdbWriter.cs [deleted file]
mcs/class/IKVM.Reflection/Impl/SymbolSupport.cs [deleted file]
mcs/class/IKVM.Reflection/InterfaceMapping.cs [deleted file]
mcs/class/IKVM.Reflection/LocalVariableInfo.cs [deleted file]
mcs/class/IKVM.Reflection/Makefile [deleted file]
mcs/class/IKVM.Reflection/ManifestResourceInfo.cs [deleted file]
mcs/class/IKVM.Reflection/MarshalSpec.cs [deleted file]
mcs/class/IKVM.Reflection/MemberInfo.cs [deleted file]
mcs/class/IKVM.Reflection/Metadata/CliHeader.cs [deleted file]
mcs/class/IKVM.Reflection/Metadata/MetadataRW.cs [deleted file]
mcs/class/IKVM.Reflection/Metadata/Tables.cs [deleted file]
mcs/class/IKVM.Reflection/MethodBase.cs [deleted file]
mcs/class/IKVM.Reflection/MethodBody.cs [deleted file]
mcs/class/IKVM.Reflection/MethodImplMap.cs [deleted file]
mcs/class/IKVM.Reflection/MethodInfo.cs [deleted file]
mcs/class/IKVM.Reflection/MethodSignature.cs [deleted file]
mcs/class/IKVM.Reflection/Missing.cs [deleted file]
mcs/class/IKVM.Reflection/Module.cs [deleted file]
mcs/class/IKVM.Reflection/ParameterInfo.cs [deleted file]
mcs/class/IKVM.Reflection/ParameterModifier.cs [deleted file]
mcs/class/IKVM.Reflection/Properties/AssemblyInfo.cs [deleted file]
mcs/class/IKVM.Reflection/PropertyInfo.cs [deleted file]
mcs/class/IKVM.Reflection/PropertySignature.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/AssemblyReader.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/Authenticode.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/ByteReader.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/EventInfoImpl.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/Field.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/GenericTypeParameter.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/MetadataReader.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/Method.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/ModuleReader.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/PEReader.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/PropertyInfoImpl.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/ResourceModule.cs [deleted file]
mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs [deleted file]
mcs/class/IKVM.Reflection/Signature.cs [deleted file]
mcs/class/IKVM.Reflection/StandAloneMethodSig.cs [deleted file]
mcs/class/IKVM.Reflection/StrongNameKeyPair.cs [deleted file]
mcs/class/IKVM.Reflection/Type.cs [deleted file]
mcs/class/IKVM.Reflection/TypeInfo.cs [deleted file]
mcs/class/IKVM.Reflection/TypeNameParser.cs [deleted file]
mcs/class/IKVM.Reflection/Universe.cs [deleted file]
mcs/class/IKVM.Reflection/Util.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/ByteBuffer.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/Heaps.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/MetadataWriter.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/ModuleWriter.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/PEWriter.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/ResourceSection.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/TextSection.cs [deleted file]
mcs/class/IKVM.Reflection/Writer/VersionInfo.cs [deleted file]
mcs/class/IKVM.Reflection/reflect.build [deleted file]
mcs/class/Makefile
mcs/mcs/Makefile
mcs/mcs/ikvm.cs
mcs/mcs/mcs.csproj
mcs/mcs/mcs.exe.sources

index 01b20d739f288c268892dadf40dc7fcfb1bda534..b931bff2a92d7f0938a6ba15a0d94c6c1acb102f 100644 (file)
@@ -16,3 +16,9 @@
 [submodule "external/rx"]
        path = external/rx
        url = git://github.com/mono/rx.git
+[submodule "extern/ikvm"]
+       path = extern/ikvm
+       url = git@github.com:mono/ikvm-fork.git
+[submodule "external/ikvm"]
+       path = external/ikvm
+       url = git@github.com:mono/ikvm-fork.git
diff --git a/external/ikvm b/external/ikvm
new file mode 160000 (submodule)
index 0000000..b85c0f4
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit b85c0f4a87f539dc84933aa2409e20f6499c2f63
diff --git a/mcs/class/IKVM.Reflection/AmbiguousMatchException.cs b/mcs/class/IKVM.Reflection/AmbiguousMatchException.cs
deleted file mode 100644 (file)
index 121d69f..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.Serialization;
-
-namespace IKVM.Reflection
-{
-       [Serializable]
-       public sealed class AmbiguousMatchException : Exception
-       {
-               public AmbiguousMatchException()
-               {
-               }
-
-               public AmbiguousMatchException(string message)
-                       : base(message)
-               {
-               }
-
-               public AmbiguousMatchException(string message, Exception inner)
-                       : base(message, inner)
-               {
-               }
-
-               private AmbiguousMatchException(SerializationInfo info, StreamingContext context)
-                       : base(info, context)
-               {
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Assembly.cs b/mcs/class/IKVM.Reflection/Assembly.cs
deleted file mode 100644 (file)
index 5f3a5fa..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-
-namespace IKVM.Reflection
-{
-       public delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
-
-       public abstract class Assembly : ICustomAttributeProvider
-       {
-               internal readonly Universe universe;
-               protected string fullName;      // AssemblyBuilder needs access to this field to clear it when the name changes
-               protected List<ModuleResolveEventHandler> resolvers;
-
-               internal Assembly(Universe universe)
-               {
-                       this.universe = universe;
-               }
-
-               public sealed override string ToString()
-               {
-                       return FullName;
-               }
-
-               public event ModuleResolveEventHandler ModuleResolve
-               {
-                       add
-                       {
-                               if (resolvers == null)
-                               {
-                                       resolvers = new List<ModuleResolveEventHandler>();
-                               }
-                               resolvers.Add(value);
-                       }
-                       remove
-                       {
-                               resolvers.Remove(value);
-                       }
-               }
-
-               public abstract Type[] GetTypes();
-               public abstract AssemblyName GetName();
-               public abstract string ImageRuntimeVersion { get; }
-               public abstract Module ManifestModule { get; }
-               public abstract MethodInfo EntryPoint { get; }
-               public abstract string Location { get; }
-               public abstract AssemblyName[] GetReferencedAssemblies();
-               public abstract Module[] GetModules(bool getResourceModules);
-               public abstract Module[] GetLoadedModules(bool getResourceModules);
-               public abstract Module GetModule(string name);
-               public abstract string[] GetManifestResourceNames();
-               public abstract ManifestResourceInfo GetManifestResourceInfo(string resourceName);
-               public abstract System.IO.Stream GetManifestResourceStream(string name);
-
-               internal abstract Type FindType(TypeName name);
-               internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
-
-               // The differences between ResolveType and FindType are:
-               // - ResolveType is only used when a type is assumed to exist (because another module's metadata claims it)
-               // - ResolveType can return a MissingType
-               internal Type ResolveType(TypeName typeName)
-               {
-                       return FindType(typeName) ?? universe.GetMissingTypeOrThrow(this.ManifestModule, null, typeName);
-               }
-
-               public string FullName
-               {
-                       get { return fullName ?? (fullName = GetName().FullName); }
-               }
-
-               public Module[] GetModules()
-               {
-                       return GetModules(true);
-               }
-
-               public IEnumerable<Module> Modules
-               {
-                       get { return GetLoadedModules(); }
-               }
-
-               public Module[] GetLoadedModules()
-               {
-                       return GetLoadedModules(true);
-               }
-
-               public AssemblyName GetName(bool copiedName)
-               {
-                       return GetName();
-               }
-
-               public bool ReflectionOnly
-               {
-                       get { return true; }
-               }
-
-               public Type[] GetExportedTypes()
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (Type type in GetTypes())
-                       {
-                               if (type.IsVisible)
-                               {
-                                       list.Add(type);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public IEnumerable<Type> ExportedTypes
-               {
-                       get { return GetExportedTypes(); }
-               }
-
-               public IEnumerable<TypeInfo> DefinedTypes
-               {
-                       get
-                       {
-                               Type[] types = GetTypes();
-                               TypeInfo[] typeInfos = new TypeInfo[types.Length];
-                               for (int i = 0; i < types.Length; i++)
-                               {
-                                       typeInfos[i] = types[i].GetTypeInfo();
-                               }
-                               return typeInfos;
-                       }
-               }
-
-               public Type GetType(string name)
-               {
-                       return GetType(name, false);
-               }
-
-               public Type GetType(string name, bool throwOnError)
-               {
-                       return GetType(name, throwOnError, false);
-               }
-
-               public Type GetType(string name, bool throwOnError, bool ignoreCase)
-               {
-                       TypeNameParser parser = TypeNameParser.Parse(name, throwOnError);
-                       if (parser.Error)
-                       {
-                               return null;
-                       }
-                       if (parser.AssemblyName != null)
-                       {
-                               if (throwOnError)
-                               {
-                                       throw new ArgumentException("Type names passed to Assembly.GetType() must not specify an assembly.");
-                               }
-                               else
-                               {
-                                       return null;
-                               }
-                       }
-                       TypeName typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
-                       Type type = ignoreCase
-                               ? FindTypeIgnoreCase(typeName.ToLowerInvariant())
-                               : FindType(typeName);
-                       if (type == null && __IsMissing)
-                       {
-                               throw new MissingAssemblyException((MissingAssembly)this);
-                       }
-                       return parser.Expand(type, this, throwOnError, name, false, ignoreCase);
-               }
-
-               public virtual Module LoadModule(string moduleName, byte[] rawModule)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)
-               {
-                       return LoadModule(moduleName, rawModule);
-               }
-
-               public bool IsDefined(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
-               }
-
-               public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
-               }
-
-               public IList<CustomAttributeData> GetCustomAttributesData()
-               {
-                       return CustomAttributeData.GetCustomAttributes(this);
-               }
-
-               public IEnumerable<CustomAttributeData> CustomAttributes
-               {
-                       get { return GetCustomAttributesData(); }
-               }
-
-               public static string CreateQualifiedName(string assemblyName, string typeName)
-               {
-                       return typeName + ", " + assemblyName;
-               }
-
-               public static Assembly GetAssembly(Type type)
-               {
-                       return type.Assembly;
-               }
-
-               public string CodeBase
-               {
-                       get
-                       {
-                               string path = this.Location.Replace(System.IO.Path.DirectorySeparatorChar, '/');
-                               if (!path.StartsWith("/"))
-                               {
-                                       path = "/" + path;
-                               }
-                               return "file://" + path;
-                       }
-               }
-
-               public virtual bool IsDynamic
-               {
-                       get { return false; }
-               }
-
-               public virtual bool __IsMissing
-               {
-                       get { return false; }
-               }
-
-               public AssemblyNameFlags __AssemblyFlags
-               {
-                       get { return GetAssemblyFlags(); }
-               }
-
-               protected virtual AssemblyNameFlags GetAssemblyFlags()
-               {
-                       return GetName().Flags;
-               }
-
-               internal abstract IList<CustomAttributeData> GetCustomAttributesData(Type attributeType);
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/AssemblyName.cs b/mcs/class/IKVM.Reflection/AssemblyName.cs
deleted file mode 100644 (file)
index beae6ad..0000000
+++ /dev/null
@@ -1,476 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Globalization;
-using System.Configuration.Assemblies;
-using System.IO;
-using System.Security.Cryptography;
-using System.Text;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       public sealed class AssemblyName : ICloneable
-       {
-               private string name;
-               private string culture;
-               private Version version;
-               private byte[] publicKeyToken;
-               private byte[] publicKey;
-               private StrongNameKeyPair keyPair;
-               private AssemblyNameFlags flags;
-               private AssemblyHashAlgorithm hashAlgorithm;
-               private AssemblyVersionCompatibility versionCompatibility = AssemblyVersionCompatibility.SameMachine;
-               private ProcessorArchitecture processorArchitecture;
-               private string codeBase;
-               internal byte[] hash;
-
-               public AssemblyName()
-               {
-               }
-
-               public AssemblyName(string assemblyName)
-               {
-                       if (assemblyName == null)
-                       {
-                               throw new ArgumentNullException("assemblyName");
-                       }
-                       if (assemblyName == "")
-                       {
-                               throw new ArgumentException();
-                       }
-                       ParsedAssemblyName parsed;
-                       switch (Fusion.ParseAssemblyName(assemblyName, out parsed))
-                       {
-                               case ParseAssemblyResult.GenericError:
-                               case ParseAssemblyResult.DuplicateKey:
-                                       throw new FileLoadException();
-                       }
-                       name = parsed.Name;
-                       if (parsed.Culture != null)
-                       {
-                               if (parsed.Culture.Equals("neutral", StringComparison.InvariantCultureIgnoreCase))
-                               {
-                                       culture = "";
-                               }
-                               else if (parsed.Culture == "")
-                               {
-                                       throw new FileLoadException();
-                               }
-                               else
-                               {
-                                       culture = new CultureInfo(parsed.Culture).Name;
-                               }
-                       }
-                       if (parsed.Version != null && parsed.Version.Major != 65535 && parsed.Version.Minor != 65535)
-                       {
-                               // our Fusion parser returns -1 for build and revision for incomplete version numbers (and we want 65535)
-                               version = new Version(parsed.Version.Major, parsed.Version.Minor, parsed.Version.Build & 0xFFFF, parsed.Version.Revision & 0xFFFF);
-                       }
-                       if (parsed.PublicKeyToken != null)
-                       {
-                               if (parsed.PublicKeyToken.Equals("null", StringComparison.InvariantCultureIgnoreCase))
-                               {
-                                       publicKeyToken = Empty<byte>.Array;
-                               }
-                               else if (parsed.PublicKeyToken.Length != 16)
-                               {
-                                       throw new FileLoadException();
-                               }
-                               else
-                               {
-                                       publicKeyToken = ParseKey(parsed.PublicKeyToken);
-                               }
-                       }
-                       if (parsed.Retargetable.HasValue)
-                       {
-                               if (parsed.Culture == null || parsed.PublicKeyToken == null || parsed.Version == null || parsed.Version.Build == -1 || parsed.Version.Revision == -1)
-                               {
-                                       throw new FileLoadException();
-                               }
-                               if (parsed.Retargetable.Value)
-                               {
-                                       flags |= AssemblyNameFlags.Retargetable;
-                               }
-                       }
-                       ProcessorArchitecture = parsed.ProcessorArchitecture;
-                       if (parsed.WindowsRuntime)
-                       {
-                               ContentType = AssemblyContentType.WindowsRuntime;
-                       }
-               }
-
-               private static byte[] ParseKey(string key)
-               {
-                       if ((key.Length & 1) != 0)
-                       {
-                               throw new FileLoadException();
-                       }
-                       byte[] buf = new byte[key.Length / 2];
-                       for (int i = 0; i < buf.Length; i++)
-                       {
-                               buf[i] = (byte)(ParseHexDigit(key[i * 2]) * 16 + ParseHexDigit(key[i * 2 + 1]));
-                       }
-                       return buf;
-               }
-
-               private static int ParseHexDigit(char digit)
-               {
-                       if (digit >= '0' && digit <= '9')
-                       {
-                               return digit - '0';
-                       }
-                       else
-                       {
-                               digit |= (char)0x20;
-                               if (digit >= 'a' && digit <= 'f')
-                               {
-                                       return 10 + digit - 'a';
-                               }
-                               else
-                               {
-                                       throw new FileLoadException();
-                               }
-                       }
-               }
-
-               public override string ToString()
-               {
-                       return FullName;
-               }
-
-               public string Name
-               {
-                       get { return name; }
-                       set { name = value; }
-               }
-
-               public CultureInfo CultureInfo
-               {
-                       get { return culture == null ? null : new CultureInfo(culture); }
-                       set { culture = value == null ? null : value.Name; }
-               }
-
-               public string CultureName
-               {
-                       get { return culture; }
-               }
-
-               internal string Culture
-               {
-                       get { return culture; }
-                       set { culture = value; }
-               }
-
-               public Version Version
-               {
-                       get { return version; }
-                       set { version = value; }
-               }
-
-               public StrongNameKeyPair KeyPair
-               {
-                       get { return keyPair; }
-                       set { keyPair = value; }
-               }
-
-               public string CodeBase
-               {
-                       get { return codeBase; }
-                       set { codeBase = value; }
-               }
-
-               public string EscapedCodeBase
-               {
-                       get
-                       {
-                               // HACK use the real AssemblyName to escape the codebase
-                               System.Reflection.AssemblyName tmp = new System.Reflection.AssemblyName();
-                               tmp.CodeBase = codeBase;
-                               return tmp.EscapedCodeBase;
-                       }
-               }
-
-               public ProcessorArchitecture ProcessorArchitecture
-               {
-                       get { return processorArchitecture; }
-                       set
-                       {
-                               if (value >= ProcessorArchitecture.None && value <= ProcessorArchitecture.Arm)
-                               {
-                                       processorArchitecture = value;
-                                       flags = (flags & ~(AssemblyNameFlags)0x70) | (AssemblyNameFlags)((int)value << 4);
-                               }
-                       }
-               }
-
-               public AssemblyNameFlags Flags
-               {
-                       get { return flags & (AssemblyNameFlags)~0xEF0; }
-                       set { flags = (flags & (AssemblyNameFlags)0xEF0) | (value & (AssemblyNameFlags)~0xEF0); }
-               }
-
-               public AssemblyVersionCompatibility VersionCompatibility
-               {
-                       get { return versionCompatibility; }
-                       set { versionCompatibility = value; }
-               }
-
-               public AssemblyContentType ContentType
-               {
-                       get { return (AssemblyContentType)(((int)flags & 0xE00) >> 9); }
-                       set
-                       {
-                               if (value >= AssemblyContentType.Default && value <= AssemblyContentType.WindowsRuntime)
-                               {
-                                       flags = (flags & ~(AssemblyNameFlags)0xE00) | (AssemblyNameFlags)((int)value << 9);
-                               }
-                       }
-               }
-
-               public byte[] GetPublicKey()
-               {
-                       return publicKey;
-               }
-
-               public void SetPublicKey(byte[] publicKey)
-               {
-                       this.publicKey = publicKey;
-                       flags = (flags & ~AssemblyNameFlags.PublicKey) | (publicKey == null ? 0 : AssemblyNameFlags.PublicKey);
-               }
-
-               public byte[] GetPublicKeyToken()
-               {
-                       if (publicKeyToken == null && publicKey != null)
-                       {
-                               // note that GetPublicKeyToken() has a side effect in this case, because we retain this token even after the public key subsequently gets changed
-                               publicKeyToken = ComputePublicKeyToken(publicKey);
-                       }
-                       return publicKeyToken;
-               }
-
-               public void SetPublicKeyToken(byte[] publicKeyToken)
-               {
-                       this.publicKeyToken = publicKeyToken;
-               }
-
-               public AssemblyHashAlgorithm HashAlgorithm
-               {
-                       get { return hashAlgorithm; }
-                       set { hashAlgorithm = value; }
-               }
-
-               public byte[] __Hash
-               {
-                       get { return hash; }
-               }
-
-               public string FullName
-               {
-                       get
-                       {
-                               if (name == null)
-                               {
-                                       return "";
-                               }
-                               StringBuilder sb = new StringBuilder();
-                               bool doubleQuotes = name.StartsWith(" ") || name.EndsWith(" ") || name.IndexOf('\'') != -1;
-                               bool singleQuotes = name.IndexOf('"') != -1;
-                               if (singleQuotes)
-                               {
-                                       sb.Append('\'');
-                               }
-                               else if (doubleQuotes)
-                               {
-                                       sb.Append('"');
-                               }
-                               if (name.IndexOf(',') != -1 || name.IndexOf('\\') != -1 || name.IndexOf('=') != -1 || (singleQuotes && name.IndexOf('\'') != -1))
-                               {
-                                       for (int i = 0; i < name.Length; i++)
-                                       {
-                                               char c = name[i];
-                                               if (c == ',' || c == '\\' || c == '=' || (singleQuotes && c == '\''))
-                                               {
-                                                       sb.Append('\\');
-                                               }
-                                               sb.Append(c);
-                                       }
-                               }
-                               else
-                               {
-                                       sb.Append(name);
-                               }
-                               if (singleQuotes)
-                               {
-                                       sb.Append('\'');
-                               }
-                               else if (doubleQuotes)
-                               {
-                                       sb.Append('"');
-                               }
-                               if (version != null)
-                               {
-                                       if ((version.Major & 0xFFFF) != 0xFFFF)
-                                       {
-                                               sb.Append(", Version=").Append(version.Major & 0xFFFF);
-                                               if ((version.Minor & 0xFFFF) != 0xFFFF)
-                                               {
-                                                       sb.Append('.').Append(version.Minor & 0xFFFF);
-                                                       if ((version.Build & 0xFFFF) != 0xFFFF)
-                                                       {
-                                                               sb.Append('.').Append(version.Build & 0xFFFF);
-                                                               if ((version.Revision & 0xFFFF) != 0xFFFF)
-                                                               {
-                                                                       sb.Append('.').Append(version.Revision & 0xFFFF);
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-                               if (culture != null)
-                               {
-                                       sb.Append(", Culture=").Append(culture == "" ? "neutral" : culture);
-                               }
-                               byte[] publicKeyToken = this.publicKeyToken;
-                               if ((publicKeyToken == null || publicKeyToken.Length == 0) && publicKey != null)
-                               {
-                                       publicKeyToken = ComputePublicKeyToken(publicKey);
-                               }
-                               if (publicKeyToken != null)
-                               {
-                                       sb.Append(", PublicKeyToken=");
-                                       if (publicKeyToken.Length == 0)
-                                       {
-                                               sb.Append("null");
-                                       }
-                                       else
-                                       {
-                                               AppendPublicKey(sb, publicKeyToken);
-                                       }
-                               }
-                               if ((Flags & AssemblyNameFlags.Retargetable) != 0)
-                               {
-                                       sb.Append(", Retargetable=Yes");
-                               }
-                               if (ContentType == AssemblyContentType.WindowsRuntime)
-                               {
-                                       sb.Append(", ContentType=WindowsRuntime");
-                               }
-                               return sb.ToString();
-                       }
-               }
-
-               private static byte[] ComputePublicKeyToken(byte[] publicKey)
-               {
-                       if (publicKey.Length == 0)
-                       {
-                               return publicKey;
-                       }
-                       byte[] hash = new SHA1Managed().ComputeHash(publicKey);
-                       byte[] token = new byte[8];
-                       for (int i = 0; i < token.Length; i++)
-                       {
-                               token[i] = hash[hash.Length - 1 - i];
-                       }
-                       return token;
-               }
-
-               internal static string ComputePublicKeyToken(string publicKey)
-               {
-                       StringBuilder sb = new StringBuilder(16);
-                       AppendPublicKey(sb, ComputePublicKeyToken(ParseKey(publicKey)));
-                       return sb.ToString();
-               }
-
-               private static void AppendPublicKey(StringBuilder sb, byte[] publicKey)
-               {
-                       for (int i = 0; i < publicKey.Length; i++)
-                       {
-                               sb.Append("0123456789abcdef"[publicKey[i] >> 4]);
-                               sb.Append("0123456789abcdef"[publicKey[i] & 0x0F]);
-                       }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       AssemblyName other = obj as AssemblyName;
-                       return other != null && other.FullName == this.FullName;
-               }
-
-               public override int GetHashCode()
-               {
-                       return FullName.GetHashCode();
-               }
-
-               public object Clone()
-               {
-                       AssemblyName copy = (AssemblyName)MemberwiseClone();
-                       copy.publicKey = Copy(publicKey);
-                       copy.publicKeyToken = Copy(publicKeyToken);
-                       return copy;
-               }
-
-               private static byte[] Copy(byte[] b)
-               {
-                       return b == null || b.Length == 0 ? b : (byte[])b.Clone();
-               }
-
-               public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition)
-               {
-                       // HACK use the real AssemblyName to implement the (broken) ReferenceMatchesDefinition method
-                       return System.Reflection.AssemblyName.ReferenceMatchesDefinition(new System.Reflection.AssemblyName(reference.FullName), new System.Reflection.AssemblyName(definition.FullName));
-               }
-
-               public static AssemblyName GetAssemblyName(string path)
-               {
-                       try
-                       {
-                               path = Path.GetFullPath(path);
-                               using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
-                               {
-                                       ModuleReader module = new ModuleReader(null, null, fs, path);
-                                       if (module.Assembly == null)
-                                       {
-                                               throw new BadImageFormatException("Module does not contain a manifest");
-                                       }
-                                       return module.Assembly.GetName();
-                               }
-                       }
-                       catch (IOException x)
-                       {
-                               throw new FileNotFoundException(x.Message, x);
-                       }
-                       catch (UnauthorizedAccessException x)
-                       {
-                               throw new FileNotFoundException(x.Message, x);
-                       }
-               }
-
-               internal AssemblyNameFlags RawFlags
-               {
-                       get { return flags; }
-                       set { flags = value; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/BadImageFormatException.cs b/mcs/class/IKVM.Reflection/BadImageFormatException.cs
deleted file mode 100644 (file)
index 330f983..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.Serialization;
-
-namespace IKVM.Reflection
-{
-       [Serializable]
-       public sealed class BadImageFormatException : Exception
-       {
-               public BadImageFormatException()
-               {
-               }
-
-               public BadImageFormatException(string message)
-                       : base(message)
-               {
-               }
-
-               public BadImageFormatException(string message, Exception inner)
-                       : base(message, inner)
-               {
-               }
-
-               private BadImageFormatException(SerializationInfo info, StreamingContext context)
-                       : base(info, context)
-               {
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Binder.cs b/mcs/class/IKVM.Reflection/Binder.cs
deleted file mode 100644 (file)
index a079451..0000000
+++ /dev/null
@@ -1,405 +0,0 @@
-/*
-  Copyright (C) 2010-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Globalization;
-
-namespace IKVM.Reflection
-{
-       public abstract class Binder
-       {
-               protected Binder()
-               {
-               }
-
-               public virtual MethodBase BindToMethod(BindingFlags bindingAttr, MethodBase[] match, ref object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] names, out object state)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public virtual FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo culture)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public virtual object ChangeType(object value, Type type, CultureInfo culture)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public virtual void ReorderArgumentArray(ref object[] args, object state)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public abstract MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers);
-               public abstract PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers);
-       }
-
-       sealed class DefaultBinder : Binder
-       {
-               public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
-               {
-                       int matchCount = 0;
-                       foreach (MethodBase method in match)
-                       {
-                               if (MatchParameterTypes(method.GetParameters(), types))
-                               {
-                                       match[matchCount++] = method;
-                               }
-                       }
-
-                       if (matchCount == 0)
-                       {
-                               return null;
-                       }
-
-                       if (matchCount == 1)
-                       {
-                               return match[0];
-                       }
-
-                       MethodBase bestMatch = match[0];
-                       bool ambiguous = false;
-                       for (int i = 1; i < matchCount; i++)
-                       {
-                               bestMatch = SelectBestMatch(bestMatch, match[i], types, ref ambiguous);
-                       }
-                       if (ambiguous)
-                       {
-                               throw new AmbiguousMatchException();
-                       }
-                       return bestMatch;
-               }
-
-               private static bool MatchParameterTypes(ParameterInfo[] parameters, Type[] types)
-               {
-                       if (parameters.Length != types.Length)
-                       {
-                               return false;
-                       }
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               Type sourceType = types[i];
-                               Type targetType = parameters[i].ParameterType;
-                               if (sourceType != targetType
-                                       && !targetType.IsAssignableFrom(sourceType)
-                                       && !IsAllowedPrimitiveConversion(sourceType, targetType))
-                               {
-                                       return false;
-                               }
-                       }
-                       return true;
-               }
-
-               private static MethodBase SelectBestMatch(MethodBase mb1, MethodBase mb2, Type[] types, ref bool ambiguous)
-               {
-                       switch (MatchSignatures(mb1.MethodSignature, mb2.MethodSignature, types))
-                       {
-                               case 1:
-                                       return mb1;
-                               case 2:
-                                       return mb2;
-                       }
-
-                       if (mb1.MethodSignature.MatchParameterTypes(mb2.MethodSignature))
-                       {
-                               int depth1 = GetInheritanceDepth(mb1.DeclaringType);
-                               int depth2 = GetInheritanceDepth(mb2.DeclaringType);
-                               if (depth1 > depth2)
-                               {
-                                       return mb1;
-                               }
-                               else if (depth1 < depth2)
-                               {
-                                       return mb2;
-                               }
-                       }
-
-                       ambiguous = true;
-                       return mb1;
-               }
-
-               private static int GetInheritanceDepth(Type type)
-               {
-                       int depth = 0;
-                       while (type != null)
-                       {
-                               depth++;
-                               type = type.BaseType;
-                       }
-                       return depth;
-               }
-
-               private static int MatchSignatures(MethodSignature sig1, MethodSignature sig2, Type[] types)
-               {
-                       for (int i = 0; i < sig1.GetParameterCount(); i++)
-                       {
-                               Type type1 = sig1.GetParameterType(i);
-                               Type type2 = sig2.GetParameterType(i);
-                               if (type1 != type2)
-                               {
-                                       return MatchTypes(type1, type2, types[i]);
-                               }
-                       }
-                       return 0;
-               }
-
-               private static int MatchSignatures(PropertySignature sig1, PropertySignature sig2, Type[] types)
-               {
-                       for (int i = 0; i < sig1.ParameterCount; i++)
-                       {
-                               Type type1 = sig1.GetParameter(i);
-                               Type type2 = sig2.GetParameter(i);
-                               if (type1 != type2)
-                               {
-                                       return MatchTypes(type1, type2, types[i]);
-                               }
-                       }
-                       return 0;
-               }
-
-               private static int MatchTypes(Type type1, Type type2, Type type)
-               {
-                       if (type1 == type)
-                       {
-                               return 1;
-                       }
-                       if (type2 == type)
-                       {
-                               return 2;
-                       }
-                       bool conv = type1.IsAssignableFrom(type2);
-                       return conv == type2.IsAssignableFrom(type1) ? 0 : conv ? 2 : 1;
-               }
-
-               private static bool IsAllowedPrimitiveConversion(Type source, Type target)
-               {
-                       // we need to check for primitives, because GetTypeCode will return the underlying type for enums
-                       if (!source.IsPrimitive || !target.IsPrimitive)
-                       {
-                               return false;
-                       }
-                       TypeCode sourceType = Type.GetTypeCode(source);
-                       TypeCode targetType = Type.GetTypeCode(target);
-                       switch (sourceType)
-                       {
-                               case TypeCode.Char:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.UInt16:
-                                               case TypeCode.UInt32:
-                                               case TypeCode.Int32:
-                                               case TypeCode.UInt64:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.Byte:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Char:
-                                               case TypeCode.UInt16:
-                                               case TypeCode.Int16:
-                                               case TypeCode.UInt32:
-                                               case TypeCode.Int32:
-                                               case TypeCode.UInt64:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.SByte:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Int16:
-                                               case TypeCode.Int32:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.UInt16:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.UInt32:
-                                               case TypeCode.Int32:
-                                               case TypeCode.UInt64:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.Int16:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Int32:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.UInt32:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.UInt64:
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.Int32:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Int64:
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.UInt64:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.Int64:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Single:
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               case TypeCode.Single:
-                                       switch (targetType)
-                                       {
-                                               case TypeCode.Double:
-                                                       return true;
-                                               default:
-                                                       return false;
-                                       }
-                               default:
-                                       return false;
-                       }
-               }
-
-               public override PropertyInfo SelectProperty(BindingFlags bindingAttr, PropertyInfo[] match, Type returnType, Type[] indexes, ParameterModifier[] modifiers)
-               {
-                       int matchCount = 0;
-                       foreach (PropertyInfo property in match)
-                       {
-                               if (indexes == null || MatchParameterTypes(property.GetIndexParameters(), indexes))
-                               {
-                                       if (returnType != null)
-                                       {
-                                               if (property.PropertyType.IsPrimitive)
-                                               {
-                                                       if (!IsAllowedPrimitiveConversion(returnType, property.PropertyType))
-                                                       {
-                                                               continue;
-                                                       }
-                                               }
-                                               else
-                                               {
-                                                       if (!property.PropertyType.IsAssignableFrom(returnType))
-                                                       {
-                                                               continue;
-                                                       }
-                                               }
-                                       }
-                                       match[matchCount++] = property;
-                               }
-                       }
-
-                       if (matchCount == 0)
-                       {
-                               return null;
-                       }
-
-                       if (matchCount == 1)
-                       {
-                               return match[0];
-                       }
-
-                       PropertyInfo bestMatch = match[0];
-                       bool ambiguous = false;
-                       for (int i = 1; i < matchCount; i++)
-                       {
-                               int best = MatchTypes(bestMatch.PropertyType, match[i].PropertyType, returnType);
-                               if (best == 0 && indexes != null)
-                               {
-                                       best = MatchSignatures(bestMatch.PropertySignature, match[i].PropertySignature, indexes);
-                               }
-                               if (best == 0)
-                               {
-                                       int depth1 = GetInheritanceDepth(bestMatch.DeclaringType);
-                                       int depth2 = GetInheritanceDepth(match[i].DeclaringType);
-                                       if (bestMatch.Name == match[i].Name && depth1 != depth2)
-                                       {
-                                               if (depth1 > depth2)
-                                               {
-                                                       best = 1;
-                                               }
-                                               else
-                                               {
-                                                       best = 2;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               ambiguous = true;
-                                       }
-                               }
-                               if (best == 2)
-                               {
-                                       ambiguous = false;
-                                       bestMatch = match[i];
-                               }
-                       }
-                       if (ambiguous)
-                       {
-                               throw new AmbiguousMatchException();
-                       }
-                       return bestMatch;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/ConstructorInfo.cs b/mcs/class/IKVM.Reflection/ConstructorInfo.cs
deleted file mode 100644 (file)
index 11d18a7..0000000
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace IKVM.Reflection
-{
-       public abstract class ConstructorInfo : MethodBase
-       {
-               // prevent external subclasses
-               internal ConstructorInfo()
-               {
-               }
-
-               public sealed override string ToString()
-               {
-                       return GetMethodInfo().ToString();
-               }
-
-               public static readonly string ConstructorName = ".ctor";
-               public static readonly string TypeConstructorName = ".cctor";
-
-               internal abstract MethodInfo GetMethodInfo();
-
-               internal override MethodBase BindTypeParameters(Type type)
-               {
-                       return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().BindTypeParameters(type));
-               }
-
-               public sealed override MethodBase __GetMethodOnTypeDefinition()
-               {
-                       return new ConstructorInfoImpl((MethodInfo)GetMethodInfo().__GetMethodOnTypeDefinition());
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return MemberTypes.Constructor; }
-               }
-
-               public sealed override int __MethodRVA
-               {
-                       get { return GetMethodInfo().__MethodRVA; }
-               }
-
-               public sealed override bool ContainsGenericParameters
-               {
-                       get { return GetMethodInfo().ContainsGenericParameters; }
-               }
-
-               public ParameterInfo __ReturnParameter
-               {
-                       get { return new ParameterInfoWrapper(this, GetMethodInfo().ReturnParameter); }
-               }
-
-               public sealed override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameters = GetMethodInfo().GetParameters();
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
-                       }
-                       return parameters;
-               }
-
-               public sealed override CallingConventions CallingConvention
-               {
-                       get { return GetMethodInfo().CallingConvention; }
-               }
-
-               public sealed override MethodAttributes Attributes
-               {
-                       get { return GetMethodInfo().Attributes; }
-               }
-
-               public sealed override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return GetMethodInfo().GetMethodImplementationFlags();
-               }
-
-               public sealed override Type DeclaringType
-               {
-                       get { return GetMethodInfo().DeclaringType; }
-               }
-
-               public sealed override string Name
-               {
-                       get { return GetMethodInfo().Name; }
-               }
-
-               public sealed override int MetadataToken
-               {
-                       get { return GetMethodInfo().MetadataToken; }
-               }
-
-               public sealed override Module Module
-               {
-                       get { return GetMethodInfo().Module; }
-               }
-
-               public sealed override MethodBody GetMethodBody()
-               {
-                       return GetMethodInfo().GetMethodBody();
-               }
-
-               public sealed override bool __IsMissing
-               {
-                       get { return GetMethodInfo().__IsMissing; }
-               }
-
-               internal sealed override int ParameterCount
-               {
-                       get { return GetMethodInfo().ParameterCount; }
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       return new ConstructorInfoWithReflectedType(type, this);
-               }
-
-               internal sealed override int GetCurrentToken()
-               {
-                       return GetMethodInfo().GetCurrentToken();
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       return GetMethodInfo().GetPseudoCustomAttributes(attributeType);
-               }
-
-               internal sealed override bool IsBaked
-               {
-                       get { return GetMethodInfo().IsBaked; }
-               }
-
-               internal sealed override MethodSignature MethodSignature
-               {
-                       get { return GetMethodInfo().MethodSignature; }
-               }
-
-               internal sealed override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       return GetMethodInfo().ImportTo(module);
-               }
-       }
-
-       sealed class ConstructorInfoImpl : ConstructorInfo
-       {
-               private readonly MethodInfo method;
-
-               internal ConstructorInfoImpl(MethodInfo method)
-               {
-                       this.method = method;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       ConstructorInfoImpl other = obj as ConstructorInfoImpl;
-                       return other != null && other.method.Equals(method);
-               }
-
-               public override int GetHashCode()
-               {
-                       return method.GetHashCode();
-               }
-
-               internal override MethodInfo GetMethodInfo()
-               {
-                       return method;
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return method.GetMethodOnTypeDefinition();
-               }
-       }
-
-       sealed class ConstructorInfoWithReflectedType : ConstructorInfo
-       {
-               private readonly Type reflectedType;
-               private readonly ConstructorInfo ctor;
-
-               internal ConstructorInfoWithReflectedType(Type reflectedType, ConstructorInfo ctor)
-               {
-                       Debug.Assert(reflectedType != ctor.DeclaringType);
-                       this.reflectedType = reflectedType;
-                       this.ctor = ctor;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       ConstructorInfoWithReflectedType other = obj as ConstructorInfoWithReflectedType;
-                       return other != null
-                               && other.reflectedType == reflectedType
-                               && other.ctor == ctor;
-               }
-
-               public override int GetHashCode()
-               {
-                       return reflectedType.GetHashCode() ^ ctor.GetHashCode();
-               }
-
-               public override Type ReflectedType
-               {
-                       get { return reflectedType; }
-               }
-
-               internal override MethodInfo GetMethodInfo()
-               {
-                       return ctor.GetMethodInfo();
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return ctor.GetMethodOnTypeDefinition();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/CustomAttributeData.cs b/mcs/class/IKVM.Reflection/CustomAttributeData.cs
deleted file mode 100644 (file)
index 6c4c2a7..0000000
+++ /dev/null
@@ -1,1016 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection
-{
-       public sealed class CustomAttributeData
-       {
-               internal static readonly IList<CustomAttributeData> EmptyList = new List<CustomAttributeData>(0).AsReadOnly();
-
-               /*
-                * There are several states a CustomAttributeData object can be in:
-                * 
-                * 1) Unresolved Custom Attribute
-                *    - customAttributeIndex >= 0
-                *    - declSecurityIndex == -1
-                *    - declSecurityBlob == null
-                *    - lazyConstructor = null
-                *    - lazyConstructorArguments = null
-                *    - lazyNamedArguments = null
-                * 
-                * 2) Resolved Custom Attribute
-                *    - customAttributeIndex >= 0
-                *    - declSecurityIndex == -1
-                *    - declSecurityBlob == null
-                *    - lazyConstructor != null
-                *    - lazyConstructorArguments != null
-                *    - lazyNamedArguments != null
-                *    
-                * 3) Pre-resolved Custom Attribute
-                *    - customAttributeIndex = -1
-                *    - declSecurityIndex == -1
-                *    - declSecurityBlob == null
-                *    - lazyConstructor != null
-                *    - lazyConstructorArguments != null
-                *    - lazyNamedArguments != null
-                *    
-                * 4) Pseudo Custom Attribute, .NET 1.x declarative security or result of CustomAttributeBuilder.ToData()
-                *    - customAttributeIndex = -1
-                *    - declSecurityIndex == -1
-                *    - declSecurityBlob == null
-                *    - lazyConstructor != null
-                *    - lazyConstructorArguments != null
-                *    - lazyNamedArguments != null
-                *    
-                * 5) Unresolved declarative security
-                *    - customAttributeIndex = -1
-                *    - declSecurityIndex >= 0
-                *    - declSecurityBlob != null
-                *    - lazyConstructor != null
-                *    - lazyConstructorArguments != null
-                *    - lazyNamedArguments == null
-                * 
-                * 6) Resolved declarative security
-                *    - customAttributeIndex = -1
-                *    - declSecurityIndex >= 0
-                *    - declSecurityBlob == null
-                *    - lazyConstructor != null
-                *    - lazyConstructorArguments != null
-                *    - lazyNamedArguments != null
-                * 
-                */
-               private readonly Module module;
-               private readonly int customAttributeIndex;
-               private readonly int declSecurityIndex;
-               private readonly byte[] declSecurityBlob;
-               private ConstructorInfo lazyConstructor;
-               private IList<CustomAttributeTypedArgument> lazyConstructorArguments;
-               private IList<CustomAttributeNamedArgument> lazyNamedArguments;
-
-               // 1) Unresolved Custom Attribute
-               internal CustomAttributeData(Module module, int index)
-               {
-                       this.module = module;
-                       this.customAttributeIndex = index;
-                       this.declSecurityIndex = -1;
-               }
-
-               // 4) Pseudo Custom Attribute, .NET 1.x declarative security
-               internal CustomAttributeData(Module module, ConstructorInfo constructor, object[] args, List<CustomAttributeNamedArgument> namedArguments)
-                       : this(module, constructor, WrapConstructorArgs(args, constructor.MethodSignature), namedArguments)
-               {
-               }
-
-               private static List<CustomAttributeTypedArgument> WrapConstructorArgs(object[] args, MethodSignature sig)
-               {
-                       List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>();
-                       for (int i = 0; i < args.Length; i++)
-                       {
-                               list.Add(new CustomAttributeTypedArgument(sig.GetParameterType(i), args[i]));
-                       }
-                       return list;
-               }
-
-               // 4) Pseudo Custom Attribute, .NET 1.x declarative security or result of CustomAttributeBuilder.ToData()
-               internal CustomAttributeData(Module module, ConstructorInfo constructor, List<CustomAttributeTypedArgument> constructorArgs, List<CustomAttributeNamedArgument> namedArguments)
-               {
-                       this.module = module;
-                       this.customAttributeIndex = -1;
-                       this.declSecurityIndex = -1;
-                       this.lazyConstructor = constructor;
-                       lazyConstructorArguments = constructorArgs.AsReadOnly();
-                       if (namedArguments == null)
-                       {
-                               this.lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
-                       }
-                       else
-                       {
-                               this.lazyNamedArguments = namedArguments.AsReadOnly();
-                       }
-               }
-
-               // 3) Pre-resolved Custom Attribute
-               internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, ByteReader br)
-               {
-                       this.module = asm.ManifestModule;
-                       this.customAttributeIndex = -1;
-                       this.declSecurityIndex = -1;
-                       this.lazyConstructor = constructor;
-                       if (br.Length == 0)
-                       {
-                               // it's legal to have an empty blob
-                               lazyConstructorArguments = Empty<CustomAttributeTypedArgument>.Array;
-                               lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
-                       }
-                       else
-                       {
-                               if (br.ReadUInt16() != 1)
-                               {
-                                       throw new BadImageFormatException();
-                               }
-                               lazyConstructorArguments = ReadConstructorArguments(asm, br, constructor);
-                               lazyNamedArguments = ReadNamedArguments(asm, br, br.ReadUInt16(), constructor.DeclaringType);
-                       }
-               }
-
-               public override string ToString()
-               {
-                       StringBuilder sb = new StringBuilder();
-                       sb.Append('[');
-                       sb.Append(Constructor.DeclaringType.FullName);
-                       sb.Append('(');
-                       string sep = "";
-                       ParameterInfo[] parameters = Constructor.GetParameters();
-                       IList<CustomAttributeTypedArgument> args = ConstructorArguments;
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               sb.Append(sep);
-                               sep = ", ";
-                               AppendValue(sb, parameters[i].ParameterType, args[i]);
-                       }
-                       foreach (CustomAttributeNamedArgument named in NamedArguments)
-                       {
-                               sb.Append(sep);
-                               sep = ", ";
-                               sb.Append(named.MemberInfo.Name);
-                               sb.Append(" = ");
-                               FieldInfo fi = named.MemberInfo as FieldInfo;
-                               Type type = fi != null ? fi.FieldType : ((PropertyInfo)named.MemberInfo).PropertyType;
-                               AppendValue(sb, type, named.TypedValue);
-                       }
-                       sb.Append(')');
-                       sb.Append(']');
-                       return sb.ToString();
-               }
-
-               private static void AppendValue(StringBuilder sb, Type type, CustomAttributeTypedArgument arg)
-               {
-                       if (arg.ArgumentType == arg.ArgumentType.Module.universe.System_String)
-                       {
-                               sb.Append('"').Append(arg.Value).Append('"');
-                       }
-                       else if (arg.ArgumentType.IsArray)
-                       {
-                               Type elementType = arg.ArgumentType.GetElementType();
-                               string elementTypeName;
-                               if (elementType.IsPrimitive
-                                       || elementType == type.Module.universe.System_Object
-                                       || elementType == type.Module.universe.System_String
-                                       || elementType == type.Module.universe.System_Type)
-                               {
-                                       elementTypeName = elementType.Name;
-                               }
-                               else
-                               {
-                                       elementTypeName = elementType.FullName;
-                               }
-                               sb.Append("new ").Append(elementTypeName).Append("[").Append(((Array)arg.Value).Length).Append("] { ");
-                               string sep = "";
-                               foreach (CustomAttributeTypedArgument elem in (CustomAttributeTypedArgument[])arg.Value)
-                               {
-                                       sb.Append(sep);
-                                       sep = ", ";
-                                       AppendValue(sb, elementType, elem);
-                               }
-                               sb.Append(" }");
-                       }
-                       else
-                       {
-                               if (arg.ArgumentType != type || (type.IsEnum && !arg.Value.Equals(0)))
-                               {
-                                       sb.Append('(');
-                                       sb.Append(arg.ArgumentType.FullName);
-                                       sb.Append(')');
-                               }
-                               sb.Append(arg.Value);
-                       }
-               }
-
-               internal static void ReadDeclarativeSecurity(Module module, int index, List<CustomAttributeData> list)
-               {
-                       Universe u = module.universe;
-                       Assembly asm = module.Assembly;
-                       int action = module.DeclSecurity.records[index].Action;
-                       ByteReader br = module.GetBlob(module.DeclSecurity.records[index].PermissionSet);
-                       if (br.PeekByte() == '.')
-                       {
-                               br.ReadByte();
-                               int count = br.ReadCompressedUInt();
-                               for (int j = 0; j < count; j++)
-                               {
-                                       Type type = ReadType(asm, br);
-                                       ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction);
-                                       // LAMESPEC there is an additional length here (probably of the named argument list)
-                                       byte[] blob = br.ReadBytes(br.ReadCompressedUInt());
-                                       list.Add(new CustomAttributeData(asm, constructor, action, blob, index));
-                               }
-                       }
-                       else
-                       {
-                               // .NET 1.x format (xml)
-                               char[] buf = new char[br.Length / 2];
-                               for (int i = 0; i < buf.Length; i++)
-                               {
-                                       buf[i] = br.ReadChar();
-                               }
-                               string xml = new String(buf);
-                               ConstructorInfo constructor = u.System_Security_Permissions_PermissionSetAttribute.GetPseudoCustomAttributeConstructor(u.System_Security_Permissions_SecurityAction);
-                               List<CustomAttributeNamedArgument> args = new List<CustomAttributeNamedArgument>();
-                               args.Add(new CustomAttributeNamedArgument(GetProperty(u.System_Security_Permissions_PermissionSetAttribute, "XML", u.System_String),
-                                       new CustomAttributeTypedArgument(u.System_String, xml)));
-                               list.Add(new CustomAttributeData(asm.ManifestModule, constructor, new object[] { action }, args));
-                       }
-               }
-
-               // 5) Unresolved declarative security
-               internal CustomAttributeData(Assembly asm, ConstructorInfo constructor, int securityAction, byte[] blob, int index)
-               {
-                       this.module = asm.ManifestModule;
-                       this.customAttributeIndex = -1;
-                       this.declSecurityIndex = index;
-                       Universe u = constructor.Module.universe;
-                       this.lazyConstructor = constructor;
-                       List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>();
-                       list.Add(new CustomAttributeTypedArgument(u.System_Security_Permissions_SecurityAction, securityAction));
-                       this.lazyConstructorArguments =  list.AsReadOnly();
-                       this.declSecurityBlob = blob;
-               }
-
-               private static Type ReadFieldOrPropType(Assembly asm, ByteReader br)
-               {
-                       Universe u = asm.universe;
-                       switch (br.ReadByte())
-                       {
-                               case Signature.ELEMENT_TYPE_BOOLEAN:
-                                       return u.System_Boolean;
-                               case Signature.ELEMENT_TYPE_CHAR:
-                                       return u.System_Char;
-                               case Signature.ELEMENT_TYPE_I1:
-                                       return u.System_SByte;
-                               case Signature.ELEMENT_TYPE_U1:
-                                       return u.System_Byte;
-                               case Signature.ELEMENT_TYPE_I2:
-                                       return u.System_Int16;
-                               case Signature.ELEMENT_TYPE_U2:
-                                       return u.System_UInt16;
-                               case Signature.ELEMENT_TYPE_I4:
-                                       return u.System_Int32;
-                               case Signature.ELEMENT_TYPE_U4:
-                                       return u.System_UInt32;
-                               case Signature.ELEMENT_TYPE_I8:
-                                       return u.System_Int64;
-                               case Signature.ELEMENT_TYPE_U8:
-                                       return u.System_UInt64;
-                               case Signature.ELEMENT_TYPE_R4:
-                                       return u.System_Single;
-                               case Signature.ELEMENT_TYPE_R8:
-                                       return u.System_Double;
-                               case Signature.ELEMENT_TYPE_STRING:
-                                       return u.System_String;
-                               case Signature.ELEMENT_TYPE_SZARRAY:
-                                       return ReadFieldOrPropType(asm, br).MakeArrayType();
-                               case 0x55:
-                                       return ReadType(asm, br);
-                               case 0x50:
-                                       return u.System_Type;
-                               case 0x51:
-                                       return u.System_Object;
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               private static CustomAttributeTypedArgument ReadFixedArg(Assembly asm, ByteReader br, Type type)
-               {
-                       Universe u = asm.universe;
-                       if (type == u.System_String)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadString());
-                       }
-                       else if (type == u.System_Boolean)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadByte() != 0);
-                       }
-                       else if (type == u.System_Char)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadChar());
-                       }
-                       else if (type == u.System_Single)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadSingle());
-                       }
-                       else if (type == u.System_Double)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadDouble());
-                       }
-                       else if (type == u.System_SByte)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadSByte());
-                       }
-                       else if (type == u.System_Int16)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadInt16());
-                       }
-                       else if (type == u.System_Int32)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadInt32());
-                       }
-                       else if (type == u.System_Int64)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadInt64());
-                       }
-                       else if (type == u.System_Byte)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadByte());
-                       }
-                       else if (type == u.System_UInt16)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadUInt16());
-                       }
-                       else if (type == u.System_UInt32)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadUInt32());
-                       }
-                       else if (type == u.System_UInt64)
-                       {
-                               return new CustomAttributeTypedArgument(type, br.ReadUInt64());
-                       }
-                       else if (type == u.System_Type)
-                       {
-                               return new CustomAttributeTypedArgument(type, ReadType(asm, br));
-                       }
-                       else if (type == u.System_Object)
-                       {
-                               return ReadFixedArg(asm, br, ReadFieldOrPropType(asm, br));
-                       }
-                       else if (type.IsArray)
-                       {
-                               int length = br.ReadInt32();
-                               if (length == -1)
-                               {
-                                       return new CustomAttributeTypedArgument(type, null);
-                               }
-                               Type elementType = type.GetElementType();
-                               CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[length];
-                               for (int i = 0; i < length; i++)
-                               {
-                                       array[i] = ReadFixedArg(asm, br, elementType);
-                               }
-                               return new CustomAttributeTypedArgument(type, array);
-                       }
-                       else if (type.IsEnum)
-                       {
-                               return new CustomAttributeTypedArgument(type, ReadFixedArg(asm, br, type.GetEnumUnderlyingTypeImpl()).Value);
-                       }
-                       else
-                       {
-                               throw new InvalidOperationException();
-                       }
-               }
-
-               private static Type ReadType(Assembly asm, ByteReader br)
-               {
-                       string typeName = br.ReadString();
-                       if (typeName == null)
-                       {
-                               return null;
-                       }
-                       if (typeName.Length > 0 && typeName[typeName.Length - 1] == 0)
-                       {
-                               // there are broken compilers that emit an extra NUL character after the type name
-                               typeName = typeName.Substring(0, typeName.Length - 1);
-                       }
-                       return TypeNameParser.Parse(typeName, true).GetType(asm.universe, asm, true, typeName, true, false);
-               }
-
-               private static IList<CustomAttributeTypedArgument> ReadConstructorArguments(Assembly asm, ByteReader br, ConstructorInfo constructor)
-               {
-                       MethodSignature sig = constructor.MethodSignature;
-                       int count = sig.GetParameterCount();
-                       List<CustomAttributeTypedArgument> list = new List<CustomAttributeTypedArgument>(count);
-                       for (int i = 0; i < count; i++)
-                       {
-                               list.Add(ReadFixedArg(asm, br, sig.GetParameterType(i)));
-                       }
-                       return list.AsReadOnly();
-               }
-
-               private static IList<CustomAttributeNamedArgument> ReadNamedArguments(Assembly asm, ByteReader br, int named, Type type)
-               {
-                       List<CustomAttributeNamedArgument> list = new List<CustomAttributeNamedArgument>(named);
-                       for (int i = 0; i < named; i++)
-                       {
-                               byte fieldOrProperty = br.ReadByte();
-                               Type fieldOrPropertyType = ReadFieldOrPropType(asm, br);
-                               string name = br.ReadString();
-                               CustomAttributeTypedArgument value = ReadFixedArg(asm, br, fieldOrPropertyType);
-                               MemberInfo member;
-                               switch (fieldOrProperty)
-                               {
-                                       case 0x53:
-                                               member = GetField(type, name, fieldOrPropertyType);
-                                               break;
-                                       case 0x54:
-                                               member = GetProperty(type, name, fieldOrPropertyType);
-                                               break;
-                                       default:
-                                               throw new BadImageFormatException();
-                               }
-                               list.Add(new CustomAttributeNamedArgument(member, value));
-                       }
-                       return list.AsReadOnly();
-               }
-
-               private static FieldInfo GetField(Type type, string name, Type fieldType)
-               {
-                       Type org = type;
-                       for (; type != null && !type.__IsMissing; type = type.BaseType)
-                       {
-                               foreach (FieldInfo field in type.__GetDeclaredFields())
-                               {
-                                       if (field.IsPublic && !field.IsStatic && field.Name == name)
-                                       {
-                                               return field;
-                                       }
-                               }
-                       }
-                       // if the field is missing, we stick the missing field on the first missing base type
-                       if (type == null)
-                       {
-                               type = org;
-                       }
-                       FieldSignature sig = FieldSignature.Create(fieldType, new CustomModifiers());
-                       return type.FindField(name, sig)
-                               ?? type.Module.universe.GetMissingFieldOrThrow(type, name, sig);
-               }
-
-               private static PropertyInfo GetProperty(Type type, string name, Type propertyType)
-               {
-                       Type org = type;
-                       for (; type != null && !type.__IsMissing; type = type.BaseType)
-                       {
-                               foreach (PropertyInfo property in type.__GetDeclaredProperties())
-                               {
-                                       if (property.IsPublic && !property.IsStatic && property.Name == name)
-                                       {
-                                               return property;
-                                       }
-                               }
-                       }
-                       // if the property is missing, we stick the missing property on the first missing base type
-                       if (type == null)
-                       {
-                               type = org;
-                       }
-                       return type.Module.universe.GetMissingPropertyOrThrow(type, name, PropertySignature.Create(CallingConventions.Standard | CallingConventions.HasThis, propertyType, null, new PackedCustomModifiers()));
-               }
-
-               [Obsolete("Use AttributeType property instead.")]
-               internal bool __TryReadTypeName(out string ns, out string name)
-               {
-                       if (Constructor.DeclaringType.IsNested)
-                       {
-                               ns = null;
-                               name = null;
-                               return false;
-                       }
-                       ns = Constructor.DeclaringType.__Namespace;
-                       name = Constructor.DeclaringType.__Name;
-                       return true;
-               }
-
-               public byte[] __GetBlob()
-               {
-                       if (declSecurityBlob != null)
-                       {
-                               return (byte[])declSecurityBlob.Clone();
-                       }
-                       else if (customAttributeIndex == -1)
-                       {
-                               return __ToBuilder().GetBlob(module.Assembly);
-                       }
-                       else
-                       {
-                               return ((ModuleReader)module).GetBlobCopy(module.CustomAttribute.records[customAttributeIndex].Value);
-                       }
-               }
-
-               public int __Parent
-               {
-                       get
-                       {
-                               return customAttributeIndex >= 0
-                                       ? module.CustomAttribute.records[customAttributeIndex].Parent
-                                       : declSecurityIndex >= 0
-                                               ? module.DeclSecurity.records[declSecurityIndex].Parent
-                                               : 0;
-                       }
-               }
-
-               // .NET 4.5 API
-               public Type AttributeType
-               {
-                       get { return Constructor.DeclaringType; }
-               }
-
-               public ConstructorInfo Constructor
-               {
-                       get
-                       {
-                               if (lazyConstructor == null)
-                               {
-                                       lazyConstructor = (ConstructorInfo)module.ResolveMethod(module.CustomAttribute.records[customAttributeIndex].Type);
-                               }
-                               return lazyConstructor;
-                       }
-               }
-
-               public IList<CustomAttributeTypedArgument> ConstructorArguments
-               {
-                       get
-                       {
-                               if (lazyConstructorArguments == null)
-                               {
-                                       LazyParseArguments();
-                               }
-                               return lazyConstructorArguments;
-                       }
-               }
-
-               public IList<CustomAttributeNamedArgument> NamedArguments
-               {
-                       get
-                       {
-                               if (lazyNamedArguments == null)
-                               {
-                                       if (customAttributeIndex >= 0)
-                                       {
-                                               // 1) Unresolved Custom Attribute
-                                               LazyParseArguments();
-                                       }
-                                       else
-                                       {
-                                               // 5) Unresolved declarative security
-                                               ByteReader br = new ByteReader(declSecurityBlob, 0, declSecurityBlob.Length);
-                                               // LAMESPEC the count of named arguments is a compressed integer (instead of UInt16 as NumNamed in custom attributes)
-                                               lazyNamedArguments = ReadNamedArguments(module.Assembly, br, br.ReadCompressedUInt(), Constructor.DeclaringType);
-                                       }
-                               }
-                               return lazyNamedArguments;
-                       }
-               }
-
-               private void LazyParseArguments()
-               {
-                       ByteReader br = module.GetBlob(module.CustomAttribute.records[customAttributeIndex].Value);
-                       if (br.Length == 0)
-                       {
-                               // it's legal to have an empty blob
-                               lazyConstructorArguments = Empty<CustomAttributeTypedArgument>.Array;
-                               lazyNamedArguments = Empty<CustomAttributeNamedArgument>.Array;
-                       }
-                       else
-                       {
-                               if (br.ReadUInt16() != 1)
-                               {
-                                       throw new BadImageFormatException();
-                               }
-                               lazyConstructorArguments = ReadConstructorArguments(module.Assembly, br, Constructor);
-                               lazyNamedArguments = ReadNamedArguments(module.Assembly, br, br.ReadUInt16(), Constructor.DeclaringType);
-                       }
-               }
-
-               public CustomAttributeBuilder __ToBuilder()
-               {
-                       ParameterInfo[] parameters = Constructor.GetParameters();
-                       object[] args = new object[ConstructorArguments.Count];
-                       for (int i = 0; i < args.Length; i++)
-                       {
-                               args[i] = RewrapArray(parameters[i].ParameterType, ConstructorArguments[i]);
-                       }
-                       List<PropertyInfo> namedProperties = new List<PropertyInfo>();
-                       List<object> propertyValues = new List<object>();
-                       List<FieldInfo> namedFields = new List<FieldInfo>();
-                       List<object> fieldValues = new List<object>();
-                       foreach (CustomAttributeNamedArgument named in NamedArguments)
-                       {
-                               PropertyInfo pi = named.MemberInfo as PropertyInfo;
-                               if (pi != null)
-                               {
-                                       namedProperties.Add(pi);
-                                       propertyValues.Add(RewrapArray(pi.PropertyType, named.TypedValue));
-                               }
-                               else
-                               {
-                                       FieldInfo fi = (FieldInfo)named.MemberInfo;
-                                       namedFields.Add(fi);
-                                       fieldValues.Add(RewrapArray(fi.FieldType, named.TypedValue));
-                               }
-                       }
-                       return new CustomAttributeBuilder(Constructor, args, namedProperties.ToArray(), propertyValues.ToArray(), namedFields.ToArray(), fieldValues.ToArray());
-               }
-
-               private static object RewrapArray(Type type, CustomAttributeTypedArgument arg)
-               {
-                       IList<CustomAttributeTypedArgument> list = arg.Value as IList<CustomAttributeTypedArgument>;
-                       if (list != null)
-                       {
-                               Type elementType = arg.ArgumentType.GetElementType();
-                               object[] arr = new object[list.Count];
-                               for (int i = 0; i < arr.Length; i++)
-                               {
-                                       arr[i] = RewrapArray(elementType, list[i]);
-                               }
-                               if (type == type.Module.universe.System_Object)
-                               {
-                                       return CustomAttributeBuilder.__MakeTypedArgument(arg.ArgumentType, arr);
-                               }
-                               return arr;
-                       }
-                       else
-                       {
-                               return arg.Value;
-                       }
-               }
-
-               public static IList<CustomAttributeData> GetCustomAttributes(MemberInfo member)
-               {
-                       return __GetCustomAttributes(member, null, false);
-               }
-
-               public static IList<CustomAttributeData> GetCustomAttributes(Assembly assembly)
-               {
-                       return assembly.GetCustomAttributesData(null);
-               }
-
-               public static IList<CustomAttributeData> GetCustomAttributes(Module module)
-               {
-                       return __GetCustomAttributes(module, null, false);
-               }
-
-               public static IList<CustomAttributeData> GetCustomAttributes(ParameterInfo parameter)
-               {
-                       return __GetCustomAttributes(parameter, null, false);
-               }
-
-               public static IList<CustomAttributeData> __GetCustomAttributes(Assembly assembly, Type attributeType, bool inherit)
-               {
-                       return assembly.GetCustomAttributesData(attributeType);
-               }
-
-               public static IList<CustomAttributeData> __GetCustomAttributes(Module module, Type attributeType, bool inherit)
-               {
-                       if (module.__IsMissing)
-                       {
-                               throw new MissingModuleException((MissingModule)module);
-                       }
-                       return GetCustomAttributesImpl(null, module, 0x00000001, attributeType) ?? EmptyList;
-               }
-
-               public static IList<CustomAttributeData> __GetCustomAttributes(ParameterInfo parameter, Type attributeType, bool inherit)
-               {
-                       Module module = parameter.Module;
-                       List<CustomAttributeData> list = null;
-                       if (module.universe.ReturnPseudoCustomAttributes)
-                       {
-                               if (attributeType == null || attributeType.IsAssignableFrom(parameter.Module.universe.System_Runtime_InteropServices_MarshalAsAttribute))
-                               {
-                                       FieldMarshal spec;
-                                       if (parameter.__TryGetFieldMarshal(out spec))
-                                       {
-                                               if (list == null)
-                                               {
-                                                       list = new List<CustomAttributeData>();
-                                               }
-                                               list.Add(CustomAttributeData.CreateMarshalAsPseudoCustomAttribute(parameter.Module, spec));
-                                       }
-                               }
-                       }
-                       ModuleBuilder mb = module as ModuleBuilder;
-                       int token = parameter.MetadataToken;
-                       if (mb != null && mb.IsSaved && ModuleBuilder.IsPseudoToken(token))
-                       {
-                               token = mb.ResolvePseudoToken(token);
-                       }
-                       return GetCustomAttributesImpl(list, module, token, attributeType) ?? EmptyList;
-               }
-
-               public static IList<CustomAttributeData> __GetCustomAttributes(MemberInfo member, Type attributeType, bool inherit)
-               {
-                       if (!member.IsBaked)
-                       {
-                               // like .NET we we don't return custom attributes for unbaked members
-                               throw new NotImplementedException();
-                       }
-                       if (!inherit || !IsInheritableAttribute(attributeType))
-                       {
-                               return GetCustomAttributesImpl(null, member, attributeType) ?? EmptyList;
-                       }
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       for (; ; )
-                       {
-                               GetCustomAttributesImpl(list, member, attributeType);
-                               Type type = member as Type;
-                               if (type != null)
-                               {
-                                       type = type.BaseType;
-                                       if (type == null)
-                                       {
-                                               return list;
-                                       }
-                                       member = type;
-                                       continue;
-                               }
-                               MethodInfo method = member as MethodInfo;
-                               if (method != null)
-                               {
-                                       MemberInfo prev = member;
-                                       method = method.GetBaseDefinition();
-                                       if (method == null || method == prev)
-                                       {
-                                               return list;
-                                       }
-                                       member = method;
-                                       continue;
-                               }
-                               return list;
-                       }
-               }
-
-               private static List<CustomAttributeData> GetCustomAttributesImpl(List<CustomAttributeData> list, MemberInfo member, Type attributeType)
-               {
-                       if (member.Module.universe.ReturnPseudoCustomAttributes)
-                       {
-                               List<CustomAttributeData> pseudo = member.GetPseudoCustomAttributes(attributeType);
-                               if (list == null)
-                               {
-                                       list = pseudo;
-                               }
-                               else if (pseudo != null)
-                               {
-                                       list.AddRange(pseudo);
-                               }
-                       }
-                       return GetCustomAttributesImpl(list, member.Module, member.GetCurrentToken(), attributeType);
-               }
-
-               internal static List<CustomAttributeData> GetCustomAttributesImpl(List<CustomAttributeData> list, Module module, int token, Type attributeType)
-               {
-                       foreach (int i in module.CustomAttribute.Filter(token))
-                       {
-                               if (attributeType == null)
-                               {
-                                       if (list == null)
-                                       {
-                                               list = new List<CustomAttributeData>();
-                                       }
-                                       list.Add(new CustomAttributeData(module, i));
-                               }
-                               else
-                               {
-                                       if (attributeType.IsAssignableFrom(module.ResolveMethod(module.CustomAttribute.records[i].Type).DeclaringType))
-                                       {
-                                               if (list == null)
-                                               {
-                                                       list = new List<CustomAttributeData>();
-                                               }
-                                               list.Add(new CustomAttributeData(module, i));
-                                       }
-                               }
-                       }
-                       return list;
-               }
-
-               public static IList<CustomAttributeData> __GetCustomAttributes(Type type, Type interfaceType, Type attributeType, bool inherit)
-               {
-                       Module module = type.Module;
-                       foreach (int i in module.InterfaceImpl.Filter(type.MetadataToken))
-                       {
-                               if (module.ResolveType(module.InterfaceImpl.records[i].Interface, type) == interfaceType)
-                               {
-                                       return GetCustomAttributesImpl(null, module, (InterfaceImplTable.Index << 24) | (i + 1), attributeType) ?? EmptyList;
-                               }
-                       }
-                       return EmptyList;
-               }
-
-               public static IList<CustomAttributeData> __GetDeclarativeSecurity(Assembly assembly)
-               {
-                       if (assembly.__IsMissing)
-                       {
-                               throw new MissingAssemblyException((MissingAssembly)assembly);
-                       }
-                       return assembly.ManifestModule.GetDeclarativeSecurity(0x20000001);
-               }
-
-               public static IList<CustomAttributeData> __GetDeclarativeSecurity(Type type)
-               {
-                       if ((type.Attributes & TypeAttributes.HasSecurity) != 0)
-                       {
-                               return type.Module.GetDeclarativeSecurity(type.MetadataToken);
-                       }
-                       else
-                       {
-                               return EmptyList;
-                       }
-               }
-
-               public static IList<CustomAttributeData> __GetDeclarativeSecurity(MethodBase method)
-               {
-                       if ((method.Attributes & MethodAttributes.HasSecurity) != 0)
-                       {
-                               return method.Module.GetDeclarativeSecurity(method.MetadataToken);
-                       }
-                       else
-                       {
-                               return EmptyList;
-                       }
-               }
-
-               private static bool IsInheritableAttribute(Type attribute)
-               {
-                       Type attributeUsageAttribute = attribute.Module.universe.System_AttributeUsageAttribute;
-                       IList<CustomAttributeData> attr = __GetCustomAttributes(attribute, attributeUsageAttribute, false);
-                       if (attr.Count != 0)
-                       {
-                               foreach (CustomAttributeNamedArgument named in attr[0].NamedArguments)
-                               {
-                                       if (named.MemberInfo.Name == "Inherited")
-                                       {
-                                               return (bool)named.TypedValue.Value;
-                                       }
-                               }
-                       }
-                       return true;
-               }
-
-               internal static CustomAttributeData CreateDllImportPseudoCustomAttribute(Module module, ImplMapFlags flags, string entryPoint, string dllName, MethodImplAttributes attr)
-               {
-                       Type type = module.universe.System_Runtime_InteropServices_DllImportAttribute;
-                       ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(module.universe.System_String);
-                       List<CustomAttributeNamedArgument> list = new List<CustomAttributeNamedArgument>();
-                       System.Runtime.InteropServices.CharSet charSet;
-                       switch (flags & ImplMapFlags.CharSetMask)
-                       {
-                               case ImplMapFlags.CharSetAnsi:
-                                       charSet = System.Runtime.InteropServices.CharSet.Ansi;
-                                       break;
-                               case ImplMapFlags.CharSetUnicode:
-                                       charSet = System.Runtime.InteropServices.CharSet.Unicode;
-                                       break;
-                               case ImplMapFlags.CharSetAuto:
-                                       charSet = System.Runtime.InteropServices.CharSet.Auto;
-                                       break;
-                               case ImplMapFlags.CharSetNotSpec:
-                               default:
-                                       charSet = System.Runtime.InteropServices.CharSet.None;
-                                       break;
-                       }
-                       System.Runtime.InteropServices.CallingConvention callingConvention;
-                       switch (flags & ImplMapFlags.CallConvMask)
-                       {
-                               case ImplMapFlags.CallConvCdecl:
-                                       callingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
-                                       break;
-                               case ImplMapFlags.CallConvFastcall:
-                                       callingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
-                                       break;
-                               case ImplMapFlags.CallConvStdcall:
-                                       callingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
-                                       break;
-                               case ImplMapFlags.CallConvThiscall:
-                                       callingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
-                                       break;
-                               case ImplMapFlags.CallConvWinapi:
-                                       callingConvention = System.Runtime.InteropServices.CallingConvention.Winapi;
-                                       break;
-                               default:
-                                       callingConvention = 0;
-                                       break;
-                       }
-                       AddNamedArgument(list, type, "EntryPoint", entryPoint);
-                       AddNamedArgument(list, type, "CharSet", module.universe.System_Runtime_InteropServices_CharSet, (int)charSet);
-                       AddNamedArgument(list, type, "ExactSpelling", (int)flags, (int)ImplMapFlags.NoMangle);
-                       AddNamedArgument(list, type, "SetLastError", (int)flags, (int)ImplMapFlags.SupportsLastError);
-                       AddNamedArgument(list, type, "PreserveSig", (int)attr, (int)MethodImplAttributes.PreserveSig);
-                       AddNamedArgument(list, type, "CallingConvention", module.universe.System_Runtime_InteropServices_CallingConvention, (int)callingConvention);
-                       AddNamedArgument(list, type, "BestFitMapping", (int)flags, (int)ImplMapFlags.BestFitOn);
-                       AddNamedArgument(list, type, "ThrowOnUnmappableChar", (int)flags, (int)ImplMapFlags.CharMapErrorOn);
-                       return new CustomAttributeData(module, constructor, new object[] { dllName }, list);
-               }
-
-               internal static CustomAttributeData CreateMarshalAsPseudoCustomAttribute(Module module, FieldMarshal fm)
-               {
-                       Type typeofMarshalAs = module.universe.System_Runtime_InteropServices_MarshalAsAttribute;
-                       Type typeofUnmanagedType = module.universe.System_Runtime_InteropServices_UnmanagedType;
-                       Type typeofVarEnum = module.universe.System_Runtime_InteropServices_VarEnum;
-                       Type typeofType = module.universe.System_Type;
-                       List<CustomAttributeNamedArgument> named = new List<CustomAttributeNamedArgument>();
-                       AddNamedArgument(named, typeofMarshalAs, "ArraySubType", typeofUnmanagedType, (int)(fm.ArraySubType ?? 0));
-                       AddNamedArgument(named, typeofMarshalAs, "SizeParamIndex", module.universe.System_Int16, fm.SizeParamIndex ?? 0);
-                       AddNamedArgument(named, typeofMarshalAs, "SizeConst", module.universe.System_Int32, fm.SizeConst ?? 0);
-                       AddNamedArgument(named, typeofMarshalAs, "IidParameterIndex", module.universe.System_Int32, fm.IidParameterIndex ?? 0);
-                       AddNamedArgument(named, typeofMarshalAs, "SafeArraySubType", typeofVarEnum, (int)(fm.SafeArraySubType ?? 0));
-                       if (fm.SafeArrayUserDefinedSubType != null)
-                       {
-                               AddNamedArgument(named, typeofMarshalAs, "SafeArrayUserDefinedSubType", typeofType, fm.SafeArrayUserDefinedSubType);
-                       }
-                       if (fm.MarshalType != null)
-                       {
-                               AddNamedArgument(named, typeofMarshalAs, "MarshalType", module.universe.System_String, fm.MarshalType);
-                       }
-                       if (fm.MarshalTypeRef != null)
-                       {
-                               AddNamedArgument(named, typeofMarshalAs, "MarshalTypeRef", module.universe.System_Type, fm.MarshalTypeRef);
-                       }
-                       if (fm.MarshalCookie != null)
-                       {
-                               AddNamedArgument(named, typeofMarshalAs, "MarshalCookie", module.universe.System_String, fm.MarshalCookie);
-                       }
-                       ConstructorInfo constructor = typeofMarshalAs.GetPseudoCustomAttributeConstructor(typeofUnmanagedType);
-                       return new CustomAttributeData(module, constructor, new object[] { (int)fm.UnmanagedType }, named);
-               }
-
-               private static void AddNamedArgument(List<CustomAttributeNamedArgument> list, Type type, string fieldName, string value)
-               {
-                       AddNamedArgument(list, type, fieldName, type.Module.universe.System_String, value);
-               }
-
-               private static void AddNamedArgument(List<CustomAttributeNamedArgument> list, Type type, string fieldName, int flags, int flagMask)
-               {
-                       AddNamedArgument(list, type, fieldName, type.Module.universe.System_Boolean, (flags & flagMask) != 0);
-               }
-
-               private static void AddNamedArgument(List<CustomAttributeNamedArgument> list, Type attributeType, string fieldName, Type valueType, object value)
-               {
-                       // some fields are not available on the .NET Compact Framework version of DllImportAttribute/MarshalAsAttribute
-                       FieldInfo field = attributeType.FindField(fieldName, FieldSignature.Create(valueType, new CustomModifiers()));
-                       if (field != null)
-                       {
-                               list.Add(new CustomAttributeNamedArgument(field, new CustomAttributeTypedArgument(valueType, value)));
-                       }
-               }
-
-               internal static CustomAttributeData CreateFieldOffsetPseudoCustomAttribute(Module module, int offset)
-               {
-                       Type type = module.universe.System_Runtime_InteropServices_FieldOffsetAttribute;
-                       ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor(module.universe.System_Int32);
-                       return new CustomAttributeData(module, constructor, new object[] { offset }, null);
-               }
-
-               internal static CustomAttributeData CreatePreserveSigPseudoCustomAttribute(Module module)
-               {
-                       Type type = module.universe.System_Runtime_InteropServices_PreserveSigAttribute;
-                       ConstructorInfo constructor = type.GetPseudoCustomAttributeConstructor();
-                       return new CustomAttributeData(module, constructor, Empty<object>.Array, null);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/CustomAttributeNamedArgument.cs b/mcs/class/IKVM.Reflection/CustomAttributeNamedArgument.cs
deleted file mode 100644 (file)
index 4b4a8ea..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       public struct CustomAttributeNamedArgument
-       {
-               private readonly MemberInfo member;
-               private readonly CustomAttributeTypedArgument value;
-
-               internal CustomAttributeNamedArgument(MemberInfo member, CustomAttributeTypedArgument value)
-               {
-                       this.member = member;
-                       this.value = value;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return this == obj as CustomAttributeNamedArgument?;
-               }
-
-               public override int GetHashCode()
-               {
-                       return member.GetHashCode() ^ 53 * value.GetHashCode();
-               }
-
-               public MemberInfo MemberInfo
-               {
-                       get { return member; }
-               }
-
-               public CustomAttributeTypedArgument TypedValue
-               {
-                       get { return value; }
-               }
-
-               public bool IsField
-               {
-                       get { return member.MemberType == MemberTypes.Field; }
-               }
-
-               public string MemberName
-               {
-                       get { return member.Name; }
-               }
-
-               public static bool operator ==(CustomAttributeNamedArgument arg1, CustomAttributeNamedArgument arg2)
-               {
-                       return arg1.member.Equals(arg2.member) && arg1.value == arg2.value;
-               }
-
-               public static bool operator !=(CustomAttributeNamedArgument arg1, CustomAttributeNamedArgument arg2)
-               {
-                       return !(arg1 == arg2);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/CustomAttributeTypedArgument.cs b/mcs/class/IKVM.Reflection/CustomAttributeTypedArgument.cs
deleted file mode 100644 (file)
index 3403135..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       public struct CustomAttributeTypedArgument
-       {
-               private readonly Type type;
-               private readonly object value;
-
-               internal CustomAttributeTypedArgument(Type type, object value)
-               {
-                       this.type = type;
-                       this.value = value;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return this == obj as CustomAttributeTypedArgument?;
-               }
-
-               public override int GetHashCode()
-               {
-                       return type.GetHashCode() ^ 77 * (value == null ? 0 : value.GetHashCode());
-               }
-
-               public Type ArgumentType
-               {
-                       get { return type; }
-               }
-
-               public Object Value
-               {
-                       get { return value; }
-               }
-
-               public static bool operator ==(CustomAttributeTypedArgument arg1, CustomAttributeTypedArgument arg2)
-               {
-                       return arg1.type.Equals(arg2.type) && (arg1.value == arg2.value || (arg1.value != null && arg1.value.Equals(arg2.value)));
-               }
-
-               public static bool operator !=(CustomAttributeTypedArgument arg1, CustomAttributeTypedArgument arg2)
-               {
-                       return !(arg1 == arg2);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/CustomModifiers.cs b/mcs/class/IKVM.Reflection/CustomModifiers.cs
deleted file mode 100644 (file)
index dade700..0000000
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
-  Copyright (C) 2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       public struct CustomModifiers : IEquatable<CustomModifiers>, IEnumerable<CustomModifiers.Entry>
-       {
-               // note that FromReqOpt assumes that Initial == ModOpt
-               private static Type Initial { get { return MarkerType.ModOpt; } }
-               private readonly Type[] types;
-
-               internal CustomModifiers(List<CustomModifiersBuilder.Item> list)
-               {
-                       bool required = Initial == MarkerType.ModReq;
-                       int count = list.Count;
-                       foreach (CustomModifiersBuilder.Item item in list)
-                       {
-                               if (item.required != required)
-                               {
-                                       required = item.required;
-                                       count++;
-                               }
-                       }
-                       types = new Type[count];
-                       required = Initial == MarkerType.ModReq;
-                       int index = 0;
-                       foreach (CustomModifiersBuilder.Item item in list)
-                       {
-                               if (item.required != required)
-                               {
-                                       required = item.required;
-                                       types[index++] = required ? MarkerType.ModReq : MarkerType.ModOpt;
-                               }
-                               types[index++] = item.type;
-                       }
-               }
-
-               private CustomModifiers(Type[] types)
-               {
-                       Debug.Assert(types == null || types.Length != 0);
-                       this.types = types;
-               }
-
-               public struct Enumerator : IEnumerator<Entry>
-               {
-                       private readonly Type[] types;
-                       private int index;
-                       private bool required;
-
-                       internal Enumerator(Type[] types)
-                       {
-                               this.types = types;
-                               this.index = -1;
-                               this.required = Initial == MarkerType.ModReq;
-                       }
-
-                       void System.Collections.IEnumerator.Reset()
-                       {
-                               this.index = -1;
-                               this.required = Initial == MarkerType.ModReq;
-                       }
-
-                       public Entry Current
-                       {
-                               get { return new Entry(types[index], required); }
-                       }
-
-                       public bool MoveNext()
-                       {
-                               if (types == null || index == types.Length)
-                               {
-                                       return false;
-                               }
-                               index++;
-                               if (index == types.Length)
-                               {
-                                       return false;
-                               }
-                               else if (types[index] == MarkerType.ModOpt)
-                               {
-                                       required = false;
-                                       index++;
-                               }
-                               else if (types[index] == MarkerType.ModReq)
-                               {
-                                       required = true;
-                                       index++;
-                               }
-                               return true;
-                       }
-
-                       object System.Collections.IEnumerator.Current
-                       {
-                               get { return Current; }
-                       }
-
-                       void IDisposable.Dispose()
-                       {
-                       }
-               }
-
-               public struct Entry
-               {
-                       private readonly Type type;
-                       private readonly bool required;
-
-                       internal Entry(Type type, bool required)
-                       {
-                               this.type = type;
-                               this.required = required;
-                       }
-
-                       public Type Type
-                       {
-                               get { return type; }
-                       }
-
-                       public bool IsRequired
-                       {
-                               get { return required; }
-                       }
-               }
-
-               public Enumerator GetEnumerator()
-               {
-                       return new Enumerator(types);
-               }
-
-               IEnumerator<Entry> IEnumerable<Entry>.GetEnumerator()
-               {
-                       return GetEnumerator();
-               }
-
-               System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
-               {
-                       return GetEnumerator();
-               }
-
-               public bool IsEmpty
-               {
-                       get { return types == null; }
-               }
-
-               public bool Equals(CustomModifiers other)
-               {
-                       return Util.ArrayEquals(types, other.types);
-               }
-
-               public override bool Equals(object obj)
-               {
-                       CustomModifiers? other = obj as CustomModifiers?;
-                       return other != null && Equals(other.Value);
-               }
-
-               public override int GetHashCode()
-               {
-                       return Util.GetHashCode(types);
-               }
-
-               public override string ToString()
-               {
-                       if (types == null)
-                       {
-                               return string.Empty;
-                       }
-                       StringBuilder sb = new StringBuilder();
-                       string sep = "";
-                       foreach (Entry e in this)
-                       {
-                               sb.Append(sep).Append(e.IsRequired ? "modreq(" : "modopt(").Append(e.Type.FullName).Append(')');
-                               sep = " ";
-                       }
-                       return sb.ToString();
-               }
-
-               private Type[] GetRequiredOrOptional(bool required)
-               {
-                       if (types == null)
-                       {
-                               return Type.EmptyTypes;
-                       }
-                       int count = 0;
-                       foreach (Entry e in this)
-                       {
-                               if (e.IsRequired == required)
-                               {
-                                       count++;
-                               }
-                       }
-                       Type[] result = new Type[count];
-                       foreach (Entry e in this)
-                       {
-                               if (e.IsRequired == required)
-                               {
-                                       // FXBUG reflection (and ildasm) return custom modifiers in reverse order
-                                       // while SRE writes them in the specified order
-                                       result[--count] = e.Type;
-                               }
-                       }
-                       return result;
-               }
-
-               internal Type[] GetRequired()
-               {
-                       return GetRequiredOrOptional(true);
-               }
-
-               internal Type[] GetOptional()
-               {
-                       return GetRequiredOrOptional(false);
-               }
-
-               internal CustomModifiers Bind(IGenericBinder binder)
-               {
-                       if (types == null)
-                       {
-                               return this;
-                       }
-                       Type[] result = types;
-                       for (int i = 0; i < types.Length; i++)
-                       {
-                               if (types[i] == MarkerType.ModOpt || types[i] == MarkerType.ModReq)
-                               {
-                                       continue;
-                               }
-                               Type type = types[i].BindTypeParameters(binder);
-                               if (!ReferenceEquals(type, types[i]))
-                               {
-                                       if (result == types)
-                                       {
-                                               result = (Type[])types.Clone();
-                                       }
-                                       result[i] = type;
-                               }
-                       }
-                       return new CustomModifiers(result);
-               }
-
-               internal static CustomModifiers Read(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       byte b = br.PeekByte();
-                       if (!IsCustomModifier(b))
-                       {
-                               return new CustomModifiers();
-                       }
-                       List<Type> list = new List<Type>();
-                       Type mode = Initial;
-                       do
-                       {
-                               Type cmod = br.ReadByte() == Signature.ELEMENT_TYPE_CMOD_REQD ? MarkerType.ModReq : MarkerType.ModOpt;
-                               if (mode != cmod)
-                               {
-                                       mode = cmod;
-                                       list.Add(mode);
-                               }
-                               list.Add(Signature.ReadTypeDefOrRefEncoded(module, br, context));
-                               b = br.PeekByte();
-                       }
-                       while (IsCustomModifier(b));
-                       return new CustomModifiers(list.ToArray());
-               }
-
-               internal static void Skip(ByteReader br)
-               {
-                       byte b = br.PeekByte();
-                       while (IsCustomModifier(b))
-                       {
-                               br.ReadByte();
-                               br.ReadCompressedUInt();
-                               b = br.PeekByte();
-                       }
-               }
-
-               internal static CustomModifiers FromReqOpt(Type[] req, Type[] opt)
-               {
-                       List<Type> list = null;
-                       if (opt != null && opt.Length != 0)
-                       {
-                               Debug.Assert(Initial == MarkerType.ModOpt);
-                               list = new List<Type>(opt);
-                       }
-                       if (req != null && req.Length != 0)
-                       {
-                               if (list == null)
-                               {
-                                       list = new List<Type>();
-                               }
-                               list.Add(MarkerType.ModReq);
-                               list.AddRange(req);
-                       }
-                       if (list == null)
-                       {
-                               return new CustomModifiers();
-                       }
-                       else
-                       {
-                               return new CustomModifiers(list.ToArray());
-                       }
-               }
-
-               private static bool IsCustomModifier(byte b)
-               {
-                       return b == Signature.ELEMENT_TYPE_CMOD_OPT || b == Signature.ELEMENT_TYPE_CMOD_REQD;
-               }
-
-               internal static CustomModifiers Combine(CustomModifiers mods1, CustomModifiers mods2)
-               {
-                       if (mods1.IsEmpty)
-                       {
-                               return mods2;
-                       }
-                       else if (mods2.IsEmpty)
-                       {
-                               return mods1;
-                       }
-                       else
-                       {
-                               Type[] combo = new Type[mods1.types.Length + mods2.types.Length];
-                               Array.Copy(mods1.types, combo, mods1.types.Length);
-                               Array.Copy(mods2.types, 0, combo, mods1.types.Length, mods2.types.Length);
-                               return new CustomModifiers(combo);
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/AssemblyBuilder.cs b/mcs/class/IKVM.Reflection/Emit/AssemblyBuilder.cs
deleted file mode 100644 (file)
index 910a6db..0000000
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Configuration.Assemblies;
-using System.IO;
-using System.Diagnostics;
-using System.Globalization;
-using System.Resources;
-using System.Security.Cryptography;
-using System.Security;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Impl;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class AssemblyBuilder : Assembly
-       {
-               private readonly string name;
-               private ushort majorVersion;
-               private ushort minorVersion;
-               private ushort buildVersion;
-               private ushort revisionVersion;
-               private string culture;
-               private AssemblyNameFlags flags;
-               private AssemblyHashAlgorithm hashAlgorithm;
-               private StrongNameKeyPair keyPair;
-               private byte[] publicKey;
-               internal readonly string dir;
-               private readonly PermissionSet requiredPermissions;
-               private readonly PermissionSet optionalPermissions;
-               private readonly PermissionSet refusedPermissions;
-               private PEFileKinds fileKind = PEFileKinds.Dll;
-               private MethodInfo entryPoint;
-               private VersionInfo versionInfo;
-               private byte[] win32icon;
-               private byte[] win32manifest;
-               private byte[] win32resources;
-               private string imageRuntimeVersion;
-               internal int mdStreamVersion = 0x20000;
-               private Module pseudoManifestModule;
-               private readonly List<ResourceFile> resourceFiles = new List<ResourceFile>();
-               private readonly List<ModuleBuilder> modules = new List<ModuleBuilder>();
-               private readonly List<Module> addedModules = new List<Module>();
-               private readonly List<CustomAttributeBuilder> customAttributes = new List<CustomAttributeBuilder>();
-               private readonly List<CustomAttributeBuilder> declarativeSecurity = new List<CustomAttributeBuilder>();
-               private readonly List<Type> typeForwarders = new List<Type>();
-
-               private struct ResourceFile
-               {
-                       internal string Name;
-                       internal string FileName;
-                       internal ResourceAttributes Attributes;
-                       internal ResourceWriter Writer;
-               }
-
-               internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
-                       : base(universe)
-               {
-                       this.name = name.Name;
-                       SetVersionHelper(name.Version);
-                       if (!string.IsNullOrEmpty(name.Culture))
-                       {
-                               this.culture = name.Culture;
-                       }
-                       this.flags = name.RawFlags;
-                       this.hashAlgorithm = name.HashAlgorithm;
-                       if (this.hashAlgorithm == AssemblyHashAlgorithm.None)
-                       {
-                               this.hashAlgorithm = AssemblyHashAlgorithm.SHA1;
-                       }
-                       this.keyPair = name.KeyPair;
-                       if (this.keyPair != null)
-                       {
-                               this.publicKey = this.keyPair.PublicKey;
-                       }
-                       else
-                       {
-                               byte[] publicKey = name.GetPublicKey();
-                               if (publicKey != null && publicKey.Length != 0)
-                               {
-                                       this.publicKey = (byte[])publicKey.Clone();
-                               }
-                       }
-                       this.dir = dir ?? ".";
-                       this.requiredPermissions = requiredPermissions;
-                       this.optionalPermissions = optionalPermissions;
-                       this.refusedPermissions = refusedPermissions;
-                       if (universe.HasMscorlib && !universe.Mscorlib.__IsMissing && universe.Mscorlib.ImageRuntimeVersion != null)
-                       {
-                               this.imageRuntimeVersion = universe.Mscorlib.ImageRuntimeVersion;
-                       }
-                       else
-                       {
-                               this.imageRuntimeVersion = typeof(object).Assembly.ImageRuntimeVersion;
-                       }
-               }
-
-               private void SetVersionHelper(Version version)
-               {
-                       if (version == null)
-                       {
-                               majorVersion = 0;
-                               minorVersion = 0;
-                               buildVersion = 0;
-                               revisionVersion = 0;
-                       }
-                       else
-                       {
-                               majorVersion = (ushort)version.Major;
-                               minorVersion = (ushort)version.Minor;
-                               buildVersion = version.Build == -1 ? (ushort)0 : (ushort)version.Build;
-                               revisionVersion = version.Revision == -1 ? (ushort)0 : (ushort)version.Revision;
-                       }
-               }
-
-               private void Rename(AssemblyName oldName)
-               {
-                       this.fullName = null;
-                       universe.RenameAssembly(this, oldName);
-               }
-
-               public void __SetAssemblyVersion(Version version)
-               {
-                       AssemblyName oldName = GetName();
-                       SetVersionHelper(version);
-                       Rename(oldName);
-               }
-
-               public void __SetAssemblyCulture(string cultureName)
-               {
-                       AssemblyName oldName = GetName();
-                       this.culture = cultureName;
-                       Rename(oldName);
-               }
-
-               public void __SetAssemblyKeyPair(StrongNameKeyPair keyPair)
-               {
-                       AssemblyName oldName = GetName();
-                       this.keyPair = keyPair;
-                       if (keyPair != null)
-                       {
-                               this.publicKey = keyPair.PublicKey;
-                       }
-                       Rename(oldName);
-               }
-
-               // this is used in combination with delay signing
-               public void __SetAssemblyPublicKey(byte[] publicKey)
-               {
-                       AssemblyName oldName = GetName();
-                       this.publicKey = publicKey == null ? null : (byte[])publicKey.Clone();
-                       Rename(oldName);
-               }
-
-               public void __SetAssemblyAlgorithmId(AssemblyHashAlgorithm hashAlgorithm)
-               {
-                       this.hashAlgorithm = hashAlgorithm;
-               }
-
-               [Obsolete("Use __AssemblyFlags property instead.")]
-               public void __SetAssemblyFlags(AssemblyNameFlags flags)
-               {
-                       this.__AssemblyFlags = flags;
-               }
-
-               protected override AssemblyNameFlags GetAssemblyFlags()
-               {
-                       return flags;
-               }
-
-               public new AssemblyNameFlags __AssemblyFlags
-               {
-                       get { return flags; }
-                       set
-                       {
-                               AssemblyName oldName = GetName();
-                               this.flags = value;
-                               Rename(oldName);
-                       }
-               }
-
-               internal string Name
-               {
-                       get { return name; }
-               }
-
-               public override AssemblyName GetName()
-               {
-                       AssemblyName n = new AssemblyName();
-                       n.Name = name;
-                       n.Version = new Version(majorVersion, minorVersion, buildVersion, revisionVersion);
-                       n.Culture = culture ?? "";
-                       n.HashAlgorithm = hashAlgorithm;
-                       n.RawFlags = flags;
-                       n.SetPublicKey(publicKey != null ? (byte[])publicKey.Clone() : Empty<byte>.Array);
-                       n.KeyPair = keyPair;
-                       return n;
-               }
-
-               public override string Location
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public ModuleBuilder DefineDynamicModule(string name, string fileName)
-               {
-                       return DefineDynamicModule(name, fileName, false);
-               }
-
-               public ModuleBuilder DefineDynamicModule(string name, string fileName, bool emitSymbolInfo)
-               {
-                       ModuleBuilder module = new ModuleBuilder(this, name, fileName, emitSymbolInfo);
-                       modules.Add(module);
-                       return module;
-               }
-
-               public ModuleBuilder GetDynamicModule(string name)
-               {
-                       foreach (ModuleBuilder module in modules)
-                       {
-                               if (module.Name == name)
-                               {
-                                       return module;
-                               }
-                       }
-                       return null;
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       customAttributes.Add(customBuilder);
-               }
-
-               public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
-               {
-                       declarativeSecurity.Add(customBuilder);
-               }
-
-               public void __AddTypeForwarder(Type type)
-               {
-                       typeForwarders.Add(type);
-               }
-
-               public void SetEntryPoint(MethodInfo entryMethod)
-               {
-                       SetEntryPoint(entryMethod, PEFileKinds.ConsoleApplication);
-               }
-
-               public void SetEntryPoint(MethodInfo entryMethod, PEFileKinds fileKind)
-               {
-                       this.entryPoint = entryMethod;
-                       this.fileKind = fileKind;
-               }
-
-               public void __Save(Stream stream, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       if (!stream.CanRead || !stream.CanWrite || !stream.CanSeek || stream.Position != 0)
-                       {
-                               throw new ArgumentException("Stream must support read/write/seek and current position must be zero.", "stream");
-                       }
-                       if (modules.Count != 1)
-                       {
-                               throw new NotSupportedException("Saving to a stream is only supported for single module assemblies.");
-                       }
-                       SaveImpl(modules[0].fileName, stream, portableExecutableKind, imageFileMachine);
-               }
-
-               public void Save(string assemblyFileName)
-               {
-                       Save(assemblyFileName, PortableExecutableKinds.ILOnly, ImageFileMachine.I386);
-               }
-
-               public void Save(string assemblyFileName, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       SaveImpl(assemblyFileName, null, portableExecutableKind, imageFileMachine);
-               }
-
-               private void SaveImpl(string assemblyFileName, Stream streamOrNull, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       ModuleBuilder manifestModule = null;
-
-                       foreach (ModuleBuilder moduleBuilder in modules)
-                       {
-                               moduleBuilder.SetIsSaved();
-                               moduleBuilder.PopulatePropertyAndEventTables();
-
-                               if (manifestModule == null
-                                       && string.Compare(moduleBuilder.fileName, assemblyFileName, StringComparison.OrdinalIgnoreCase) == 0)
-                               {
-                                       manifestModule = moduleBuilder;
-                               }
-                       }
-
-                       if (manifestModule == null)
-                       {
-                               manifestModule = DefineDynamicModule("RefEmit_OnDiskManifestModule", assemblyFileName, false);
-                       }
-
-                       AssemblyTable.Record assemblyRecord = new AssemblyTable.Record();
-                       assemblyRecord.HashAlgId = (int)hashAlgorithm;
-                       assemblyRecord.Name = manifestModule.Strings.Add(name);
-                       assemblyRecord.MajorVersion = majorVersion;
-                       assemblyRecord.MinorVersion = minorVersion;
-                       assemblyRecord.BuildNumber = buildVersion;
-                       assemblyRecord.RevisionNumber = revisionVersion;
-                       if (publicKey != null)
-                       {
-                               assemblyRecord.PublicKey = manifestModule.Blobs.Add(ByteBuffer.Wrap(publicKey));
-                               assemblyRecord.Flags = (int)(flags | AssemblyNameFlags.PublicKey);
-                       }
-                       else
-                       {
-                               assemblyRecord.Flags = (int)(flags & ~AssemblyNameFlags.PublicKey);
-                       }
-                       if (culture != null)
-                       {
-                               assemblyRecord.Culture = manifestModule.Strings.Add(culture);
-                       }
-                       int token = 0x20000000 + manifestModule.AssemblyTable.AddRecord(assemblyRecord);
-
-#pragma warning disable 618
-                       // this values are obsolete, but we already know that so we disable the warning
-                       System.Security.Permissions.SecurityAction requestMinimum = System.Security.Permissions.SecurityAction.RequestMinimum;
-                       System.Security.Permissions.SecurityAction requestOptional = System.Security.Permissions.SecurityAction.RequestOptional;
-                       System.Security.Permissions.SecurityAction requestRefuse = System.Security.Permissions.SecurityAction.RequestRefuse;
-#pragma warning restore 618
-                       if (requiredPermissions != null)
-                       {
-                               manifestModule.AddDeclarativeSecurity(token, requestMinimum, requiredPermissions);
-                       }
-                       if (optionalPermissions != null)
-                       {
-                               manifestModule.AddDeclarativeSecurity(token, requestOptional, optionalPermissions);
-                       }
-                       if (refusedPermissions != null)
-                       {
-                               manifestModule.AddDeclarativeSecurity(token, requestRefuse, refusedPermissions);
-                       }
-
-                       ResourceSection unmanagedResources = versionInfo != null || win32icon != null || win32manifest != null || win32resources != null
-                               ? new ResourceSection()
-                               : null;
-
-                       if (versionInfo != null)
-                       {
-                               versionInfo.SetName(GetName());
-                               versionInfo.SetFileName(assemblyFileName);
-                               foreach (CustomAttributeBuilder cab in customAttributes)
-                               {
-                                       // .NET doesn't support copying blob custom attributes into the version info
-                                       if (!cab.HasBlob)
-                                       {
-                                               versionInfo.SetAttribute(cab);
-                                       }
-                               }
-                               ByteBuffer versionInfoData = new ByteBuffer(512);
-                               versionInfo.Write(versionInfoData);
-                               unmanagedResources.AddVersionInfo(versionInfoData);
-                       }
-
-                       if (win32icon != null)
-                       {
-                               unmanagedResources.AddIcon(win32icon);
-                       }
-
-                       if (win32manifest != null)
-                       {
-                               unmanagedResources.AddManifest(win32manifest, fileKind == PEFileKinds.Dll ? (ushort)2 : (ushort)1);
-                       }
-
-                       if (win32resources != null)
-                       {
-                               unmanagedResources.ExtractResources(win32resources);
-                       }
-
-                       foreach (CustomAttributeBuilder cab in customAttributes)
-                       {
-                               // we intentionally don't filter out the version info (pseudo) custom attributes (to be compatible with .NET)
-                               manifestModule.SetCustomAttribute(0x20000001, cab);
-                       }
-
-                       manifestModule.AddDeclarativeSecurity(0x20000001, declarativeSecurity);
-
-                       foreach (Type type in typeForwarders)
-                       {
-                               manifestModule.AddTypeForwarder(type);
-                       }
-
-                       foreach (ResourceFile resfile in resourceFiles)
-                       {
-                               if (resfile.Writer != null)
-                               {
-                                       resfile.Writer.Generate();
-                                       resfile.Writer.Close();
-                               }
-                               int fileToken = AddFile(manifestModule, resfile.FileName, 1 /*ContainsNoMetaData*/);
-                               ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
-                               rec.Offset = 0;
-                               rec.Flags = (int)resfile.Attributes;
-                               rec.Name = manifestModule.Strings.Add(resfile.Name);
-                               rec.Implementation = fileToken;
-                               manifestModule.ManifestResource.AddRecord(rec);
-                       }
-
-                       int entryPointToken = 0;
-
-                       foreach (ModuleBuilder moduleBuilder in modules)
-                       {
-                               moduleBuilder.FillAssemblyRefTable();
-                               moduleBuilder.EmitResources();
-                               if (moduleBuilder != manifestModule)
-                               {
-                                       int fileToken;
-                                       if (entryPoint != null && entryPoint.Module == moduleBuilder)
-                                       {
-                                               ModuleWriter.WriteModule(null, null, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, moduleBuilder.unmanagedResources, entryPoint.MetadataToken);
-                                               entryPointToken = fileToken = AddFile(manifestModule, moduleBuilder.fileName, 0 /*ContainsMetaData*/);
-                                       }
-                                       else
-                                       {
-                                               ModuleWriter.WriteModule(null, null, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, moduleBuilder.unmanagedResources, 0);
-                                               fileToken = AddFile(manifestModule, moduleBuilder.fileName, 0 /*ContainsMetaData*/);
-                                       }
-                                       moduleBuilder.ExportTypes(fileToken, manifestModule);
-                               }
-                       }
-
-                       foreach (Module module in addedModules)
-                       {
-                               int fileToken = AddFile(manifestModule, module.FullyQualifiedName, 0 /*ContainsMetaData*/);
-                               module.ExportTypes(fileToken, manifestModule);
-                       }
-
-                       if (entryPointToken == 0 && entryPoint != null)
-                       {
-                               entryPointToken = entryPoint.MetadataToken;
-                       }
-
-                       // finally, write the manifest module
-                       ModuleWriter.WriteModule(keyPair, publicKey, manifestModule, fileKind, portableExecutableKind, imageFileMachine, unmanagedResources ?? manifestModule.unmanagedResources, entryPointToken, streamOrNull);
-               }
-
-               private int AddFile(ModuleBuilder manifestModule, string fileName, int flags)
-               {
-                       SHA1Managed hash = new SHA1Managed();
-                       string fullPath = fileName;
-                       if (dir != null)
-                       {
-                               fullPath = Path.Combine(dir, fileName);
-                       }
-                       using (FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
-                       {
-                               using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
-                               {
-                                       byte[] buf = new byte[8192];
-                                       ModuleWriter.HashChunk(fs, cs, buf, (int)fs.Length);
-                               }
-                       }
-                       return manifestModule.__AddModule(flags, Path.GetFileName(fileName), hash.Hash);
-               }
-
-               public void AddResourceFile(string name, string fileName)
-               {
-                       AddResourceFile(name, fileName, ResourceAttributes.Public);
-               }
-
-               public void AddResourceFile(string name, string fileName, ResourceAttributes attribs)
-               {
-                       ResourceFile resfile = new ResourceFile();
-                       resfile.Name = name;
-                       resfile.FileName = fileName;
-                       resfile.Attributes = attribs;
-                       resourceFiles.Add(resfile);
-               }
-
-               public IResourceWriter DefineResource(string name, string description, string fileName)
-               {
-                       return DefineResource(name, description, fileName, ResourceAttributes.Public);
-               }
-
-               public IResourceWriter DefineResource(string name, string description, string fileName, ResourceAttributes attribute)
-               {
-                       // FXBUG we ignore the description, because there is no such thing
-
-                       string fullPath = fileName;
-                       if (dir != null)
-                       {
-                               fullPath = Path.Combine(dir, fileName);
-                       }
-                       ResourceWriter rw = new ResourceWriter(fullPath);
-                       ResourceFile resfile;
-                       resfile.Name = name;
-                       resfile.FileName = fileName;
-                       resfile.Attributes = attribute;
-                       resfile.Writer = rw;
-                       resourceFiles.Add(resfile);
-                       return rw;
-               }
-
-               public void DefineVersionInfoResource()
-               {
-                       if (versionInfo != null || win32resources != null)
-                       {
-                               throw new ArgumentException("Native resource has already been defined.");
-                       }
-                       versionInfo = new VersionInfo();
-               }
-
-               public void DefineVersionInfoResource(string product, string productVersion, string company, string copyright, string trademark)
-               {
-                       if (versionInfo != null || win32resources != null)
-                       {
-                               throw new ArgumentException("Native resource has already been defined.");
-                       }
-                       versionInfo = new VersionInfo();
-                       versionInfo.product = product;
-                       versionInfo.informationalVersion = productVersion;
-                       versionInfo.company = company;
-                       versionInfo.copyright = copyright;
-                       versionInfo.trademark = trademark;
-               }
-
-               public void __DefineIconResource(byte[] iconFile)
-               {
-                       if (win32icon != null || win32resources != null)
-                       {
-                               throw new ArgumentException("Native resource has already been defined.");
-                       }
-                       win32icon = (byte[])iconFile.Clone();
-               }
-
-               public void __DefineManifestResource(byte[] manifest)
-               {
-                       if (win32manifest != null || win32resources != null)
-                       {
-                               throw new ArgumentException("Native resource has already been defined.");
-                       }
-                       win32manifest = (byte[])manifest.Clone();
-               }
-
-               public void __DefineUnmanagedResource(byte[] resource)
-               {
-                       if (versionInfo != null || win32icon != null || win32manifest != null || win32resources != null)
-                       {
-                               throw new ArgumentException("Native resource has already been defined.");
-                       }
-                       // The standard .NET DefineUnmanagedResource(byte[]) is useless, because it embeds "resource" (as-is) as the .rsrc section,
-                       // but it doesn't set the PE file Resource Directory entry to point to it. That's why we have a renamed version, which behaves
-                       // like DefineUnmanagedResource(string).
-                       win32resources = (byte[])resource.Clone();
-               }
-
-               public void DefineUnmanagedResource(string resourceFileName)
-               {
-                       // This method reads the specified resource file (Win32 .res file) and converts it into the appropriate format and embeds it in the .rsrc section,
-                       // also setting the Resource Directory entry.
-                       __DefineUnmanagedResource(File.ReadAllBytes(resourceFileName));
-               }
-
-               public override Type[] GetTypes()
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (ModuleBuilder module in modules)
-                       {
-                               module.GetTypesImpl(list);
-                       }
-                       foreach (Module module in addedModules)
-                       {
-                               module.GetTypesImpl(list);
-                       }
-                       return list.ToArray();
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       foreach (ModuleBuilder mb in modules)
-                       {
-                               Type type = mb.FindType(typeName);
-                               if (type != null)
-                               {
-                                       return type;
-                               }
-                       }
-                       foreach (Module module in addedModules)
-                       {
-                               Type type = module.FindType(typeName);
-                               if (type != null)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       foreach (ModuleBuilder mb in modules)
-                       {
-                               Type type = mb.FindTypeIgnoreCase(lowerCaseName);
-                               if (type != null)
-                               {
-                                       return type;
-                               }
-                       }
-                       foreach (Module module in addedModules)
-                       {
-                               Type type = module.FindTypeIgnoreCase(lowerCaseName);
-                               if (type != null)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               public override string ImageRuntimeVersion
-               {
-                       get { return imageRuntimeVersion; }
-               }
-
-               public void __SetImageRuntimeVersion(string imageRuntimeVersion, int mdStreamVersion)
-               {
-                       this.imageRuntimeVersion = imageRuntimeVersion;
-                       this.mdStreamVersion = mdStreamVersion;
-               }
-
-               public override Module ManifestModule
-               {
-                       get
-                       {
-                               if (pseudoManifestModule == null)
-                               {
-                                       pseudoManifestModule = new ManifestModule(this);
-                               }
-                               return pseudoManifestModule;
-                       }
-               }
-
-               public override MethodInfo EntryPoint
-               {
-                       get { return entryPoint; }
-               }
-
-               public override AssemblyName[] GetReferencedAssemblies()
-               {
-                       return Empty<AssemblyName>.Array;
-               }
-
-               public override Module[] GetLoadedModules(bool getResourceModules)
-               {
-                       return GetModules(getResourceModules);
-               }
-
-               public override Module[] GetModules(bool getResourceModules)
-               {
-                       List<Module> list = new List<Module>();
-                       foreach (ModuleBuilder module in modules)
-                       {
-                               if (getResourceModules || !module.IsResource())
-                               {
-                                       list.Add(module);
-                               }
-                       }
-                       foreach (Module module in addedModules)
-                       {
-                               if (getResourceModules || !module.IsResource())
-                               {
-                                       list.Add(module);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public override Module GetModule(string name)
-               {
-                       foreach (ModuleBuilder module in modules)
-                       {
-                               if (module.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
-                               {
-                                       return module;
-                               }
-                       }
-                       foreach (Module module in addedModules)
-                       {
-                               if (module.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase))
-                               {
-                                       return module;
-                               }
-                       }
-                       return null;
-               }
-
-               public Module __AddModule(RawModule module)
-               {
-                       Module mod = module.ToModule(this);
-                       addedModules.Add(mod);
-                       return mod;
-               }
-
-               public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public override string[] GetManifestResourceNames()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public override Stream GetManifestResourceStream(string resourceName)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public override bool IsDynamic
-               {
-                       get { return true; }
-               }
-
-               internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
-               {
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       foreach (CustomAttributeBuilder cab in customAttributes)
-                       {
-                               if (attributeType == null || attributeType.IsAssignableFrom(cab.Constructor.DeclaringType))
-                               {
-                                       list.Add(cab.ToData(this));
-                               }
-                       }
-                       return list;
-               }
-
-               internal bool IsWindowsRuntime
-               {
-                       get { return (flags & (AssemblyNameFlags)0x200) != 0; }
-               }
-       }
-
-       sealed class ManifestModule : NonPEModule
-       {
-               private readonly AssemblyBuilder assembly;
-               private readonly Guid guid = Guid.NewGuid();
-
-               internal ManifestModule(AssemblyBuilder assembly)
-                       : base(assembly.universe)
-               {
-                       this.assembly = assembly;
-               }
-
-               public override int MDStreamVersion
-               {
-                       get { return assembly.mdStreamVersion; }
-               }
-
-               public override Assembly Assembly
-               {
-                       get { return assembly; }
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       return null;
-               }
-
-               internal override void  GetTypesImpl(List<Type> list)
-               {
-               }
-
-               public override string FullyQualifiedName
-               {
-                       get { return Path.Combine(assembly.dir, "RefEmit_InMemoryManifestModule"); }
-               }
-
-               public override string Name
-               {
-                       get { return "<In Memory Module>"; }
-               }
-
-               public override Guid ModuleVersionId
-               {
-                       get { return guid; }
-               }
-
-               public override string ScopeName
-               {
-                       get { return "RefEmit_InMemoryManifestModule"; }
-               }
-
-               protected override Exception NotSupportedException()
-               {
-                       return new InvalidOperationException();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/ConstructorBuilder.cs b/mcs/class/IKVM.Reflection/Emit/ConstructorBuilder.cs
deleted file mode 100644 (file)
index 02ccca1..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class ConstructorBuilder : ConstructorInfo
-       {
-               private readonly MethodBuilder methodBuilder;
-
-               internal ConstructorBuilder(MethodBuilder mb)
-               {
-                       this.methodBuilder = mb;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       ConstructorBuilder other = obj as ConstructorBuilder;
-                       return other != null && other.methodBuilder.Equals(methodBuilder);
-               }
-
-               public override int GetHashCode()
-               {
-                       return methodBuilder.GetHashCode();
-               }
-
-               public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       methodBuilder.__SetSignature(returnType, returnTypeCustomModifiers, parameterTypes, parameterTypeCustomModifiers);
-               }
-
-               [Obsolete("Please use __SetSignature(Type, CustomModifiers, Type[], CustomModifiers[]) instead.")]
-               public void __SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       methodBuilder.SetSignature(returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
-               }
-
-               public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string strParamName)
-               {
-                       return methodBuilder.DefineParameter(position, attributes, strParamName);
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       methodBuilder.SetCustomAttribute(customBuilder);
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con,     byte[] binaryAttribute)
-               {
-                       methodBuilder.SetCustomAttribute(con, binaryAttribute);
-               }
-
-               public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
-               {
-                       methodBuilder.__AddDeclarativeSecurity(customBuilder);
-               }
-
-               public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
-               {
-                       methodBuilder.AddDeclarativeSecurity(securityAction, permissionSet);
-               }
-
-               public void SetImplementationFlags(MethodImplAttributes attributes)
-               {
-                       methodBuilder.SetImplementationFlags(attributes);
-               }
-
-               public ILGenerator GetILGenerator()
-               {
-                       return methodBuilder.GetILGenerator();
-               }
-
-               public ILGenerator GetILGenerator(int streamSize)
-               {
-                       return methodBuilder.GetILGenerator(streamSize);
-               }
-
-               public void __ReleaseILGenerator()
-               {
-                       methodBuilder.__ReleaseILGenerator();
-               }
-
-               public Type ReturnType
-               {
-                       get { return methodBuilder.ReturnType; }
-               }
-
-               public Module GetModule()
-               {
-                       return methodBuilder.GetModule();
-               }
-
-               public MethodToken GetToken()
-               {
-                       return methodBuilder.GetToken();
-               }
-
-               public bool InitLocals
-               {
-                       get { return methodBuilder.InitLocals; }
-                       set { methodBuilder.InitLocals = value; }
-               }
-
-               public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
-               {
-                       methodBuilder.SetMethodBody(il, maxStack, localSignature, exceptionHandlers, tokenFixups);
-               }
-
-               internal override MethodInfo GetMethodInfo()
-               {
-                       return methodBuilder;
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return methodBuilder;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/CustomAttributeBuilder.cs b/mcs/class/IKVM.Reflection/Emit/CustomAttributeBuilder.cs
deleted file mode 100644 (file)
index 2b9708b..0000000
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class CustomAttributeBuilder
-       {
-               private readonly ConstructorInfo con;
-               private readonly byte[] blob;
-               private readonly object[] constructorArgs;
-               private readonly PropertyInfo[] namedProperties;
-               private readonly object[] propertyValues;
-               private readonly FieldInfo[] namedFields;
-               private readonly object[] fieldValues;
-
-               internal CustomAttributeBuilder(ConstructorInfo con, byte[] blob)
-               {
-                       this.con = con;
-                       this.blob = blob;
-               }
-
-               private CustomAttributeBuilder(ConstructorInfo con, int securityAction, byte[] blob)
-               {
-                       this.con = con;
-                       this.blob = blob;
-                       this.constructorArgs = new object[] { securityAction };
-               }
-
-               public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs)
-                       : this(con, constructorArgs, null, null, null,null)
-               {
-               }
-
-               public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, FieldInfo[] namedFields, object[] fieldValues)
-                       : this(con, constructorArgs, null, null, namedFields, fieldValues)
-               {
-               }
-
-               public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues)
-                       : this(con, constructorArgs, namedProperties, propertyValues, null, null)
-               {
-               }
-
-               public CustomAttributeBuilder(ConstructorInfo con, object[] constructorArgs, PropertyInfo[] namedProperties, object[] propertyValues, FieldInfo[] namedFields, object[] fieldValues)
-               {
-                       this.con = con;
-                       this.constructorArgs = constructorArgs;
-                       this.namedProperties = namedProperties;
-                       this.propertyValues = propertyValues;
-                       this.namedFields = namedFields;
-                       this.fieldValues = fieldValues;
-               }
-
-               public static CustomAttributeBuilder __FromBlob(ConstructorInfo con, byte[] blob)
-               {
-                       return new CustomAttributeBuilder(con, blob);
-               }
-
-               public static CustomAttributeBuilder __FromBlob(ConstructorInfo con, int securityAction, byte[] blob)
-               {
-                       return new CustomAttributeBuilder(con, securityAction, blob);
-               }
-
-               public static CustomAttributeTypedArgument __MakeTypedArgument(Type type, object value)
-               {
-                       return new CustomAttributeTypedArgument(type, value);
-               }
-
-               private sealed class BlobWriter
-               {
-                       private readonly Assembly assembly;
-                       private readonly CustomAttributeBuilder cab;
-                       private readonly ByteBuffer bb;
-
-                       internal BlobWriter(Assembly assembly, CustomAttributeBuilder cab, ByteBuffer bb)
-                       {
-                               this.assembly = assembly;
-                               this.cab = cab;
-                               this.bb = bb;
-                       }
-
-                       internal void WriteCustomAttributeBlob()
-                       {
-                               // prolog
-                               WriteUInt16(1);
-                               ParameterInfo[] pi = cab.con.GetParameters();
-                               for (int i = 0; i < pi.Length; i++)
-                               {
-                                       WriteFixedArg(pi[i].ParameterType, cab.constructorArgs[i]);
-                               }
-                               WriteNamedArguments(false);
-                       }
-
-                       internal void WriteNamedArguments(bool forDeclSecurity)
-                       {
-                               // NumNamed
-                               int named = 0;
-                               if (cab.namedFields != null)
-                               {
-                                       named += cab.namedFields.Length;
-                               }
-                               if (cab.namedProperties != null)
-                               {
-                                       named += cab.namedProperties.Length;
-                               }
-                               if (forDeclSecurity)
-                               {
-                                       WritePackedLen(named);
-                               }
-                               else
-                               {
-                                       WriteUInt16((ushort)named);
-                               }
-                               if (cab.namedFields != null)
-                               {
-                                       for (int i = 0; i < cab.namedFields.Length; i++)
-                                       {
-                                               WriteNamedArg(0x53, cab.namedFields[i].FieldType, cab.namedFields[i].Name, cab.fieldValues[i]);
-                                       }
-                               }
-                               if (cab.namedProperties != null)
-                               {
-                                       for (int i = 0; i < cab.namedProperties.Length; i++)
-                                       {
-                                               WriteNamedArg(0x54, cab.namedProperties[i].PropertyType, cab.namedProperties[i].Name, cab.propertyValues[i]);
-                                       }
-                               }
-                       }
-
-                       private void WriteNamedArg(byte fieldOrProperty, Type type, string name, object value)
-                       {
-                               WriteByte(fieldOrProperty);
-                               WriteFieldOrPropType(type);
-                               WriteString(name);
-                               WriteFixedArg(type, value);
-                       }
-
-                       private void WriteByte(byte value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteUInt16(ushort value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteInt32(int value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteFixedArg(Type type, object value)
-                       {
-                               Universe u = assembly.universe;
-                               if (type == u.System_String)
-                               {
-                                       WriteString((string)value);
-                               }
-                               else if (type == u.System_Boolean)
-                               {
-                                       WriteByte((bool)value ? (byte)1 : (byte)0);
-                               }
-                               else if (type == u.System_Char)
-                               {
-                                       WriteUInt16((char)value);
-                               }
-                               else if (type == u.System_SByte)
-                               {
-                                       WriteByte((byte)(sbyte)value);
-                               }
-                               else if (type == u.System_Byte)
-                               {
-                                       WriteByte((byte)value);
-                               }
-                               else if (type == u.System_Int16)
-                               {
-                                       WriteUInt16((ushort)(short)value);
-                               }
-                               else if (type == u.System_UInt16)
-                               {
-                                       WriteUInt16((ushort)value);
-                               }
-                               else if (type == u.System_Int32)
-                               {
-                                       WriteInt32((int)value);
-                               }
-                               else if (type == u.System_UInt32)
-                               {
-                                       WriteInt32((int)(uint)value);
-                               }
-                               else if (type == u.System_Int64)
-                               {
-                                       WriteInt64((long)value);
-                               }
-                               else if (type == u.System_UInt64)
-                               {
-                                       WriteInt64((long)(ulong)value);
-                               }
-                               else if (type == u.System_Single)
-                               {
-                                       WriteSingle((float)value);
-                               }
-                               else if (type == u.System_Double)
-                               {
-                                       WriteDouble((double)value);
-                               }
-                               else if (type == u.System_Type)
-                               {
-                                       WriteTypeName((Type)value);
-                               }
-                               else if (type == u.System_Object)
-                               {
-                                       if (value == null)
-                                       {
-                                               type = u.System_String;
-                                       }
-                                       else if (value is Type)
-                                       {
-                                               // value.GetType() would return a subclass of Type, but we don't want to deal with that
-                                               type = u.System_Type;
-                                       }
-                                       else if (value is CustomAttributeTypedArgument)
-                                       {
-                                               CustomAttributeTypedArgument cta = (CustomAttributeTypedArgument)value;
-                                               value = cta.Value;
-                                               type = cta.ArgumentType;
-                                       }
-                                       else
-                                       {
-                                               type = u.Import(value.GetType());
-                                       }
-                                       WriteFieldOrPropType(type);
-                                       WriteFixedArg(type, value);
-                               }
-                               else if (type.IsArray)
-                               {
-                                       if (value == null)
-                                       {
-                                               WriteInt32(-1);
-                                       }
-                                       else
-                                       {
-                                               Array array = (Array)value;
-                                               Type elemType = type.GetElementType();
-                                               WriteInt32(array.Length);
-                                               foreach (object val in array)
-                                               {
-                                                       WriteFixedArg(elemType, val);
-                                               }
-                                       }
-                               }
-                               else if (type.IsEnum)
-                               {
-                                       WriteFixedArg(type.GetEnumUnderlyingTypeImpl(), value);
-                               }
-                               else
-                               {
-                                       throw new ArgumentException();
-                               }
-                       }
-
-                       private void WriteInt64(long value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteSingle(float value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteDouble(double value)
-                       {
-                               bb.Write(value);
-                       }
-
-                       private void WriteTypeName(Type type)
-                       {
-                               string name = null;
-                               if (type != null)
-                               {
-                                       StringBuilder sb = new StringBuilder();
-                                       GetTypeName(sb, type, false);
-                                       name = sb.ToString();
-                               }
-                               WriteString(name);
-                       }
-
-                       private void GetTypeName(StringBuilder sb, Type type, bool isTypeParam)
-                       {
-                               bool v1 = !assembly.ManifestModule.__IsMissing && assembly.ManifestModule.MDStreamVersion < 0x20000;
-                               bool includeAssemblyName = type.Assembly != assembly && (!v1 || type.Assembly != type.Module.universe.Mscorlib);
-                               if (isTypeParam && includeAssemblyName)
-                               {
-                                       sb.Append('[');
-                               }
-                               GetTypeNameImpl(sb, type);
-                               if (includeAssemblyName)
-                               {
-                                       if (v1)
-                                       {
-                                               sb.Append(',');
-                                       }
-                                       else
-                                       {
-                                               sb.Append(", ");
-                                       }
-                                       if (isTypeParam)
-                                       {
-                                               sb.Append(type.Assembly.FullName.Replace("]", "\\]")).Append(']');
-                                       }
-                                       else
-                                       {
-                                               sb.Append(type.Assembly.FullName);
-                                       }
-                               }
-                       }
-
-                       private void GetTypeNameImpl(StringBuilder sb, Type type)
-                       {
-                               if (type.HasElementType)
-                               {
-                                       GetTypeNameImpl(sb, type.GetElementType());
-                                       sb.Append(((ElementHolderType)type).GetSuffix());
-                               }
-                               else if (type.IsConstructedGenericType)
-                               {
-                                       sb.Append(type.GetGenericTypeDefinition().FullName);
-                                       sb.Append('[');
-                                       string sep = "";
-                                       foreach (Type typeParam in type.GetGenericArguments())
-                                       {
-                                               sb.Append(sep);
-                                               GetTypeName(sb, typeParam, true);
-                                               sep = ",";
-                                       }
-                                       sb.Append(']');
-                               }
-                               else
-                               {
-                                       sb.Append(type.FullName);
-                               }
-                       }
-       
-                       private void WriteString(string val)
-                       {
-                               bb.Write(val);
-                       }
-
-                       private void WritePackedLen(int len)
-                       {
-                               bb.WriteCompressedUInt(len);
-                       }
-
-                       private void WriteFieldOrPropType(Type type)
-                       {
-                               Universe u = type.Module.universe;
-                               if (type == u.System_Type)
-                               {
-                                       WriteByte(0x50);
-                               }
-                               else if (type == u.System_Object)
-                               {
-                                       WriteByte(0x51);
-                               }
-                               else if (type == u.System_Boolean)
-                               {
-                                       WriteByte(0x02);
-                               }
-                               else if (type == u.System_Char)
-                               {
-                                       WriteByte(0x03);
-                               }
-                               else if (type == u.System_SByte)
-                               {
-                                       WriteByte(0x04);
-                               }
-                               else if (type == u.System_Byte)
-                               {
-                                       WriteByte(0x05);
-                               }
-                               else if (type == u.System_Int16)
-                               {
-                                       WriteByte(0x06);
-                               }
-                               else if (type == u.System_UInt16)
-                               {
-                                       WriteByte(0x07);
-                               }
-                               else if (type == u.System_Int32)
-                               {
-                                       WriteByte(0x08);
-                               }
-                               else if (type == u.System_UInt32)
-                               {
-                                       WriteByte(0x09);
-                               }
-                               else if (type == u.System_Int64)
-                               {
-                                       WriteByte(0x0A);
-                               }
-                               else if (type == u.System_UInt64)
-                               {
-                                       WriteByte(0x0B);
-                               }
-                               else if (type == u.System_Single)
-                               {
-                                       WriteByte(0x0C);
-                               }
-                               else if (type == u.System_Double)
-                               {
-                                       WriteByte(0x0D);
-                               }
-                               else if (type == u.System_String)
-                               {
-                                       WriteByte(0x0E);
-                               }
-                               else if (type.IsArray)
-                               {
-                                       WriteByte(0x1D);
-                                       WriteFieldOrPropType(type.GetElementType());
-                               }
-                               else if (type.IsEnum)
-                               {
-                                       WriteByte(0x55);
-                                       WriteTypeName(type);
-                               }
-                               else
-                               {
-                                       throw new ArgumentException();
-                               }
-                       }
-               }
-
-               internal bool IsPseudoCustomAttribute
-               {
-                       get { return con.DeclaringType.IsPseudoCustomAttribute; }
-               }
-
-               internal ConstructorInfo Constructor
-               {
-                       get { return con; }
-               }
-
-               internal int WriteBlob(ModuleBuilder moduleBuilder)
-               {
-                       ByteBuffer bb;
-                       if (blob != null)
-                       {
-                               bb = ByteBuffer.Wrap(blob);
-                       }
-                       else
-                       {
-                               bb = new ByteBuffer(100);
-                               BlobWriter bw = new BlobWriter(moduleBuilder.Assembly, this, bb);
-                               bw.WriteCustomAttributeBlob();
-                       }
-                       return moduleBuilder.Blobs.Add(bb);
-               }
-
-               internal object GetConstructorArgument(int pos)
-               {
-                       return constructorArgs[pos];
-               }
-
-               internal int ConstructorArgumentCount
-               {
-                       get { return constructorArgs == null ? 0 : constructorArgs.Length; }
-               }
-
-               internal T? GetFieldValue<T>(string name) where T : struct
-               {
-                       object val = GetFieldValue(name);
-                       if (val is T)
-                       {
-                               return (T)val;
-                       }
-                       else if (val != null)
-                       {
-                               if (typeof(T).IsEnum)
-                               {
-                                       Debug.Assert(Enum.GetUnderlyingType(typeof(T)) == val.GetType());
-                                       return (T)Enum.ToObject(typeof(T), val);
-                               }
-                               else
-                               {
-                                       Debug.Assert(Enum.GetUnderlyingType(val.GetType()) == typeof(T));
-                                       return (T)Convert.ChangeType(val, typeof(T));
-                               }
-                       }
-                       else
-                       {
-                               return null;
-                       }
-               }
-
-               internal object GetFieldValue(string name)
-               {
-                       if (namedFields != null)
-                       {
-                               for (int i = 0; i < namedFields.Length; i++)
-                               {
-                                       if (namedFields[i].Name == name)
-                                       {
-                                               return fieldValues[i];
-                                       }
-                               }
-                       }
-                       return null;
-               }
-
-               internal string GetLegacyDeclSecurity()
-               {
-                       if (con.DeclaringType == con.Module.universe.System_Security_Permissions_PermissionSetAttribute
-                               && blob == null
-                               && (namedFields == null || namedFields.Length == 0)
-                               && namedProperties != null
-                               && namedProperties.Length == 1
-                               && namedProperties[0].Name == "XML")
-                       {
-                               return propertyValues[0] as string;
-                       }
-                       return null;
-               }
-
-               internal void WriteNamedArgumentsForDeclSecurity(ModuleBuilder moduleBuilder, ByteBuffer bb)
-               {
-                       if (blob != null)
-                       {
-                               bb.Write(blob);
-                       }
-                       else
-                       {
-                               BlobWriter bw = new BlobWriter(moduleBuilder.Assembly, this, bb);
-                               bw.WriteNamedArguments(true);
-                       }
-               }
-
-               internal CustomAttributeData ToData(Assembly asm)
-               {
-                       if (blob != null)
-                       {
-                               if (constructorArgs != null)
-                               {
-                                       return new CustomAttributeData(asm, con, (int)constructorArgs[0], blob, -1);
-                               }
-                               return new CustomAttributeData(asm, con, new IKVM.Reflection.Reader.ByteReader(blob, 0, blob.Length));
-                       }
-                       else
-                       {
-                               List<CustomAttributeNamedArgument> namedArgs = new List<CustomAttributeNamedArgument>();
-                               if (namedProperties != null)
-                               {
-                                       for (int i = 0; i < namedProperties.Length; i++)
-                                       {
-                                               namedArgs.Add(new CustomAttributeNamedArgument(namedProperties[i], RewrapValue(namedProperties[i].PropertyType, propertyValues[i])));
-                                       }
-                               }
-                               if (namedFields != null)
-                               {
-                                       for (int i = 0; i < namedFields.Length; i++)
-                                       {
-                                               namedArgs.Add(new CustomAttributeNamedArgument(namedFields[i], RewrapValue(namedFields[i].FieldType, fieldValues[i])));
-                                       }
-                               }
-                               List<CustomAttributeTypedArgument> args = new List<CustomAttributeTypedArgument>(constructorArgs.Length);
-                               ParameterInfo[] parameters = this.Constructor.GetParameters();
-                               for (int i = 0; i < constructorArgs.Length; i++)
-                               {
-                                       args.Add(RewrapValue(parameters[i].ParameterType, constructorArgs[i]));
-                               }
-                               return new CustomAttributeData(asm.ManifestModule, con, args, namedArgs);
-                       }
-               }
-
-               private static CustomAttributeTypedArgument RewrapValue(Type type, object value)
-               {
-                       if (value is Array)
-                       {
-                               Array array = (Array)value;
-                               Type arrayType = type.Module.universe.Import(array.GetType());
-                               return RewrapArray(arrayType, array);
-                       }
-                       else if (value is CustomAttributeTypedArgument)
-                       {
-                               CustomAttributeTypedArgument arg = (CustomAttributeTypedArgument)value;
-                               if (arg.Value is Array)
-                               {
-                                       return RewrapArray(arg.ArgumentType, (Array)arg.Value);
-                               }
-                               return arg;
-                       }
-                       else
-                       {
-                               return new CustomAttributeTypedArgument(type, value);
-                       }
-               }
-
-               private static CustomAttributeTypedArgument RewrapArray(Type arrayType, Array array)
-               {
-                       Type elementType = arrayType.GetElementType();
-                       CustomAttributeTypedArgument[] newArray = new CustomAttributeTypedArgument[array.Length];
-                       for (int i = 0; i < newArray.Length; i++)
-                       {
-                               newArray[i] = RewrapValue(elementType, array.GetValue(i));
-                       }
-                       return new CustomAttributeTypedArgument(arrayType, newArray);
-               }
-
-               internal bool HasBlob
-               {
-                       get { return blob != null; }
-               }
-
-               internal CustomAttributeBuilder DecodeBlob(Assembly asm)
-               {
-                       if (blob == null)
-                       {
-                               return this;
-                       }
-                       else
-                       {
-                               return ToData(asm).__ToBuilder();
-                       }
-               }
-
-               internal byte[] GetBlob(Assembly asm)
-               {
-                       ByteBuffer bb = new ByteBuffer(100);
-                       BlobWriter bw = new BlobWriter(asm, this, bb);
-                       bw.WriteCustomAttributeBlob();
-                       return bb.ToArray();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/CustomModifiersBuilder.cs b/mcs/class/IKVM.Reflection/Emit/CustomModifiersBuilder.cs
deleted file mode 100644 (file)
index 91f5b83..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-  Copyright (C) 2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class CustomModifiersBuilder
-       {
-               private readonly List<Item> list = new List<Item>();
-
-               internal struct Item
-               {
-                       internal Type type;
-                       internal bool required;
-               }
-
-               public void AddRequired(Type type)
-               {
-                       Item item;
-                       item.type = type;
-                       item.required = true;
-                       list.Add(item);
-               }
-
-               public void AddOptional(Type type)
-               {
-                       Item item;
-                       item.type = type;
-                       item.required = false;
-                       list.Add(item);
-               }
-
-               // this adds the custom modifiers in the same order as the normal SRE APIs
-               // (the advantage over using the SRE APIs is that a CustomModifiers object is slightly more efficient,
-               // because unlike the Type arrays it doesn't need to be copied)
-               public void Add(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       foreach (CustomModifiers.Entry entry in CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers))
-                       {
-                               Item item;
-                               item.type = entry.Type;
-                               item.required = entry.IsRequired;
-                               list.Add(item);
-                       }
-               }
-
-               public CustomModifiers Create()
-               {
-                       return new CustomModifiers(list);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/EnumBuilder.cs b/mcs/class/IKVM.Reflection/Emit/EnumBuilder.cs
deleted file mode 100644 (file)
index eacacb0..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
-  Copyright (C) 2010 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class EnumBuilder : TypeInfo
-       {
-               private readonly TypeBuilder typeBuilder;
-               private readonly FieldBuilder fieldBuilder;
-
-               internal EnumBuilder(TypeBuilder typeBuilder, FieldBuilder fieldBuilder)
-                       : base(typeBuilder)
-               {
-                       this.typeBuilder = typeBuilder;
-                       this.fieldBuilder = fieldBuilder;
-               }
-
-               public override string __Name
-               {
-                       get { return typeBuilder.__Name; }
-               }
-
-               public override string __Namespace
-               {
-                       get { return typeBuilder.__Namespace; }
-               }
-
-               public override string Name
-               {
-                       get { return typeBuilder.Name; }
-               }
-
-               public override string FullName
-               {
-                       get { return typeBuilder.FullName; }
-               }
-
-               public override Type BaseType
-               {
-                       get { return typeBuilder.BaseType; }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return typeBuilder.Attributes; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeBuilder.Module; }
-               }
-
-               public FieldBuilder DefineLiteral(string literalName, object literalValue)
-               {
-                       FieldBuilder fb = typeBuilder.DefineField(literalName, typeBuilder, FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
-                       fb.SetConstant(literalValue);
-                       return fb;
-               }
-
-               public Type CreateType()
-               {
-                       return typeBuilder.CreateType();
-               }
-
-               public TypeInfo CreateTypeInfo()
-               {
-                       return typeBuilder.CreateTypeInfo();
-               }
-
-               public TypeToken TypeToken
-               {
-                       get { return typeBuilder.TypeToken; }
-               }
-
-               public FieldBuilder UnderlyingField
-               {
-                       get { return fieldBuilder; }
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       typeBuilder.SetCustomAttribute(con, binaryAttribute);
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       typeBuilder.SetCustomAttribute(customBuilder);
-               }
-
-               public override Type GetEnumUnderlyingType()
-               {
-                       return fieldBuilder.FieldType;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return typeBuilder.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/Enums.cs b/mcs/class/IKVM.Reflection/Emit/Enums.cs
deleted file mode 100644 (file)
index 7c85a55..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-
-namespace IKVM.Reflection.Emit
-{
-       public enum AssemblyBuilderAccess
-       {
-               Save = 2,
-               ReflectionOnly = 6,
-       }
-
-       public enum OpCodeType
-       {
-               Annotation = 0,
-               Macro = 1,
-               Nternal = 2,
-               Objmodel = 3,
-               Prefix = 4,
-               Primitive = 5,
-       }
-       
-       public enum OperandType
-       {
-               InlineBrTarget = 0,
-               InlineField = 1,
-               InlineI = 2,
-               InlineI8 = 3,
-               InlineMethod = 4,
-               InlineNone = 5,
-               InlinePhi = 6,
-               InlineR = 7,
-               InlineSig = 9,
-               InlineString = 10,
-               InlineSwitch = 11,
-               InlineTok = 12,
-               InlineType = 13,
-               InlineVar = 14,
-               ShortInlineBrTarget = 15,
-               ShortInlineI = 16,
-               ShortInlineR = 17,
-               ShortInlineVar = 18,
-       }
-
-       public enum FlowControl
-       {
-               Branch = 0,
-               Break = 1,
-               Call = 2,
-               Cond_Branch = 3,
-               Meta = 4,
-               Next = 5,
-               Return = 7,
-               Throw = 8,
-       }
-
-       public enum PackingSize
-       {
-               Unspecified = 0,
-               Size1 = 1,
-               Size2 = 2,
-               Size4 = 4,
-               Size8 = 8,
-               Size16 = 16,
-               Size32 = 32,
-               Size64 = 64,
-               Size128 = 128,
-       }
-
-       public enum PEFileKinds
-       {
-               Dll = 1,
-               ConsoleApplication = 2,
-               WindowApplication = 3,
-       }
-
-       public enum StackBehaviour
-       {
-               Pop0 = 0,
-               Pop1 = 1,
-               Pop1_pop1 = 2,
-               Popi = 3,
-               Popi_pop1 = 4,
-               Popi_popi = 5,
-               Popi_popi8 = 6,
-               Popi_popi_popi = 7,
-               Popi_popr4 = 8,
-               Popi_popr8 = 9,
-               Popref = 10,
-               Popref_pop1 = 11,
-               Popref_popi = 12,
-               Popref_popi_popi = 13,
-               Popref_popi_popi8 = 14,
-               Popref_popi_popr4 = 15,
-               Popref_popi_popr8 = 16,
-               Popref_popi_popref = 17,
-               Push0 = 18,
-               Push1 = 19,
-               Push1_push1 = 20,
-               Pushi = 21,
-               Pushi8 = 22,
-               Pushr4 = 23,
-               Pushr8 = 24,
-               Pushref = 25,
-               Varpop = 26,
-               Varpush = 27,
-               Popref_popi_pop1 = 28,
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/EventBuilder.cs b/mcs/class/IKVM.Reflection/Emit/EventBuilder.cs
deleted file mode 100644 (file)
index 0324272..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class EventBuilder : EventInfo
-       {
-               private readonly TypeBuilder typeBuilder;
-               private readonly string name;
-               private EventAttributes attributes;
-               private readonly int eventtype;
-               private MethodBuilder addOnMethod;
-               private MethodBuilder removeOnMethod;
-               private MethodBuilder fireMethod;
-               private readonly List<Accessor> accessors = new List<Accessor>();
-               private int lazyPseudoToken;
-
-               private struct Accessor
-               {
-                       internal short Semantics;
-                       internal MethodBuilder Method;
-               }
-
-               internal EventBuilder(TypeBuilder typeBuilder, string name, EventAttributes attributes, Type eventtype)
-               {
-                       this.typeBuilder = typeBuilder;
-                       this.name = name;
-                       this.attributes = attributes;
-                       this.eventtype = typeBuilder.ModuleBuilder.GetTypeTokenForMemberRef(eventtype);
-               }
-
-               public void SetAddOnMethod(MethodBuilder mdBuilder)
-               {
-                       addOnMethod = mdBuilder;
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.AddOn;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void SetRemoveOnMethod(MethodBuilder mdBuilder)
-               {
-                       removeOnMethod = mdBuilder;
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.RemoveOn;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void SetRaiseMethod(MethodBuilder mdBuilder)
-               {
-                       fireMethod = mdBuilder;
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.Fire;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void AddOtherMethod(MethodBuilder mdBuilder)
-               {
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.Other;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       Universe u = typeBuilder.ModuleBuilder.universe;
-                       if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
-                       {
-                               attributes |= EventAttributes.SpecialName;
-                       }
-                       else
-                       {
-                               if (lazyPseudoToken == 0)
-                               {
-                                       lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
-                               }
-                               typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
-                       }
-               }
-
-               public override EventAttributes Attributes
-               {
-                       get { return attributes; }
-               }
-
-               public override MethodInfo GetAddMethod(bool nonPublic)
-               {
-                       return nonPublic || (addOnMethod != null && addOnMethod.IsPublic) ? addOnMethod : null;
-               }
-
-               public override MethodInfo GetRemoveMethod(bool nonPublic)
-               {
-                       return nonPublic || (removeOnMethod != null && removeOnMethod.IsPublic) ? removeOnMethod : null;
-               }
-
-               public override MethodInfo GetRaiseMethod(bool nonPublic)
-               {
-                       return nonPublic || (fireMethod != null && fireMethod.IsPublic) ? fireMethod : null;
-               }
-
-               public override MethodInfo[] GetOtherMethods(bool nonPublic)
-               {
-                       List<MethodInfo> list = new List<MethodInfo>();
-                       foreach (Accessor acc in accessors)
-                       {
-                               if (acc.Semantics == MethodSemanticsTable.Other && (nonPublic || acc.Method.IsPublic))
-                               {
-                                       list.Add(acc.Method);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public override MethodInfo[] __GetMethods()
-               {
-                       List<MethodInfo> list = new List<MethodInfo>();
-                       foreach (Accessor acc in accessors)
-                       {
-                               list.Add(acc.Method);
-                       }
-                       return list.ToArray();
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeBuilder; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeBuilder.ModuleBuilder; }
-               }
-
-               public EventToken GetEventToken()
-               {
-                       if (lazyPseudoToken == 0)
-                       {
-                               lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
-                       }
-                       return new EventToken(lazyPseudoToken);
-               }
-
-               public override Type EventHandlerType
-               {
-                       get { return typeBuilder.ModuleBuilder.ResolveType(eventtype); }
-               }
-
-               internal void Bake()
-               {
-                       EventTable.Record rec = new EventTable.Record();
-                       rec.EventFlags = (short)attributes;
-                       rec.Name = typeBuilder.ModuleBuilder.Strings.Add(name);
-                       rec.EventType = eventtype;
-                       int token = 0x14000000 | typeBuilder.ModuleBuilder.Event.AddRecord(rec);
-
-                       if (lazyPseudoToken == 0)
-                       {
-                               lazyPseudoToken = token;
-                       }
-                       else
-                       {
-                               typeBuilder.ModuleBuilder.RegisterTokenFixup(lazyPseudoToken, token);
-                       }
-
-                       foreach (Accessor acc in accessors)
-                       {
-                               AddMethodSemantics(acc.Semantics, acc.Method.MetadataToken, token);
-                       }
-               }
-
-               private void AddMethodSemantics(short semantics, int methodToken, int propertyToken)
-               {
-                       MethodSemanticsTable.Record rec = new MethodSemanticsTable.Record();
-                       rec.Semantics = semantics;
-                       rec.Method = methodToken;
-                       rec.Association = propertyToken;
-                       typeBuilder.ModuleBuilder.MethodSemantics.AddRecord(rec);
-               }
-
-               internal override bool IsPublic
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if (acc.Method.IsPublic)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if ((acc.Method.Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsStatic
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if (acc.Method.IsStatic)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return typeBuilder.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       if (typeBuilder.ModuleBuilder.IsSaved && ModuleBuilder.IsPseudoToken(lazyPseudoToken))
-                       {
-                               return typeBuilder.ModuleBuilder.ResolvePseudoToken(lazyPseudoToken);
-                       }
-                       else
-                       {
-                               return lazyPseudoToken;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/ExceptionHandler.cs b/mcs/class/IKVM.Reflection/Emit/ExceptionHandler.cs
deleted file mode 100644 (file)
index 40837a9..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
-  Copyright (C) 2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-
-namespace IKVM.Reflection.Emit
-{
-       public struct ExceptionHandler : IEquatable<ExceptionHandler>
-       {
-               private readonly int tryOffset;
-               private readonly int tryLength;
-               private readonly int filterOffset;
-               private readonly int handlerOffset;
-               private readonly int handlerLength;
-               private readonly ExceptionHandlingClauseOptions kind;
-               private readonly int exceptionTypeToken;
-
-               public ExceptionHandler(int tryOffset, int tryLength, int filterOffset, int handlerOffset, int handlerLength, ExceptionHandlingClauseOptions kind, int exceptionTypeToken)
-               {
-                       if (tryOffset < 0 || tryLength < 0 || filterOffset < 0 || handlerOffset < 0 || handlerLength < 0)
-                       {
-                               throw new ArgumentOutOfRangeException();
-                       }
-                       this.tryOffset = tryOffset;
-                       this.tryLength = tryLength;
-                       this.filterOffset = filterOffset;
-                       this.handlerOffset = handlerOffset;
-                       this.handlerLength = handlerLength;
-                       this.kind = kind;
-                       this.exceptionTypeToken = exceptionTypeToken;
-               }
-
-               public int TryOffset
-               {
-                       get { return tryOffset; }
-               }
-
-               public int TryLength
-               {
-                       get { return tryLength; }
-               }
-
-               public int FilterOffset
-               {
-                       get { return filterOffset; }
-               }
-
-               public int HandlerOffset
-               {
-                       get { return handlerOffset; }
-               }
-
-               public int HandlerLength
-               {
-                       get { return handlerLength; }
-               }
-
-               public ExceptionHandlingClauseOptions Kind
-               {
-                       get { return kind; }
-               }
-
-               public int ExceptionTypeToken
-               {
-                       get { return exceptionTypeToken; }
-               }
-
-               public bool Equals(ExceptionHandler other)
-               {
-                       return tryOffset == other.tryOffset
-                               && tryLength == other.tryLength
-                               && filterOffset == other.filterOffset
-                               && handlerOffset == other.handlerOffset
-                               && handlerLength == other.handlerLength
-                               && kind == other.kind
-                               && exceptionTypeToken == other.exceptionTypeToken;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       ExceptionHandler? other = obj as ExceptionHandler?;
-                       return other != null && Equals(other);
-               }
-
-               public override int GetHashCode()
-               {
-                       return tryOffset ^ tryLength * 33 ^ filterOffset * 333 ^ handlerOffset * 3333 ^ handlerLength * 33333;
-               }
-
-               public static bool operator ==(ExceptionHandler left, ExceptionHandler right)
-               {
-                       return left.Equals(right);
-               }
-
-               public static bool operator !=(ExceptionHandler left, ExceptionHandler right)
-               {
-                       return !left.Equals(right);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/FieldBuilder.cs b/mcs/class/IKVM.Reflection/Emit/FieldBuilder.cs
deleted file mode 100644 (file)
index cbee210..0000000
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class FieldBuilder : FieldInfo
-       {
-               private readonly TypeBuilder typeBuilder;
-               private readonly string name;
-               private readonly int pseudoToken;
-               private FieldAttributes attribs;
-               private readonly int nameIndex;
-               private readonly int signature;
-               private readonly FieldSignature fieldSig;
-
-               internal FieldBuilder(TypeBuilder type, string name, Type fieldType, CustomModifiers customModifiers, FieldAttributes attribs)
-               {
-                       this.typeBuilder = type;
-                       this.name = name;
-                       this.pseudoToken = type.ModuleBuilder.AllocPseudoToken();
-                       this.nameIndex = type.ModuleBuilder.Strings.Add(name);
-                       this.fieldSig = FieldSignature.Create(fieldType, customModifiers);
-                       ByteBuffer sig = new ByteBuffer(5);
-                       fieldSig.WriteSig(this.typeBuilder.ModuleBuilder, sig);
-                       this.signature = this.typeBuilder.ModuleBuilder.Blobs.Add(sig);
-                       this.attribs = attribs;
-                       this.typeBuilder.ModuleBuilder.Field.AddVirtualRecord();
-               }
-
-               public void SetConstant(object defaultValue)
-               {
-                       attribs |= FieldAttributes.HasDefault;
-                       typeBuilder.ModuleBuilder.AddConstant(pseudoToken, defaultValue);
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       if (!typeBuilder.IsCreated())
-                       {
-                               // the .NET FieldBuilder doesn't support this method
-                               // (since we dont' have a different FieldInfo object after baking, we will support it once we're baked)
-                               throw new NotSupportedException();
-                       }
-                       return typeBuilder.Module.Constant.GetRawConstantValue(typeBuilder.Module, GetCurrentToken());
-               }
-
-               public void __SetDataAndRVA(byte[] data)
-               {
-                       SetDataAndRvaImpl(data, typeBuilder.ModuleBuilder.initializedData, 0);
-               }
-
-               public void __SetReadOnlyDataAndRVA(byte[] data)
-               {
-                       SetDataAndRvaImpl(data, typeBuilder.ModuleBuilder.methodBodies, unchecked((int)0x80000000));
-               }
-
-               private void SetDataAndRvaImpl(byte[] data, ByteBuffer bb, int readonlyMarker)
-               {
-                       attribs |= FieldAttributes.HasFieldRVA;
-                       FieldRVATable.Record rec = new FieldRVATable.Record();
-                       bb.Align(8);
-                       rec.RVA = bb.Position + readonlyMarker;
-                       rec.Field = pseudoToken;
-                       typeBuilder.ModuleBuilder.FieldRVA.AddRecord(rec);
-                       bb.Write(data);
-               }
-
-               public override void __GetDataFromRVA(byte[] data, int offset, int length)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override int __FieldRVA
-               {
-                       get { throw new NotImplementedException(); }
-               }
-
-               public override bool __TryGetFieldOffset(out int offset)
-               {
-                       int pseudoTokenOrIndex = pseudoToken;
-                       if (typeBuilder.ModuleBuilder.IsSaved)
-                       {
-                               pseudoTokenOrIndex = typeBuilder.ModuleBuilder.ResolvePseudoToken(pseudoToken) & 0xFFFFFF;
-                       }
-                       foreach (int i in this.Module.FieldLayout.Filter(pseudoTokenOrIndex))
-                       {
-                               offset = this.Module.FieldLayout.records[i].Offset;
-                               return true;
-                       }
-                       offset = 0;
-                       return false;
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       Universe u = this.Module.universe;
-                       if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_FieldOffsetAttribute)
-                       {
-                               customBuilder = customBuilder.DecodeBlob(this.Module.Assembly);
-                               SetOffset((int)customBuilder.GetConstructorArgument(0));
-                       }
-                       else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute)
-                       {
-                               FieldMarshal.SetMarshalAsAttribute(typeBuilder.ModuleBuilder, pseudoToken, customBuilder);
-                               attribs |= FieldAttributes.HasFieldMarshal;
-                       }
-                       else if (customBuilder.Constructor.DeclaringType == u.System_NonSerializedAttribute)
-                       {
-                               attribs |= FieldAttributes.NotSerialized;
-                       }
-                       else if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
-                       {
-                               attribs |= FieldAttributes.SpecialName;
-                       }
-                       else
-                       {
-                               typeBuilder.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
-                       }
-               }
-
-               public void SetOffset(int iOffset)
-               {
-                       FieldLayoutTable.Record rec = new FieldLayoutTable.Record();
-                       rec.Offset = iOffset;
-                       rec.Field = pseudoToken;
-                       typeBuilder.ModuleBuilder.FieldLayout.AddRecord(rec);
-               }
-
-               public override FieldAttributes Attributes
-               {
-                       get { return attribs; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeBuilder.IsModulePseudoType ? null : typeBuilder; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return pseudoToken; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeBuilder.Module; }
-               }
-
-               public FieldToken GetToken()
-               {
-                       return new FieldToken(pseudoToken);
-               }
-
-               internal void WriteFieldRecords(MetadataWriter mw)
-               {
-                       mw.Write((short)attribs);
-                       mw.WriteStringIndex(nameIndex);
-                       mw.WriteBlobIndex(signature);
-               }
-
-               internal void FixupToken(int token)
-               {
-                       typeBuilder.ModuleBuilder.RegisterTokenFixup(this.pseudoToken, token);
-               }
-
-               internal override FieldSignature FieldSignature
-               {
-                       get { return fieldSig; }
-               }
-
-               internal override int ImportTo(ModuleBuilder other)
-               {
-                       return other.ImportMethodOrField(typeBuilder, name, fieldSig);
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       if (typeBuilder.ModuleBuilder.IsSaved)
-                       {
-                               return typeBuilder.ModuleBuilder.ResolvePseudoToken(pseudoToken);
-                       }
-                       else
-                       {
-                               return pseudoToken;
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return typeBuilder.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/ILGenerator.cs b/mcs/class/IKVM.Reflection/Emit/ILGenerator.cs
deleted file mode 100644 (file)
index b7be3f3..0000000
+++ /dev/null
@@ -1,1135 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.InteropServices;
-using System.Collections.Generic;
-using System.Diagnostics.SymbolStore;
-using System.Diagnostics;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public struct Label
-       {
-               // 1-based here, to make sure that an uninitialized Label isn't valid
-               private readonly int index1;
-
-               internal Label(int index)
-               {
-                       this.index1 = index + 1;
-               }
-
-               internal int Index
-               {
-                       get { return index1 - 1; }
-               }
-
-               public bool Equals(Label other)
-               {
-                       return other.index1 == index1;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return this == obj as Label?;
-               }
-
-               public override int GetHashCode()
-               {
-                       return index1;
-               }
-
-               public static bool operator ==(Label arg1, Label arg2)
-               {
-                       return arg1.index1 == arg2.index1;
-               }
-
-               public static bool operator !=(Label arg1, Label arg2)
-               {
-                       return !(arg1 == arg2);
-               }
-       }
-
-       public sealed class LocalBuilder : LocalVariableInfo
-       {
-               internal string name;
-               internal int startOffset;
-               internal int endOffset;
-
-               internal LocalBuilder(Type localType, int index, bool pinned)
-                       : base(index, localType, pinned)
-               {
-               }
-
-               internal LocalBuilder(Type localType, int index, bool pinned, CustomModifiers customModifiers)
-                       : base(index, localType, pinned, customModifiers)
-               {
-               }
-
-               public void SetLocalSymInfo(string name)
-               {
-                       this.name = name;
-               }
-
-               public void SetLocalSymInfo(string name, int startOffset, int endOffset)
-               {
-                       this.name = name;
-                       this.startOffset = startOffset;
-                       this.endOffset = endOffset;
-               }
-       }
-
-       public sealed class ILGenerator
-       {
-               private readonly ModuleBuilder moduleBuilder;
-               private readonly ByteBuffer code;
-               private readonly SignatureHelper locals;
-               private int localsCount;
-               private readonly List<int> tokenFixups = new List<int>();
-               private readonly List<int> labels = new List<int>();
-               private readonly List<int> labelStackHeight = new List<int>();
-               private readonly List<LabelFixup> labelFixups = new List<LabelFixup>();
-               private readonly List<SequencePoint> sequencePoints = new List<SequencePoint>();
-               private readonly List<ExceptionBlock> exceptions = new List<ExceptionBlock>();
-               private readonly Stack<ExceptionBlock> exceptionStack = new Stack<ExceptionBlock>();
-               private ushort maxStack;
-               private bool fatHeader;
-               private int stackHeight;
-               private Scope scope;
-               private byte exceptionBlockAssistanceMode = EBAM_COMPAT;
-               private const byte EBAM_COMPAT = 0;
-               private const byte EBAM_DISABLE = 1;
-               private const byte EBAM_CLEVER = 2;
-
-               private struct LabelFixup
-               {
-                       internal int label;
-                       internal int offset;
-               }
-
-               internal sealed class ExceptionBlock : IComparer<ExceptionBlock>
-               {
-                       internal readonly int ordinal;
-                       internal Label labelEnd;
-                       internal int tryOffset;
-                       internal int tryLength;
-                       internal int handlerOffset;
-                       internal int handlerLength;
-                       internal int filterOffsetOrExceptionTypeToken;
-                       internal ExceptionHandlingClauseOptions kind;
-
-                       internal ExceptionBlock(int ordinal)
-                       {
-                               this.ordinal = ordinal;
-                       }
-
-                       internal ExceptionBlock(ExceptionHandler h)
-                       {
-                               this.ordinal = -1;
-                               this.tryOffset = h.TryOffset;
-                               this.tryLength = h.TryLength;
-                               this.handlerOffset = h.HandlerOffset;
-                               this.handlerLength = h.HandlerLength;
-                               this.kind = h.Kind;
-                               this.filterOffsetOrExceptionTypeToken = kind == ExceptionHandlingClauseOptions.Filter ? h.FilterOffset : h.ExceptionTypeToken;
-                       }
-
-                       int IComparer<ExceptionBlock>.Compare(ExceptionBlock x, ExceptionBlock y)
-                       {
-                               // Mono's sort insists on doing unnecessary comparisons
-                               if (x == y)
-                               {
-                                       return 0;
-                               }
-                               else if (x.tryOffset == y.tryOffset && x.tryLength == y.tryLength)
-                               {
-                                       return x.ordinal < y.ordinal ? -1 : 1;
-                               }
-                               else if (x.tryOffset >= y.tryOffset && x.handlerOffset + x.handlerLength <= y.handlerOffset + y.handlerLength)
-                               {
-                                       return -1;
-                               }
-                               else if (y.tryOffset >= x.tryOffset && y.handlerOffset + y.handlerLength <= x.handlerOffset + x.handlerLength)
-                               {
-                                       return 1;
-                               }
-                               else
-                               {
-                                       return x.ordinal < y.ordinal ? -1 : 1;
-                               }
-                       }
-               }
-
-               private struct SequencePoint
-               {
-                       internal ISymbolDocumentWriter document;
-                       internal int offset;
-                       internal int startLine;
-                       internal int startColumn;
-                       internal int endLine;
-                       internal int endColumn;
-               }
-
-               private sealed class Scope
-               {
-                       internal readonly Scope parent;
-                       internal readonly List<Scope> children = new List<Scope>();
-                       internal readonly List<LocalBuilder> locals = new List<LocalBuilder>();
-                       internal int startOffset;
-                       internal int endOffset;
-
-                       internal Scope(Scope parent)
-                       {
-                               this.parent = parent;
-                       }
-               }
-
-               internal ILGenerator(ModuleBuilder moduleBuilder, int initialCapacity)
-               {
-                       this.code = new ByteBuffer(initialCapacity);
-                       this.moduleBuilder = moduleBuilder;
-                       this.locals = SignatureHelper.GetLocalVarSigHelper(moduleBuilder);
-                       if (moduleBuilder.symbolWriter != null)
-                       {
-                               scope = new Scope(null);
-                       }
-               }
-
-               // non-standard API
-               public void __DisableExceptionBlockAssistance()
-               {
-                       exceptionBlockAssistanceMode = EBAM_DISABLE;
-               }
-
-               // non-standard API
-               public void __CleverExceptionBlockAssistance()
-               {
-                       exceptionBlockAssistanceMode = EBAM_CLEVER;
-               }
-
-               // non-standard API
-               public int __MaxStackSize
-               {
-                       get { return maxStack; }
-                       set
-                       {
-                               maxStack = (ushort)value;
-                               fatHeader = true;
-                       }
-               }
-
-               // non-standard API
-               // returns -1 if the current position is currently unreachable
-               public int __StackHeight
-               {
-                       get { return stackHeight; }
-               }
-
-               // new in .NET 4.0
-               public int ILOffset
-               {
-                       get { return code.Position; }
-               }
-
-               public void BeginCatchBlock(Type exceptionType)
-               {
-                       if (exceptionType == null)
-                       {
-                               // this must be a catch block after a filter
-                               ExceptionBlock block = exceptionStack.Peek();
-                               if (block.kind != ExceptionHandlingClauseOptions.Filter || block.handlerOffset != 0)
-                               {
-                                       throw new ArgumentNullException("exceptionType");
-                               }
-                               if (exceptionBlockAssistanceMode == EBAM_COMPAT || (exceptionBlockAssistanceMode == EBAM_CLEVER && stackHeight != -1))
-                               {
-                                       Emit(OpCodes.Endfilter);
-                               }
-                               stackHeight = 0;
-                               UpdateStack(1);
-                               block.handlerOffset = code.Position;
-                       }
-                       else
-                       {
-                               ExceptionBlock block = BeginCatchOrFilterBlock();
-                               block.kind = ExceptionHandlingClauseOptions.Clause;
-                               block.filterOffsetOrExceptionTypeToken = moduleBuilder.GetTypeTokenForMemberRef(exceptionType);
-                               block.handlerOffset = code.Position;
-                       }
-               }
-
-               private ExceptionBlock BeginCatchOrFilterBlock()
-               {
-                       ExceptionBlock block = exceptionStack.Peek();
-                       if (exceptionBlockAssistanceMode == EBAM_COMPAT || (exceptionBlockAssistanceMode == EBAM_CLEVER && stackHeight != -1))
-                       {
-                               Emit(OpCodes.Leave, block.labelEnd);
-                       }
-                       stackHeight = 0;
-                       UpdateStack(1);
-                       if (block.tryLength == 0)
-                       {
-                               block.tryLength = code.Position - block.tryOffset;
-                       }
-                       else
-                       {
-                               block.handlerLength = code.Position - block.handlerOffset;
-                               exceptionStack.Pop();
-                               ExceptionBlock newBlock = new ExceptionBlock(exceptions.Count);
-                               newBlock.labelEnd = block.labelEnd;
-                               newBlock.tryOffset = block.tryOffset;
-                               newBlock.tryLength = block.tryLength;
-                               block = newBlock;
-                               exceptions.Add(block);
-                               exceptionStack.Push(block);
-                       }
-                       return block;
-               }
-
-               public Label BeginExceptionBlock()
-               {
-                       ExceptionBlock block = new ExceptionBlock(exceptions.Count);
-                       block.labelEnd = DefineLabel();
-                       block.tryOffset = code.Position;
-                       exceptionStack.Push(block);
-                       exceptions.Add(block);
-                       stackHeight = 0;
-                       return block.labelEnd;
-               }
-
-               public void BeginExceptFilterBlock()
-               {
-                       ExceptionBlock block = BeginCatchOrFilterBlock();
-                       block.kind = ExceptionHandlingClauseOptions.Filter;
-                       block.filterOffsetOrExceptionTypeToken = code.Position;
-               }
-
-               public void BeginFaultBlock()
-               {
-                       BeginFinallyFaultBlock(ExceptionHandlingClauseOptions.Fault);
-               }
-
-               public void BeginFinallyBlock()
-               {
-                       BeginFinallyFaultBlock(ExceptionHandlingClauseOptions.Finally);
-               }
-
-               private void BeginFinallyFaultBlock(ExceptionHandlingClauseOptions kind)
-               {
-                       ExceptionBlock block = exceptionStack.Peek();
-                       if (exceptionBlockAssistanceMode == EBAM_COMPAT || (exceptionBlockAssistanceMode == EBAM_CLEVER && stackHeight != -1))
-                       {
-                               Emit(OpCodes.Leave, block.labelEnd);
-                       }
-                       if (block.handlerOffset == 0)
-                       {
-                               block.tryLength = code.Position - block.tryOffset;
-                       }
-                       else
-                       {
-                               block.handlerLength = code.Position - block.handlerOffset;
-                               Label labelEnd;
-                               if (exceptionBlockAssistanceMode != EBAM_COMPAT)
-                               {
-                                       labelEnd = block.labelEnd;
-                               }
-                               else
-                               {
-                                       MarkLabel(block.labelEnd);
-                                       labelEnd = DefineLabel();
-                                       Emit(OpCodes.Leave, labelEnd);
-                               }
-                               exceptionStack.Pop();
-                               ExceptionBlock newBlock = new ExceptionBlock(exceptions.Count);
-                               newBlock.labelEnd = labelEnd;
-                               newBlock.tryOffset = block.tryOffset;
-                               newBlock.tryLength = code.Position - block.tryOffset;
-                               block = newBlock;
-                               exceptions.Add(block);
-                               exceptionStack.Push(block);
-                       }
-                       block.handlerOffset = code.Position;
-                       block.kind = kind;
-                       stackHeight = 0;
-               }
-
-               public void EndExceptionBlock()
-               {
-                       ExceptionBlock block = exceptionStack.Pop();
-                       if (exceptionBlockAssistanceMode == EBAM_COMPAT || (exceptionBlockAssistanceMode == EBAM_CLEVER && stackHeight != -1))
-                       {
-                               if (block.kind != ExceptionHandlingClauseOptions.Finally && block.kind != ExceptionHandlingClauseOptions.Fault)
-                               {
-                                       Emit(OpCodes.Leave, block.labelEnd);
-                               }
-                               else
-                               {
-                                       Emit(OpCodes.Endfinally);
-                               }
-                       }
-                       MarkLabel(block.labelEnd);
-                       block.handlerLength = code.Position - block.handlerOffset;
-               }
-
-               public void BeginScope()
-               {
-                       Scope newScope = new Scope(scope);
-                       scope.children.Add(newScope);
-                       scope = newScope;
-                       scope.startOffset = code.Position;
-               }
-
-               public void UsingNamespace(string usingNamespace)
-               {
-                       if (moduleBuilder.symbolWriter != null)
-                       {
-                               moduleBuilder.symbolWriter.UsingNamespace(usingNamespace);
-                       }
-               }
-
-               public LocalBuilder DeclareLocal(Type localType)
-               {
-                       return DeclareLocal(localType, false);
-               }
-
-               public LocalBuilder DeclareLocal(Type localType, bool pinned)
-               {
-                       LocalBuilder local = new LocalBuilder(localType, localsCount++, pinned);
-                       locals.AddArgument(localType, pinned);
-                       if (scope != null)
-                       {
-                               scope.locals.Add(local);
-                       }
-                       return local;
-               }
-
-               public LocalBuilder __DeclareLocal(Type localType, bool pinned, CustomModifiers customModifiers)
-               {
-                       LocalBuilder local = new LocalBuilder(localType, localsCount++, pinned, customModifiers);
-                       locals.__AddArgument(localType, pinned, customModifiers);
-                       if (scope != null)
-                       {
-                               scope.locals.Add(local);
-                       }
-                       return local;
-               }
-
-               public Label DefineLabel()
-               {
-                       Label label = new Label(labels.Count);
-                       labels.Add(-1);
-                       labelStackHeight.Add(-1);
-                       return label;
-               }
-
-               public void Emit(OpCode opc)
-               {
-                       Debug.Assert(opc != OpCodes.Ret || (opc == OpCodes.Ret && stackHeight <= 1));
-                       if (opc.Value < 0)
-                       {
-                               code.Write((byte)(opc.Value >> 8));
-                       }
-                       code.Write((byte)opc.Value);
-                       switch (opc.FlowControl)
-                       {
-                               case FlowControl.Branch:
-                               case FlowControl.Break:
-                               case FlowControl.Return:
-                               case FlowControl.Throw:
-                                       stackHeight = -1;
-                                       break;
-                               default:
-                                       UpdateStack(opc.StackDiff);
-                                       break;
-                       }
-               }
-
-               private void UpdateStack(int stackdiff)
-               {
-                       if (stackHeight == -1)
-                       {
-                               // we're about to emit code that is either unreachable or reachable only via a backward branch
-                               stackHeight = 0;
-                       }
-                       Debug.Assert(stackHeight >= 0 && stackHeight <= ushort.MaxValue);
-                       stackHeight += stackdiff;
-                       Debug.Assert(stackHeight >= 0 && stackHeight <= ushort.MaxValue);
-                       maxStack = Math.Max(maxStack, (ushort)stackHeight);
-               }
-
-               public void Emit(OpCode opc, byte arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, double arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, FieldInfo field)
-               {
-                       Emit(opc);
-                       WriteToken(moduleBuilder.GetFieldToken(field).Token);
-               }
-
-               public void Emit(OpCode opc, short arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, int arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, long arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, Label label)
-               {
-                       // We need special stackHeight handling for unconditional branches,
-                       // because the branch and next flows have differing stack heights.
-                       // Note that this assumes that unconditional branches do not push/pop.
-                       int flowStackHeight = this.stackHeight;
-                       Emit(opc);
-                       if (opc == OpCodes.Leave || opc == OpCodes.Leave_S)
-                       {
-                               flowStackHeight = 0;
-                       }
-                       else if (opc.FlowControl != FlowControl.Branch)
-                       {
-                               flowStackHeight = this.stackHeight;
-                       }
-                       // if the label has already been marked, we can emit the branch offset directly
-                       if (labels[label.Index] != -1)
-                       {
-                               if (labelStackHeight[label.Index] != flowStackHeight && (labelStackHeight[label.Index] != 0 || flowStackHeight != -1))
-                               {
-                                       // the "backward branch constraint" prohibits this, so we don't need to support it
-                                       throw new NotSupportedException("'Backward branch constraints' violated");
-                               }
-                               if (opc.OperandType == OperandType.ShortInlineBrTarget)
-                               {
-                                       WriteByteBranchOffset(labels[label.Index] - (code.Position + 1));
-                               }
-                               else
-                               {
-                                       code.Write(labels[label.Index] - (code.Position + 4));
-                               }
-                       }
-                       else
-                       {
-                               Debug.Assert(labelStackHeight[label.Index] == -1 || labelStackHeight[label.Index] == flowStackHeight || (flowStackHeight == -1 && labelStackHeight[label.Index] == 0));
-                               labelStackHeight[label.Index] = flowStackHeight;
-                               LabelFixup fix = new LabelFixup();
-                               fix.label = label.Index;
-                               fix.offset = code.Position;
-                               labelFixups.Add(fix);
-                               if (opc.OperandType == OperandType.ShortInlineBrTarget)
-                               {
-                                       code.Write((byte)1);
-                               }
-                               else
-                               {
-                                       code.Write(4);
-                               }
-                       }
-               }
-
-               private void WriteByteBranchOffset(int offset)
-               {
-                       if (offset < -128 || offset > 127)
-                       {
-                               throw new NotSupportedException("Branch offset of " + offset + " does not fit in one-byte branch target at position " + code.Position);
-                       }
-                       code.Write((byte)offset);
-               }
-
-               public void Emit(OpCode opc, Label[] labels)
-               {
-                       Emit(opc);
-                       LabelFixup fix = new LabelFixup();
-                       fix.label = -1;
-                       fix.offset = code.Position;
-                       labelFixups.Add(fix);
-                       code.Write(labels.Length);
-                       foreach (Label label in labels)
-                       {
-                               code.Write(label.Index);
-                               if (this.labels[label.Index] != -1)
-                               {
-                                       if (labelStackHeight[label.Index] != stackHeight)
-                                       {
-                                               // the "backward branch constraint" prohibits this, so we don't need to support it
-                                               throw new NotSupportedException();
-                                       }
-                               }
-                               else
-                               {
-                                       Debug.Assert(labelStackHeight[label.Index] == -1 || labelStackHeight[label.Index] == stackHeight);
-                                       labelStackHeight[label.Index] = stackHeight;
-                               }
-                       }
-               }
-
-               public void Emit(OpCode opc, LocalBuilder local)
-               {
-                       if ((opc == OpCodes.Ldloc || opc == OpCodes.Ldloca || opc == OpCodes.Stloc) && local.LocalIndex < 256)
-                       {
-                               if (opc == OpCodes.Ldloc)
-                               {
-                                       switch (local.LocalIndex)
-                                       {
-                                               case 0:
-                                                       Emit(OpCodes.Ldloc_0);
-                                                       break;
-                                               case 1:
-                                                       Emit(OpCodes.Ldloc_1);
-                                                       break;
-                                               case 2:
-                                                       Emit(OpCodes.Ldloc_2);
-                                                       break;
-                                               case 3:
-                                                       Emit(OpCodes.Ldloc_3);
-                                                       break;
-                                               default:
-                                                       Emit(OpCodes.Ldloc_S);
-                                                       code.Write((byte)local.LocalIndex);
-                                                       break;
-                                       }
-                               }
-                               else if (opc == OpCodes.Ldloca)
-                               {
-                                       Emit(OpCodes.Ldloca_S);
-                                       code.Write((byte)local.LocalIndex);
-                               }
-                               else if (opc == OpCodes.Stloc)
-                               {
-                                       switch (local.LocalIndex)
-                                       {
-                                               case 0:
-                                                       Emit(OpCodes.Stloc_0);
-                                                       break;
-                                               case 1:
-                                                       Emit(OpCodes.Stloc_1);
-                                                       break;
-                                               case 2:
-                                                       Emit(OpCodes.Stloc_2);
-                                                       break;
-                                               case 3:
-                                                       Emit(OpCodes.Stloc_3);
-                                                       break;
-                                               default:
-                                                       Emit(OpCodes.Stloc_S);
-                                                       code.Write((byte)local.LocalIndex);
-                                                       break;
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               Emit(opc);
-                               switch (opc.OperandType)
-                               {
-                                       case OperandType.InlineVar:
-                                               code.Write((ushort)local.LocalIndex);
-                                               break;
-                                       case OperandType.ShortInlineVar:
-                                               code.Write((byte)local.LocalIndex);
-                                               break;
-                               }
-                       }
-               }
-
-               private void WriteToken(int token)
-               {
-                       if (ModuleBuilder.IsPseudoToken(token))
-                       {
-                               tokenFixups.Add(code.Position);
-                       }
-                       code.Write(token);
-               }
-
-               private void UpdateStack(OpCode opc, bool hasthis, Type returnType, int parameterCount)
-               {
-                       if (opc == OpCodes.Jmp)
-                       {
-                               stackHeight = -1;
-                       }
-                       else if (opc.FlowControl == FlowControl.Call)
-                       {
-                               int stackdiff = 0;
-                               if ((hasthis && opc != OpCodes.Newobj) || opc == OpCodes.Calli)
-                               {
-                                       // pop this
-                                       stackdiff--;
-                               }
-                               // pop parameters
-                               stackdiff -= parameterCount;
-                               if (returnType != moduleBuilder.universe.System_Void)
-                               {
-                                       // push return value
-                                       stackdiff++;
-                               }
-                               UpdateStack(stackdiff);
-                       }
-               }
-
-               public void Emit(OpCode opc, MethodInfo method)
-               {
-                       UpdateStack(opc, method.HasThis, method.ReturnType, method.ParameterCount);
-                       Emit(opc);
-                       WriteToken(moduleBuilder.GetMethodTokenForIL(method).Token);
-               }
-
-               public void Emit(OpCode opc, ConstructorInfo constructor)
-               {
-                       Emit(opc, constructor.GetMethodInfo());
-               }
-
-               public void Emit(OpCode opc, sbyte arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, float arg)
-               {
-                       Emit(opc);
-                       code.Write(arg);
-               }
-
-               public void Emit(OpCode opc, string str)
-               {
-                       Emit(opc);
-                       code.Write(moduleBuilder.GetStringConstant(str).Token);
-               }
-
-               public void Emit(OpCode opc, Type type)
-               {
-                       Emit(opc);
-                       if (opc == OpCodes.Ldtoken)
-                       {
-                               code.Write(moduleBuilder.GetTypeToken(type).Token);
-                       }
-                       else
-                       {
-                               code.Write(moduleBuilder.GetTypeTokenForMemberRef(type));
-                       }
-               }
-
-               public void Emit(OpCode opcode, SignatureHelper signature)
-               {
-                       Emit(opcode);
-                       UpdateStack(opcode, signature.HasThis, signature.ReturnType, signature.ParameterCount);
-                       code.Write(moduleBuilder.GetSignatureToken(signature).Token);
-               }
-
-               public void EmitCall(OpCode opc, MethodInfo method, Type[] optionalParameterTypes)
-               {
-                       __EmitCall(opc, method, optionalParameterTypes, null);
-               }
-
-               public void __EmitCall(OpCode opc, MethodInfo method, Type[] optionalParameterTypes, CustomModifiers[] customModifiers)
-               {
-                       if (optionalParameterTypes == null || optionalParameterTypes.Length == 0)
-                       {
-                               Emit(opc, method);
-                       }
-                       else
-                       {
-                               Emit(opc);
-                               UpdateStack(opc, method.HasThis, method.ReturnType, method.ParameterCount + optionalParameterTypes.Length);
-                               code.Write(moduleBuilder.__GetMethodToken(method, optionalParameterTypes, customModifiers).Token);
-                       }
-               }
-
-               public void __EmitCall(OpCode opc, ConstructorInfo constructor, Type[] optionalParameterTypes)
-               {
-                       EmitCall(opc, constructor.GetMethodInfo(), optionalParameterTypes);
-               }
-
-               public void __EmitCall(OpCode opc, ConstructorInfo constructor, Type[] optionalParameterTypes, CustomModifiers[] customModifiers)
-               {
-                       __EmitCall(opc, constructor.GetMethodInfo(), optionalParameterTypes, customModifiers);
-               }
-
-               public void EmitCalli(OpCode opc, CallingConvention callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       SignatureHelper sig = SignatureHelper.GetMethodSigHelper(moduleBuilder, callingConvention, returnType);
-                       sig.AddArguments(parameterTypes, null, null);
-                       Emit(opc, sig);
-               }
-
-               public void EmitCalli(OpCode opc, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes)
-               {
-                       SignatureHelper sig = SignatureHelper.GetMethodSigHelper(moduleBuilder, callingConvention, returnType);
-                       sig.AddArguments(parameterTypes, null, null);
-                       sig.AddSentinel();
-                       sig.AddArguments(optionalParameterTypes, null, null);
-                       Emit(opc, sig);
-               }
-
-               public void __EmitCalli(OpCode opc, __StandAloneMethodSig sig)
-               {
-                       Emit(opc);
-                       if (sig.IsUnmanaged)
-                       {
-                               UpdateStack(opc, false, sig.ReturnType, sig.ParameterCount);
-                       }
-                       else
-                       {
-                               CallingConventions callingConvention = sig.CallingConvention;
-                               UpdateStack(opc, (callingConvention & CallingConventions.HasThis | CallingConventions.ExplicitThis) == CallingConventions.HasThis, sig.ReturnType, sig.ParameterCount);
-                       }
-                       ByteBuffer bb = new ByteBuffer(16);
-                       Signature.WriteStandAloneMethodSig(moduleBuilder, bb, sig);
-                       code.Write(0x11000000 | moduleBuilder.StandAloneSig.FindOrAddRecord(moduleBuilder.Blobs.Add(bb)));
-               }
-
-               public void EmitWriteLine(string text)
-               {
-                       Universe u = moduleBuilder.universe;
-                       Emit(OpCodes.Ldstr, text);
-                       Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("WriteLine", new Type[] { u.System_String }));
-               }
-
-               public void EmitWriteLine(FieldInfo field)
-               {
-                       Universe u = moduleBuilder.universe;
-                       Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("get_Out"));
-                       if (field.IsStatic)
-                       {
-                               Emit(OpCodes.Ldsfld, field);
-                       }
-                       else
-                       {
-                               Emit(OpCodes.Ldarg_0);
-                               Emit(OpCodes.Ldfld, field);
-                       }
-                       Emit(OpCodes.Callvirt, u.Import(typeof(System.IO.TextWriter)).GetMethod("WriteLine", new Type[] { field.FieldType }));
-               }
-
-               public void EmitWriteLine(LocalBuilder local)
-               {
-                       Universe u = moduleBuilder.universe;
-                       Emit(OpCodes.Call, u.Import(typeof(Console)).GetMethod("get_Out"));
-                       Emit(OpCodes.Ldloc, local);
-                       Emit(OpCodes.Callvirt, u.Import(typeof(System.IO.TextWriter)).GetMethod("WriteLine", new Type[] { local.LocalType }));
-               }
-
-               public void EndScope()
-               {
-                       scope.endOffset = code.Position;
-                       scope = scope.parent;
-               }
-
-               public void MarkLabel(Label loc)
-               {
-                       Debug.Assert(stackHeight == -1 || labelStackHeight[loc.Index] == -1 || stackHeight == labelStackHeight[loc.Index]);
-                       labels[loc.Index] = code.Position;
-                       if (labelStackHeight[loc.Index] == -1)
-                       {
-                               if (stackHeight == -1)
-                               {
-                                       // We're at a location that can only be reached by a backward branch,
-                                       // so according to the "backward branch constraint" that must mean the stack is empty,
-                                       // but note that this may be an unused label followed by another label that is used and
-                                       // that does have a non-zero stack height, so we don't yet set stackHeight here.
-                                       labelStackHeight[loc.Index] = 0;
-                               }
-                               else
-                               {
-                                       labelStackHeight[loc.Index] = stackHeight;
-                               }
-                       }
-                       else
-                       {
-                               Debug.Assert(stackHeight == -1 || stackHeight == labelStackHeight[loc.Index]);
-                               stackHeight = labelStackHeight[loc.Index];
-                       }
-               }
-
-               public void MarkSequencePoint(ISymbolDocumentWriter document, int startLine, int startColumn, int endLine, int endColumn)
-               {
-                       SequencePoint sp = new SequencePoint();
-                       sp.document = document;
-                       sp.offset = code.Position;
-                       sp.startLine = startLine;
-                       sp.startColumn = startColumn;
-                       sp.endLine = endLine;
-                       sp.endColumn = endColumn;
-                       sequencePoints.Add(sp);
-               }
-
-               public void ThrowException(Type excType)
-               {
-                       Emit(OpCodes.Newobj, excType.GetConstructor(Type.EmptyTypes));
-                       Emit(OpCodes.Throw);
-               }
-
-               internal int WriteBody(bool initLocals)
-               {
-                       if (moduleBuilder.symbolWriter != null)
-                       {
-                               Debug.Assert(scope != null && scope.parent == null);
-                               scope.endOffset = code.Position;
-                       }
-
-                       ResolveBranches();
-
-                       ByteBuffer bb = moduleBuilder.methodBodies;
-
-                       int localVarSigTok = 0;
-
-                       int rva;
-                       if (localsCount == 0 && exceptions.Count == 0 && maxStack <= 8 && code.Length < 64 && !fatHeader)
-                       {
-                               rva = WriteTinyHeaderAndCode(bb);
-                       }
-                       else
-                       {
-                               if (localsCount != 0)
-                               {
-                                       localVarSigTok = moduleBuilder.GetSignatureToken(locals).Token;
-                               }
-                               rva = WriteFatHeaderAndCode(bb, localVarSigTok, initLocals);
-                       }
-
-                       if (moduleBuilder.symbolWriter != null)
-                       {
-                               if (sequencePoints.Count != 0)
-                               {
-                                       ISymbolDocumentWriter document = sequencePoints[0].document;
-                                       int[] offsets = new int[sequencePoints.Count];
-                                       int[] lines = new int[sequencePoints.Count];
-                                       int[] columns = new int[sequencePoints.Count];
-                                       int[] endLines = new int[sequencePoints.Count];
-                                       int[] endColumns = new int[sequencePoints.Count];
-                                       for (int i = 0; i < sequencePoints.Count; i++)
-                                       {
-                                               if (sequencePoints[i].document != document)
-                                               {
-                                                       throw new NotImplementedException();
-                                               }
-                                               offsets[i] = sequencePoints[i].offset;
-                                               lines[i] = sequencePoints[i].startLine;
-                                               columns[i] = sequencePoints[i].startColumn;
-                                               endLines[i] = sequencePoints[i].endLine;
-                                               endColumns[i] = sequencePoints[i].endColumn;
-                                       }
-                                       moduleBuilder.symbolWriter.DefineSequencePoints(document, offsets, lines, columns, endLines, endColumns);
-                               }
-
-                               WriteScope(scope, localVarSigTok);
-                       }
-                       return rva;
-               }
-
-               private void ResolveBranches()
-               {
-                       foreach (LabelFixup fixup in labelFixups)
-                       {
-                               // is it a switch?
-                               if (fixup.label == -1)
-                               {
-                                       code.Position = fixup.offset;
-                                       int count = code.GetInt32AtCurrentPosition();
-                                       int offset = fixup.offset + 4 + 4 * count;
-                                       code.Position += 4;
-                                       for (int i = 0; i < count; i++)
-                                       {
-                                               int index = code.GetInt32AtCurrentPosition();
-                                               code.Write(labels[index] - offset);
-                                       }
-                               }
-                               else
-                               {
-                                       code.Position = fixup.offset;
-                                       byte size = code.GetByteAtCurrentPosition();
-                                       int branchOffset = labels[fixup.label] - (code.Position + size);
-                                       if (size == 1)
-                                       {
-                                               WriteByteBranchOffset(branchOffset);
-                                       }
-                                       else
-                                       {
-                                               code.Write(branchOffset);
-                                       }
-                               }
-                       }
-               }
-
-               internal static void WriteTinyHeader(ByteBuffer bb, int length)
-               {
-                       const byte CorILMethod_TinyFormat = 0x2;
-                       bb.Write((byte)(CorILMethod_TinyFormat | (length << 2)));
-               }
-
-               private int WriteTinyHeaderAndCode(ByteBuffer bb)
-               {
-                       int rva = bb.Position;
-                       WriteTinyHeader(bb, code.Length);
-                       AddTokenFixups(bb.Position, moduleBuilder.tokenFixupOffsets, tokenFixups);
-                       bb.Write(code);
-                       return rva;
-               }
-
-               internal static void WriteFatHeader(ByteBuffer bb, bool initLocals, bool exceptions, ushort maxStack, int codeLength, int localVarSigTok)
-               {
-                       const byte CorILMethod_FatFormat = 0x03;
-                       const byte CorILMethod_MoreSects = 0x08;
-                       const byte CorILMethod_InitLocals = 0x10;
-
-                       short flagsAndSize = (short)(CorILMethod_FatFormat | (3 << 12));
-                       if (initLocals)
-                       {
-                               flagsAndSize |= CorILMethod_InitLocals;
-                       }
-
-                       if (exceptions)
-                       {
-                               flagsAndSize |= CorILMethod_MoreSects;
-                       }
-
-                       bb.Write(flagsAndSize);
-                       bb.Write(maxStack);
-                       bb.Write(codeLength);
-                       bb.Write(localVarSigTok);
-               }
-
-               private int WriteFatHeaderAndCode(ByteBuffer bb, int localVarSigTok, bool initLocals)
-               {
-                       // fat headers require 4-byte alignment
-                       bb.Align(4);
-                       int rva = bb.Position;
-                       WriteFatHeader(bb, initLocals, exceptions.Count > 0, maxStack, code.Length, localVarSigTok);
-                       AddTokenFixups(bb.Position, moduleBuilder.tokenFixupOffsets, tokenFixups);
-                       bb.Write(code);
-                       if (exceptions.Count > 0)
-                       {
-                               exceptions.Sort(exceptions[0]);
-                               WriteExceptionHandlers(bb, exceptions);
-                       }
-                       return rva;
-               }
-
-               internal static void WriteExceptionHandlers(ByteBuffer bb, List<ExceptionBlock> exceptions)
-               {
-                       bb.Align(4);
-
-                       bool fat = false;
-                       if (exceptions.Count * 12 + 4 > 255)
-                       {
-                               fat = true;
-                       }
-                       else
-                       {
-                               foreach (ExceptionBlock block in exceptions)
-                               {
-                                       if (block.tryOffset > 65535 || block.tryLength > 255 || block.handlerOffset > 65535 || block.handlerLength > 255)
-                                       {
-                                               fat = true;
-                                               break;
-                                       }
-                               }
-                       }
-
-                       const byte CorILMethod_Sect_EHTable = 0x1;
-                       const byte CorILMethod_Sect_FatFormat = 0x40;
-
-                       if (fat)
-                       {
-                               bb.Write((byte)(CorILMethod_Sect_EHTable | CorILMethod_Sect_FatFormat));
-                               int dataSize = exceptions.Count * 24 + 4;
-                               bb.Write((byte)dataSize);
-                               bb.Write((short)(dataSize >> 8));
-                               foreach (ExceptionBlock block in exceptions)
-                               {
-                                       bb.Write((int)block.kind);
-                                       bb.Write(block.tryOffset);
-                                       bb.Write(block.tryLength);
-                                       bb.Write(block.handlerOffset);
-                                       bb.Write(block.handlerLength);
-                                       bb.Write(block.filterOffsetOrExceptionTypeToken);
-                               }
-                       }
-                       else
-                       {
-                               bb.Write(CorILMethod_Sect_EHTable);
-                               bb.Write((byte)(exceptions.Count * 12 + 4));
-                               bb.Write((short)0);
-                               foreach (ExceptionBlock block in exceptions)
-                               {
-                                       bb.Write((short)block.kind);
-                                       bb.Write((short)block.tryOffset);
-                                       bb.Write((byte)block.tryLength);
-                                       bb.Write((short)block.handlerOffset);
-                                       bb.Write((byte)block.handlerLength);
-                                       bb.Write(block.filterOffsetOrExceptionTypeToken);
-                               }
-                       }
-               }
-
-               internal static void AddTokenFixups(int codeOffset, List<int> tokenFixupOffsets, IEnumerable<int> tokenFixups)
-               {
-                       foreach (int fixup in tokenFixups)
-                       {
-                               tokenFixupOffsets.Add(fixup + codeOffset);
-                       }
-               }
-
-               private void WriteScope(Scope scope, int localVarSigTok)
-               {
-                       moduleBuilder.symbolWriter.OpenScope(scope.startOffset);
-                       foreach (LocalBuilder local in scope.locals)
-                       {
-                               if (local.name != null)
-                               {
-                                       int startOffset = local.startOffset;
-                                       int endOffset = local.endOffset;
-                                       if (startOffset == 0 && endOffset == 0)
-                                       {
-                                               startOffset = scope.startOffset;
-                                               endOffset = scope.endOffset;
-                                       }
-                                       moduleBuilder.symbolWriter.DefineLocalVariable2(local.name, 0, localVarSigTok, SymAddressKind.ILOffset, local.LocalIndex, 0, 0, startOffset, endOffset);
-                               }
-                       }
-                       foreach (Scope child in scope.children)
-                       {
-                               WriteScope(child, localVarSigTok);
-                       }
-                       moduleBuilder.symbolWriter.CloseScope(scope.endOffset);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs b/mcs/class/IKVM.Reflection/Emit/MethodBuilder.cs
deleted file mode 100644 (file)
index 486e74c..0000000
+++ /dev/null
@@ -1,778 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using System.Diagnostics;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-using System.Diagnostics.SymbolStore;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class MethodBuilder : MethodInfo
-       {
-               private readonly TypeBuilder typeBuilder;
-               private readonly string name;
-               private readonly int pseudoToken;
-               private int nameIndex;
-               private int signature;
-               private Type returnType;
-               private Type[] parameterTypes;
-               private PackedCustomModifiers customModifiers;
-               private MethodAttributes attributes;
-               private MethodImplAttributes implFlags;
-               private ILGenerator ilgen;
-               private int rva = -1;
-               private CallingConventions callingConvention;
-               private List<ParameterBuilder> parameters;
-               private GenericTypeParameterBuilder[] gtpb;
-               private List<CustomAttributeBuilder> declarativeSecurity;
-               private MethodSignature methodSignature;
-               private bool initLocals = true;
-
-               internal MethodBuilder(TypeBuilder typeBuilder, string name, MethodAttributes attributes, CallingConventions callingConvention)
-               {
-                       this.typeBuilder = typeBuilder;
-                       this.name = name;
-                       this.pseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
-                       this.attributes = attributes;
-                       if ((attributes & MethodAttributes.Static) == 0)
-                       {
-                               callingConvention |= CallingConventions.HasThis;
-                       }
-                       this.callingConvention = callingConvention;
-               }
-
-               public ILGenerator GetILGenerator()
-               {
-                       return GetILGenerator(16);
-               }
-
-               public ILGenerator GetILGenerator(int streamSize)
-               {
-                       if (rva != -1)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       if (ilgen == null)
-                       {
-                               ilgen = new ILGenerator(typeBuilder.ModuleBuilder, streamSize);
-                       }
-                       return ilgen;
-               }
-
-               public void __ReleaseILGenerator()
-               {
-                       if (ilgen != null)
-                       {
-                               if (this.ModuleBuilder.symbolWriter != null)
-                               {
-                                       this.ModuleBuilder.symbolWriter.OpenMethod(new SymbolToken(-pseudoToken | 0x06000000), this);
-                               }
-                               rva = ilgen.WriteBody(initLocals);
-                               if (this.ModuleBuilder.symbolWriter != null)
-                               {
-                                       this.ModuleBuilder.symbolWriter.CloseMethod();
-                               }
-                               ilgen = null;
-                       }
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               private void SetDllImportPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       CallingConvention? callingConvention = customBuilder.GetFieldValue<CallingConvention>("CallingConvention");
-                       CharSet? charSet = customBuilder.GetFieldValue<CharSet>("CharSet");
-                       SetDllImportPseudoCustomAttribute((string)customBuilder.GetConstructorArgument(0),
-                               (string)customBuilder.GetFieldValue("EntryPoint"),
-                               callingConvention,
-                               charSet,
-                               (bool?)customBuilder.GetFieldValue("BestFitMapping"),
-                               (bool?)customBuilder.GetFieldValue("ThrowOnUnmappableChar"),
-                               (bool?)customBuilder.GetFieldValue("SetLastError"),
-                               (bool?)customBuilder.GetFieldValue("PreserveSig"),
-                               (bool?)customBuilder.GetFieldValue("ExactSpelling"));
-               }
-
-               internal void SetDllImportPseudoCustomAttribute(string dllName, string entryName, CallingConvention? nativeCallConv, CharSet? nativeCharSet,
-                       bool? bestFitMapping, bool? throwOnUnmappableChar, bool? setLastError, bool? preserveSig, bool? exactSpelling)
-               {
-                       const short NoMangle = 0x0001;
-                       const short CharSetMask = 0x0006;
-                       const short CharSetNotSpec = 0x0000;
-                       const short CharSetAnsi = 0x0002;
-                       const short CharSetUnicode = 0x0004;
-                       const short CharSetAuto = 0x0006;
-                       const short SupportsLastError = 0x0040;
-                       const short CallConvMask = 0x0700;
-                       const short CallConvWinapi = 0x0100;
-                       const short CallConvCdecl = 0x0200;
-                       const short CallConvStdcall = 0x0300;
-                       const short CallConvThiscall = 0x0400;
-                       const short CallConvFastcall = 0x0500;
-                       // non-standard flags
-                       const short BestFitOn = 0x0010;
-                       const short BestFitOff = 0x0020;
-                       const short CharMapErrorOn = 0x1000;
-                       const short CharMapErrorOff = 0x2000;
-                       short flags = CharSetNotSpec | CallConvWinapi;
-                       if (bestFitMapping.HasValue)
-                       {
-                               flags |= bestFitMapping.Value ? BestFitOn : BestFitOff;
-                       }
-                       if (throwOnUnmappableChar.HasValue)
-                       {
-                               flags |= throwOnUnmappableChar.Value ? CharMapErrorOn : CharMapErrorOff;
-                       }
-                       if (nativeCallConv.HasValue)
-                       {
-                               flags &= ~CallConvMask;
-                               switch (nativeCallConv.Value)
-                               {
-                                       case System.Runtime.InteropServices.CallingConvention.Cdecl:
-                                               flags |= CallConvCdecl;
-                                               break;
-                                       case System.Runtime.InteropServices.CallingConvention.FastCall:
-                                               flags |= CallConvFastcall;
-                                               break;
-                                       case System.Runtime.InteropServices.CallingConvention.StdCall:
-                                               flags |= CallConvStdcall;
-                                               break;
-                                       case System.Runtime.InteropServices.CallingConvention.ThisCall:
-                                               flags |= CallConvThiscall;
-                                               break;
-                                       case System.Runtime.InteropServices.CallingConvention.Winapi:
-                                               flags |= CallConvWinapi;
-                                               break;
-                               }
-                       }
-                       if (nativeCharSet.HasValue)
-                       {
-                               flags &= ~CharSetMask;
-                               switch (nativeCharSet.Value)
-                               {
-                                       case CharSet.Ansi:
-                                       case CharSet.None:
-                                               flags |= CharSetAnsi;
-                                               break;
-                                       case CharSet.Auto:
-                                               flags |= CharSetAuto;
-                                               break;
-                                       case CharSet.Unicode:
-                                               flags |= CharSetUnicode;
-                                               break;
-                               }
-                       }
-                       if (exactSpelling.HasValue && exactSpelling.Value)
-                       {
-                               flags |= NoMangle;
-                       }
-                       if (!preserveSig.HasValue || preserveSig.Value)
-                       {
-                               implFlags |= MethodImplAttributes.PreserveSig;
-                       }
-                       if (setLastError.HasValue && setLastError.Value)
-                       {
-                               flags |= SupportsLastError;
-                       }
-                       ImplMapTable.Record rec = new ImplMapTable.Record();
-                       rec.MappingFlags = flags;
-                       rec.MemberForwarded = pseudoToken;
-                       rec.ImportName = this.ModuleBuilder.Strings.Add(entryName ?? name);
-                       rec.ImportScope = this.ModuleBuilder.ModuleRef.FindOrAddRecord(dllName == null ? 0 : this.ModuleBuilder.Strings.Add(dllName));
-                       this.ModuleBuilder.ImplMap.AddRecord(rec);
-               }
-
-               private void SetMethodImplAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       MethodImplOptions opt;
-                       switch (customBuilder.Constructor.ParameterCount)
-                       {
-                               case 0:
-                                       opt = 0;
-                                       break;
-                               case 1:
-                                       {
-                                               object val = customBuilder.GetConstructorArgument(0);
-                                               if (val is short)
-                                               {
-                                                       opt = (MethodImplOptions)(short)val;
-                                               }
-                                               else if (val is int)
-                                               {
-                                                       opt = (MethodImplOptions)(int)val;
-                                               }
-                                               else
-                                               {
-                                                       opt = (MethodImplOptions)val;
-                                               }
-                                               break;
-                                       }
-                               default:
-                                       throw new NotSupportedException();
-                       }
-                       MethodCodeType? type = customBuilder.GetFieldValue<MethodCodeType>("MethodCodeType");
-                       implFlags = (MethodImplAttributes)opt;
-                       if (type.HasValue)
-                       {
-                               implFlags |= (MethodImplAttributes)type;
-                       }
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       Universe u = this.ModuleBuilder.universe;
-                       Type type = customBuilder.Constructor.DeclaringType;
-                       if (type == u.System_Runtime_InteropServices_DllImportAttribute)
-                       {
-                               attributes |= MethodAttributes.PinvokeImpl;
-                               SetDllImportPseudoCustomAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
-                       }
-                       else if (type == u.System_Runtime_CompilerServices_MethodImplAttribute)
-                       {
-                               SetMethodImplAttribute(customBuilder.DecodeBlob(this.Module.Assembly));
-                       }
-                       else if (type == u.System_Runtime_InteropServices_PreserveSigAttribute)
-                       {
-                               implFlags |= MethodImplAttributes.PreserveSig;
-                       }
-                       else if (type == u.System_Runtime_CompilerServices_SpecialNameAttribute)
-                       {
-                               attributes |= MethodAttributes.SpecialName;
-                       }
-                       else
-                       {
-                               if (type == u.System_Security_SuppressUnmanagedCodeSecurityAttribute)
-                               {
-                                       attributes |= MethodAttributes.HasSecurity;
-                               }
-                               this.ModuleBuilder.SetCustomAttribute(pseudoToken, customBuilder);
-                       }
-               }
-
-               public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
-               {
-                       attributes |= MethodAttributes.HasSecurity;
-                       if (declarativeSecurity == null)
-                       {
-                               declarativeSecurity = new List<CustomAttributeBuilder>();
-                       }
-                       declarativeSecurity.Add(customBuilder);
-               }
-
-               public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
-               {
-                       this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, securityAction, permissionSet);
-                       this.attributes |= MethodAttributes.HasSecurity;
-               }
-
-               public void SetImplementationFlags(MethodImplAttributes attributes)
-               {
-                       implFlags = attributes;
-               }
-
-               public ParameterBuilder DefineParameter(int position, ParameterAttributes attributes, string strParamName)
-               {
-                       if (parameters == null)
-                       {
-                               parameters = new List<ParameterBuilder>();
-                       }
-                       this.ModuleBuilder.Param.AddVirtualRecord();
-                       ParameterBuilder pb = new ParameterBuilder(this.ModuleBuilder, position, attributes, strParamName);
-                       if (parameters.Count == 0 || position > parameters[parameters.Count - 1].Position)
-                       {
-                               parameters.Add(pb);
-                       }
-                       else
-                       {
-                               for (int i = 0; i < parameters.Count; i++)
-                               {
-                                       if (parameters[i].Position > position)
-                                       {
-                                               parameters.Insert(i, pb);
-                                               break;
-                                       }
-                               }
-                       }
-                       return pb;
-               }
-
-               private void CheckSig()
-               {
-                       if (methodSignature != null)
-                       {
-                               throw new InvalidOperationException("The method signature can not be modified after it has been used.");
-                       }
-               }
-
-               public void SetParameters(params Type[] parameterTypes)
-               {
-                       CheckSig();
-                       this.parameterTypes = Util.Copy(parameterTypes);
-               }
-
-               public void SetReturnType(Type returnType)
-               {
-                       CheckSig();
-                       this.returnType = returnType ?? this.Module.universe.System_Void;
-               }
-
-               public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers,
-                               parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               public void __SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       SetSignature(returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               private void SetSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       CheckSig();
-                       this.returnType = returnType ?? this.Module.universe.System_Void;
-                       this.parameterTypes = Util.Copy(parameterTypes);
-                       this.customModifiers = customModifiers;
-               }
-
-               public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
-               {
-                       CheckSig();
-                       if (gtpb != null)
-                       {
-                               throw new InvalidOperationException("Generic parameters already defined.");
-                       }
-                       gtpb = new GenericTypeParameterBuilder[names.Length];
-                       for (int i = 0; i < names.Length; i++)
-                       {
-                               gtpb[i] = new GenericTypeParameterBuilder(names[i], null, this, i);
-                       }
-                       return (GenericTypeParameterBuilder[])gtpb.Clone();
-               }
-
-               public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       return new GenericMethodInstance(typeBuilder, this, typeArguments);
-               }
-
-               public override MethodInfo GetGenericMethodDefinition()
-               {
-                       if (gtpb == null)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       return this;
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       return Util.Copy(gtpb);
-               }
-
-               internal override Type GetGenericMethodArgument(int index)
-               {
-                       return gtpb[index];
-               }
-
-               internal override int GetGenericMethodArgumentCount()
-               {
-                       return gtpb == null ? 0 : gtpb.Length;
-               }
-
-               public override Type ReturnType
-               {
-                       get { return returnType; }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get { return new ParameterInfoImpl(this, -1); }
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return attributes; }
-               }
-
-               public void __SetAttributes(MethodAttributes attributes)
-               {
-                       this.attributes = attributes;
-               }
-
-               public void __SetCallingConvention(CallingConventions callingConvention)
-               {
-                       this.callingConvention = callingConvention;
-                       this.methodSignature = null;
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return implFlags;
-               }
-
-               private sealed class ParameterInfoImpl : ParameterInfo
-               {
-                       private readonly MethodBuilder method;
-                       private readonly int parameter;
-
-                       internal ParameterInfoImpl(MethodBuilder method, int parameter)
-                       {
-                               this.method = method;
-                               this.parameter = parameter;
-                       }
-
-                       private ParameterBuilder ParameterBuilder
-                       {
-                               get
-                               {
-                                       if (method.parameters != null)
-                                       {
-                                               foreach (ParameterBuilder pb in method.parameters)
-                                               {
-                                                       // ParameterBuilder.Position is 1-based
-                                                       if (pb.Position - 1 == parameter)
-                                                       {
-                                                               return pb;
-                                                       }
-                                               }
-                                       }
-                                       return null;
-                               }
-                       }
-
-                       public override string Name
-                       {
-                               get
-                               {
-                                       ParameterBuilder pb = this.ParameterBuilder;
-                                       return pb != null ? pb.Name : null;
-                               }
-                       }
-
-                       public override Type ParameterType
-                       {
-                               get { return parameter == -1 ? method.returnType : method.parameterTypes[parameter]; }
-                       }
-
-                       public override ParameterAttributes Attributes
-                       {
-                               get
-                               {
-                                       ParameterBuilder pb = this.ParameterBuilder;
-                                       return pb != null ? (ParameterAttributes)pb.Attributes : ParameterAttributes.None;
-                               }
-                       }
-
-                       public override int Position
-                       {
-                               get { return parameter; }
-                       }
-
-                       public override object RawDefaultValue
-                       {
-                               get
-                               {
-                                       ParameterBuilder pb = this.ParameterBuilder;
-                                       if (pb != null && (pb.Attributes & (int)ParameterAttributes.HasDefault) != 0)
-                                       {
-                                               return method.ModuleBuilder.Constant.GetRawConstantValue(method.ModuleBuilder, pb.PseudoToken);
-                                       }
-                                       if (pb != null && (pb.Attributes & (int)ParameterAttributes.Optional) != 0)
-                                       {
-                                               return Missing.Value;
-                                       }
-                                       return null;
-                               }
-                       }
-
-                       public override CustomModifiers __GetCustomModifiers()
-                       {
-                               return method.customModifiers.GetParameterCustomModifiers(parameter);
-                       }
-
-                       public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-                       {
-                               fieldMarshal = new FieldMarshal();
-                               return false;
-                       }
-
-                       public override MemberInfo Member
-                       {
-                               get { return method; }
-                       }
-
-                       public override int MetadataToken
-                       {
-                               get
-                               {
-                                       ParameterBuilder pb = this.ParameterBuilder;
-                                       return pb != null ? pb.PseudoToken : 0x08000000;
-                               }
-                       }
-
-                       internal override Module Module
-                       {
-                               get { return method.Module; }
-                       }
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameters = new ParameterInfo[parameterTypes.Length];
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoImpl(this, i);
-                       }
-                       return parameters;
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return parameterTypes.Length; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeBuilder.IsModulePseudoType ? null : typeBuilder; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return callingConvention; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return pseudoToken; }
-               }
-
-               public override bool IsGenericMethod
-               {
-                       get { return gtpb != null; }
-               }
-
-               public override bool IsGenericMethodDefinition
-               {
-                       get { return gtpb != null; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeBuilder.Module; }
-               }
-
-               public Module GetModule()
-               {
-                       return typeBuilder.Module;
-               }
-
-               public MethodToken GetToken()
-               {
-                       return new MethodToken(pseudoToken);
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public override int __MethodRVA
-               {
-                       get { throw new NotImplementedException(); }
-               }
-
-               public bool InitLocals
-               {
-                       get { return initLocals; }
-                       set { initLocals = value; }
-               }
-
-               public void __AddUnmanagedExport(string name, int ordinal)
-               {
-                       this.ModuleBuilder.AddUnmanagedExport(name, ordinal, this, new RelativeVirtualAddress(0xFFFFFFFF));
-               }
-
-               public void CreateMethodBody(byte[] il, int count)
-               {
-                       if (il == null)
-                       {
-                               throw new NotSupportedException();
-                       }
-                       if (il.Length != count)
-                       {
-                               Array.Resize(ref il, count);
-                       }
-                       SetMethodBody(il, 16, null, null, null);
-               }
-
-               public void SetMethodBody(byte[] il, int maxStack, byte[] localSignature, IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
-               {
-                       ByteBuffer bb = this.ModuleBuilder.methodBodies;
-
-                       if (localSignature == null && exceptionHandlers == null && maxStack <= 8 && il.Length < 64)
-                       {
-                               rva = bb.Position;
-                               ILGenerator.WriteTinyHeader(bb, il.Length);
-                       }
-                       else
-                       {
-                               // fat headers require 4-byte alignment
-                               bb.Align(4);
-                               rva = bb.Position;
-                               ILGenerator.WriteFatHeader(bb, initLocals, exceptionHandlers != null, (ushort)maxStack, il.Length,
-                                       localSignature == null ? 0 : this.ModuleBuilder.GetSignatureToken(localSignature, localSignature.Length).Token);
-                       }
-
-                       if (tokenFixups != null)
-                       {
-                               ILGenerator.AddTokenFixups(bb.Position, this.ModuleBuilder.tokenFixupOffsets, tokenFixups);
-                       }
-                       bb.Write(il);
-
-                       if (exceptionHandlers != null)
-                       {
-                               List<ILGenerator.ExceptionBlock> exceptions = new List<ILGenerator.ExceptionBlock>();
-                               foreach (ExceptionHandler block in exceptionHandlers)
-                               {
-                                       exceptions.Add(new ILGenerator.ExceptionBlock(block));
-                               }
-                               ILGenerator.WriteExceptionHandlers(bb, exceptions);
-                       }
-               }
-
-               internal void Bake()
-               {
-                       this.nameIndex = this.ModuleBuilder.Strings.Add(name);
-                       this.signature = this.ModuleBuilder.GetSignatureBlobIndex(this.MethodSignature);
-
-                       __ReleaseILGenerator();
-
-                       if (declarativeSecurity != null)
-                       {
-                               this.ModuleBuilder.AddDeclarativeSecurity(pseudoToken, declarativeSecurity);
-                       }
-               }
-
-               internal ModuleBuilder ModuleBuilder
-               {
-                       get { return typeBuilder.ModuleBuilder; }
-               }
-
-               internal void WriteMethodDefRecord(int baseRVA, MetadataWriter mw, ref int paramList)
-               {
-                       if (rva != -1)
-                       {
-                               mw.Write(rva + baseRVA);
-                       }
-                       else
-                       {
-                               mw.Write(0);
-                       }
-                       mw.Write((short)implFlags);
-                       mw.Write((short)attributes);
-                       mw.WriteStringIndex(nameIndex);
-                       mw.WriteBlobIndex(signature);
-                       mw.WriteParam(paramList);
-                       if (parameters != null)
-                       {
-                               paramList += parameters.Count;
-                       }
-               }
-
-               internal void WriteParamRecords(MetadataWriter mw)
-               {
-                       if (parameters != null)
-                       {
-                               foreach (ParameterBuilder pb in parameters)
-                               {
-                                       pb.WriteParamRecord(mw);
-                               }
-                       }
-               }
-
-               internal void FixupToken(int token, ref int parameterToken)
-               {
-                       typeBuilder.ModuleBuilder.RegisterTokenFixup(this.pseudoToken, token);
-                       if (parameters != null)
-                       {
-                               foreach (ParameterBuilder pb in parameters)
-                               {
-                                       pb.FixupToken(parameterToken++);
-                               }
-                       }
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get
-                       {
-                               if (methodSignature == null)
-                               {
-                                       methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, customModifiers, callingConvention, gtpb == null ? 0 : gtpb.Length);
-                               }
-                               return methodSignature;
-                       }
-               }
-
-               internal override int ImportTo(ModuleBuilder other)
-               {
-                       return other.ImportMethodOrField(typeBuilder, name, this.MethodSignature);
-               }
-
-               internal void CheckBaked()
-               {
-                       typeBuilder.CheckBaked();
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       if (typeBuilder.ModuleBuilder.IsSaved)
-                       {
-                               return typeBuilder.ModuleBuilder.ResolvePseudoToken(pseudoToken);
-                       }
-                       else
-                       {
-                               return pseudoToken;
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return typeBuilder.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/ModuleBuilder.cs b/mcs/class/IKVM.Reflection/Emit/ModuleBuilder.cs
deleted file mode 100644 (file)
index 7a64f24..0000000
+++ /dev/null
@@ -1,1881 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Diagnostics;
-using System.Diagnostics.SymbolStore;
-using System.Security.Cryptography;
-using System.Resources;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using IKVM.Reflection.Impl;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class ModuleBuilder : Module, ITypeOwner
-       {
-               private static readonly bool usePublicKeyAssemblyReference = false;
-               private Guid mvid = Guid.NewGuid();
-               private long imageBaseAddress = 0x00400000;
-               private long stackReserve = -1;
-               private int fileAlignment = 0x200;
-               private DllCharacteristics dllCharacteristics = DllCharacteristics.DynamicBase | DllCharacteristics.NoSEH | DllCharacteristics.NXCompat | DllCharacteristics.TerminalServerAware;
-               private readonly AssemblyBuilder asm;
-               internal readonly string moduleName;
-               internal readonly string fileName;
-               internal readonly ISymbolWriterImpl symbolWriter;
-               private readonly TypeBuilder moduleType;
-               private readonly List<TypeBuilder> types = new List<TypeBuilder>();
-               private readonly Dictionary<Type, int> typeTokens = new Dictionary<Type, int>();
-               private readonly Dictionary<Type, int> memberRefTypeTokens = new Dictionary<Type, int>();
-               internal readonly ByteBuffer methodBodies = new ByteBuffer(128 * 1024);
-               internal readonly List<int> tokenFixupOffsets = new List<int>();
-               internal readonly ByteBuffer initializedData = new ByteBuffer(512);
-               internal readonly ByteBuffer manifestResources = new ByteBuffer(512);
-               internal ResourceSection unmanagedResources;
-               private readonly Dictionary<MemberRefKey, int> importedMemberRefs = new Dictionary<MemberRefKey, int>();
-               private readonly Dictionary<MethodSpecKey, int> importedMethodSpecs = new Dictionary<MethodSpecKey, int>();
-               private readonly Dictionary<Assembly, int> referencedAssemblies = new Dictionary<Assembly, int>();
-               private List<AssemblyName> referencedAssemblyNames;
-               private int nextPseudoToken = -1;
-               private readonly List<int> resolvedTokens = new List<int>();
-               internal readonly TableHeap Tables = new TableHeap();
-               internal readonly StringHeap Strings = new StringHeap();
-               internal readonly UserStringHeap UserStrings = new UserStringHeap();
-               internal readonly GuidHeap Guids = new GuidHeap();
-               internal readonly BlobHeap Blobs = new BlobHeap();
-               internal readonly List<VTableFixups> vtablefixups = new List<VTableFixups>();
-               internal readonly List<UnmanagedExport> unmanagedExports = new List<UnmanagedExport>();
-               private List<InterfaceImplCustomAttribute> interfaceImplCustomAttributes;
-               private List<ResourceWriterRecord> resourceWriters;
-               private bool saved;
-
-               private struct ResourceWriterRecord
-               {
-                       private readonly string name;
-                       private readonly ResourceWriter rw;
-                       private readonly MemoryStream mem;
-                       private readonly ResourceAttributes attributes;
-
-                       internal ResourceWriterRecord(string name, ResourceWriter rw, MemoryStream mem, ResourceAttributes attributes)
-                       {
-                               this.name = name;
-                               this.rw = rw;
-                               this.mem = mem;
-                               this.attributes = attributes;
-                       }
-
-                       internal void Emit(ModuleBuilder mb)
-                       {
-                               rw.Generate();
-                               mem.Position = 0;
-                               mb.DefineManifestResource(name, mem, attributes);
-                               rw.Close();
-                       }
-               }
-
-               internal struct VTableFixups
-               {
-                       internal uint initializedDataOffset;
-                       internal ushort count;
-                       internal ushort type;
-
-                       internal int SlotWidth
-                       {
-                               get { return (type & 0x02) == 0 ? 4 : 8; }
-                       }
-               }
-
-               struct InterfaceImplCustomAttribute
-               {
-                       internal int type;
-                       internal int interfaceType;
-                       internal int pseudoToken;
-               }
-
-               struct MemberRefKey : IEquatable<MemberRefKey>
-               {
-                       private readonly Type type;
-                       private readonly string name;
-                       private readonly Signature signature;
-
-                       internal MemberRefKey(Type type, string name, Signature signature)
-                       {
-                               this.type = type;
-                               this.name = name;
-                               this.signature = signature;
-                       }
-
-                       public bool Equals(MemberRefKey other)
-                       {
-                               return other.type.Equals(type)
-                                       && other.name == name
-                                       && other.signature.Equals(signature);
-                       }
-
-                       public override bool Equals(object obj)
-                       {
-                               MemberRefKey? other = obj as MemberRefKey?;
-                               return other != null && Equals(other);
-                       }
-
-                       public override int GetHashCode()
-                       {
-                               return type.GetHashCode() + name.GetHashCode() + signature.GetHashCode();
-                       }
-
-                       internal MethodBase LookupMethod()
-                       {
-                               return type.FindMethod(name, (MethodSignature)signature);
-                       }
-               }
-
-               struct MethodSpecKey : IEquatable<MethodSpecKey>
-               {
-                       private readonly Type type;
-                       private readonly string name;
-                       private readonly MethodSignature signature;
-                       private readonly Type[] genericParameters;
-
-                       internal MethodSpecKey(Type type, string name, MethodSignature signature, Type[] genericParameters)
-                       {
-                               this.type = type;
-                               this.name = name;
-                               this.signature = signature;
-                               this.genericParameters = genericParameters;
-                       }
-
-                       public bool Equals(MethodSpecKey other)
-                       {
-                               return other.type.Equals(type)
-                                       && other.name == name
-                                       && other.signature.Equals(signature)
-                                       && Util.ArrayEquals(other.genericParameters, genericParameters);
-                       }
-
-                       public override bool Equals(object obj)
-                       {
-                               MethodSpecKey? other = obj as MethodSpecKey?;
-                               return other != null && Equals(other);
-                       }
-
-                       public override int GetHashCode()
-                       {
-                               return type.GetHashCode() + name.GetHashCode() + signature.GetHashCode() + Util.GetHashCode(genericParameters);
-                       }
-               }
-
-               internal ModuleBuilder(AssemblyBuilder asm, string moduleName, string fileName, bool emitSymbolInfo)
-                       : base(asm.universe)
-               {
-                       this.asm = asm;
-                       this.moduleName = moduleName;
-                       this.fileName = fileName;
-                       if (emitSymbolInfo)
-                       {
-                               symbolWriter = SymbolSupport.CreateSymbolWriterFor(this);
-                       }
-                       // <Module> must be the first record in the TypeDef table
-                       moduleType = new TypeBuilder(this, null, "<Module>");
-                       types.Add(moduleType);
-               }
-
-               internal void PopulatePropertyAndEventTables()
-               {
-                       // LAMESPEC the PropertyMap and EventMap tables are not required to be sorted by the CLI spec,
-                       // but .NET sorts them and Mono requires them to be sorted, so we have to populate the
-                       // tables in the right order
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.PopulatePropertyAndEventTables();
-                       }
-               }
-
-               internal void WriteTypeDefTable(MetadataWriter mw)
-               {
-                       int fieldList = 1;
-                       int methodList = 1;
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.WriteTypeDefRecord(mw, ref fieldList, ref methodList);
-                       }
-               }
-
-               internal void WriteMethodDefTable(int baseRVA, MetadataWriter mw)
-               {
-                       int paramList = 1;
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.WriteMethodDefRecords(baseRVA, mw, ref paramList);
-                       }
-               }
-
-               internal void WriteParamTable(MetadataWriter mw)
-               {
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.WriteParamRecords(mw);
-                       }
-               }
-
-               internal void WriteFieldTable(MetadataWriter mw)
-               {
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.WriteFieldRecords(mw);
-                       }
-               }
-
-               internal int AllocPseudoToken()
-               {
-                       return nextPseudoToken--;
-               }
-
-               public TypeBuilder DefineType(string name)
-               {
-                       return DefineType(name, TypeAttributes.Class);
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr)
-               {
-                       return DefineType(name, attr, null);
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent)
-               {
-                       return DefineType(name, attr, parent, PackingSize.Unspecified, 0);
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, int typesize)
-               {
-                       return DefineType(name, attr, parent, PackingSize.Unspecified, typesize);
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packsize)
-               {
-                       return DefineType(name, attr, parent, packsize, 0);
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, Type[] interfaces)
-               {
-                       TypeBuilder tb = DefineType(name, attr, parent);
-                       foreach (Type iface in interfaces)
-                       {
-                               tb.AddInterfaceImplementation(iface);
-                       }
-                       return tb;
-               }
-
-               public TypeBuilder DefineType(string name, TypeAttributes attr, Type parent, PackingSize packingSize, int typesize)
-               {
-                       string ns = null;
-                       int lastdot = name.LastIndexOf('.');
-                       if (lastdot > 0)
-                       {
-                               ns = name.Substring(0, lastdot);
-                               name = name.Substring(lastdot + 1);
-                       }
-                       TypeBuilder typeBuilder = __DefineType(ns, name);
-                       typeBuilder.__SetAttributes(attr);
-                       typeBuilder.SetParent(parent);
-                       if (packingSize != PackingSize.Unspecified || typesize != 0)
-                       {
-                               typeBuilder.__SetLayout((int)packingSize, typesize);
-                       }
-                       return typeBuilder;
-               }
-
-               public TypeBuilder __DefineType(string ns, string name)
-               {
-                       return DefineType(this, ns, name);
-               }
-
-               internal TypeBuilder DefineType(ITypeOwner owner, string ns, string name)
-               {
-                       TypeBuilder typeBuilder = new TypeBuilder(owner, ns, name);
-                       types.Add(typeBuilder);
-                       return typeBuilder;
-               }
-
-               public EnumBuilder DefineEnum(string name, TypeAttributes visibility, Type underlyingType)
-               {
-                       TypeBuilder tb = DefineType(name, (visibility & TypeAttributes.VisibilityMask) | TypeAttributes.Sealed, universe.System_Enum);
-                       FieldBuilder fb = tb.DefineField("value__", underlyingType, FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
-                       return new EnumBuilder(tb, fb);
-               }
-
-               public FieldBuilder __DefineField(string name, Type type, CustomModifiers customModifiers, FieldAttributes attributes)
-               {
-                       return moduleType.__DefineField(name, type, customModifiers, attributes);
-               }
-
-               [Obsolete("Please use __DefineField(string, Type, CustomModifiers, FieldAttributes) instead.")]
-               public FieldBuilder __DefineField(string name, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
-               {
-                       return moduleType.DefineField(name, type, requiredCustomModifiers, optionalCustomModifiers, attributes);
-               }
-
-               public ConstructorBuilder __DefineModuleInitializer(MethodAttributes visibility)
-               {
-                       return moduleType.DefineConstructor(visibility | MethodAttributes.Static | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, CallingConventions.Standard, Type.EmptyTypes);
-               }
-
-               public FieldBuilder DefineUninitializedData(string name, int size, FieldAttributes attributes)
-               {
-                       return moduleType.DefineUninitializedData(name, size, attributes);
-               }
-
-               public FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttributes attributes)
-               {
-                       return moduleType.DefineInitializedData(name, data, attributes);
-               }
-
-               public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes)
-               {
-                       return moduleType.DefineMethod(name, attributes, returnType, parameterTypes);
-               }
-
-               public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       return moduleType.DefineMethod(name, attributes, callingConvention, returnType, parameterTypes);
-               }
-
-               public MethodBuilder DefineGlobalMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
-               {
-                       return moduleType.DefineMethod(name, attributes, callingConvention, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
-               }
-
-               public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
-               {
-                       return moduleType.DefinePInvokeMethod(name, dllName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
-               }
-
-               public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
-               {
-                       return moduleType.DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, parameterTypes, nativeCallConv, nativeCharSet);
-               }
-
-               public void CreateGlobalFunctions()
-               {
-                       moduleType.CreateType();
-               }
-
-               internal void AddTypeForwarder(Type type)
-               {
-                       ExportType(type);
-                       if (!type.__IsMissing)
-                       {
-                               foreach (Type nested in type.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic))
-                               {
-                                       // we export all nested types (i.e. even the private ones)
-                                       // (this behavior is the same as the C# compiler)
-                                       AddTypeForwarder(nested);
-                               }
-                       }
-               }
-
-               private int ExportType(Type type)
-               {
-                       ExportedTypeTable.Record rec = new ExportedTypeTable.Record();
-                       rec.TypeName = this.Strings.Add(type.__Name);
-                       string ns = type.__Namespace;
-                       rec.TypeNamespace = ns == null ? 0 : this.Strings.Add(ns);
-                       if (type.IsNested)
-                       {
-                               rec.Flags = 0;
-                               rec.Implementation = ExportType(type.DeclaringType);
-                       }
-                       else
-                       {
-                               rec.Flags = 0x00200000; // CorTypeAttr.tdForwarder
-                               rec.Implementation = ImportAssemblyRef(type.Assembly);
-                       }
-                       return 0x27000000 | this.ExportedType.FindOrAddRecord(rec);
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       SetCustomAttribute(0x00000001, customBuilder);
-               }
-
-               internal void SetCustomAttribute(int token, CustomAttributeBuilder customBuilder)
-               {
-                       Debug.Assert(!customBuilder.IsPseudoCustomAttribute);
-                       CustomAttributeTable.Record rec = new CustomAttributeTable.Record();
-                       rec.Parent = token;
-                       rec.Type = asm.IsWindowsRuntime ? customBuilder.Constructor.ImportTo(this) : GetConstructorToken(customBuilder.Constructor).Token;
-                       rec.Value = customBuilder.WriteBlob(this);
-                       this.CustomAttribute.AddRecord(rec);
-               }
-
-               internal void AddDeclarativeSecurity(int token, System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
-               {
-                       DeclSecurityTable.Record rec = new DeclSecurityTable.Record();
-                       rec.Action = (short)securityAction;
-                       rec.Parent = token;
-                       // like Ref.Emit, we're using the .NET 1.x xml format
-                       rec.PermissionSet = this.Blobs.Add(ByteBuffer.Wrap(System.Text.Encoding.Unicode.GetBytes(permissionSet.ToXml().ToString())));
-                       this.DeclSecurity.AddRecord(rec);
-               }
-
-               internal void AddDeclarativeSecurity(int token, List<CustomAttributeBuilder> declarativeSecurity)
-               {
-                       Dictionary<int, List<CustomAttributeBuilder>> ordered = new Dictionary<int, List<CustomAttributeBuilder>>();
-                       foreach (CustomAttributeBuilder cab in declarativeSecurity)
-                       {
-                               int action;
-                               // check for HostProtectionAttribute without SecurityAction
-                               if (cab.ConstructorArgumentCount == 0)
-                               {
-                                       action = (int)System.Security.Permissions.SecurityAction.LinkDemand;
-                               }
-                               else
-                               {
-                                       action = (int)cab.GetConstructorArgument(0);
-                               }
-                               List<CustomAttributeBuilder> list;
-                               if (!ordered.TryGetValue(action, out list))
-                               {
-                                       list = new List<CustomAttributeBuilder>();
-                                       ordered.Add(action, list);
-                               }
-                               list.Add(cab);
-                       }
-                       foreach (KeyValuePair<int, List<CustomAttributeBuilder>> kv in ordered)
-                       {
-                               DeclSecurityTable.Record rec = new DeclSecurityTable.Record();
-                               rec.Action = (short)kv.Key;
-                               rec.Parent = token;
-                               rec.PermissionSet = WriteDeclSecurityBlob(kv.Value);
-                               this.DeclSecurity.AddRecord(rec);
-                       }
-               }
-
-               private int WriteDeclSecurityBlob(List<CustomAttributeBuilder> list)
-               {
-                       string xml;
-                       if (list.Count == 1 && (xml = list[0].GetLegacyDeclSecurity()) != null)
-                       {
-                               // write .NET 1.1 format
-                               return this.Blobs.Add(ByteBuffer.Wrap(System.Text.Encoding.Unicode.GetBytes(xml)));
-                       }
-                       ByteBuffer namedArgs = new ByteBuffer(100);
-                       ByteBuffer bb = new ByteBuffer(list.Count * 100);
-                       bb.Write((byte)'.');
-                       bb.WriteCompressedUInt(list.Count);
-                       foreach (CustomAttributeBuilder cab in list)
-                       {
-                               bb.Write(cab.Constructor.DeclaringType.AssemblyQualifiedName);
-                               namedArgs.Clear();
-                               cab.WriteNamedArgumentsForDeclSecurity(this, namedArgs);
-                               bb.WriteCompressedUInt(namedArgs.Length);
-                               bb.Write(namedArgs);
-                       }
-                       return this.Blobs.Add(bb);
-               }
-
-               public void DefineManifestResource(string name, Stream stream, ResourceAttributes attribute)
-               {
-                       manifestResources.Align(8);
-                       ManifestResourceTable.Record rec = new ManifestResourceTable.Record();
-                       rec.Offset = manifestResources.Position;
-                       rec.Flags = (int)attribute;
-                       rec.Name = this.Strings.Add(name);
-                       rec.Implementation = 0;
-                       this.ManifestResource.AddRecord(rec);
-                       manifestResources.Write(0);     // placeholder for the length
-                       manifestResources.Write(stream);
-                       int savePosition = manifestResources.Position;
-                       manifestResources.Position = rec.Offset;
-                       manifestResources.Write(savePosition - (manifestResources.Position + 4));
-                       manifestResources.Position = savePosition;
-               }
-
-               public IResourceWriter DefineResource(string name, string description)
-               {
-                       return DefineResource(name, description, ResourceAttributes.Public);
-               }
-
-               public IResourceWriter DefineResource(string name, string description, ResourceAttributes attribute)
-               {
-                       // FXBUG we ignore the description, because there is no such thing
-
-                       if (resourceWriters == null)
-                       {
-                               resourceWriters = new List<ResourceWriterRecord>();
-                       }
-                       MemoryStream mem = new MemoryStream();
-                       ResourceWriter rw = new ResourceWriter(mem);
-                       resourceWriters.Add(new ResourceWriterRecord(name, rw, mem, attribute));
-                       return rw;
-               }
-
-               internal void EmitResources()
-               {
-                       if (resourceWriters != null)
-                       {
-                               foreach (ResourceWriterRecord rwr in resourceWriters)
-                               {
-                                       rwr.Emit(this);
-                               }
-                       }
-               }
-
-               public override Assembly Assembly
-               {
-                       get { return asm; }
-               }
-
-               internal override Type FindType(TypeName name)
-               {
-                       foreach (Type type in types)
-                       {
-                               if (type.__Namespace == name.Namespace && type.__Name == name.Name)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       foreach (Type type in types)
-                       {
-                               if (new TypeName(type.__Namespace, type.__Name).ToLowerInvariant() == lowerCaseName)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               internal override void GetTypesImpl(List<Type> list)
-               {
-                       foreach (Type type in types)
-                       {
-                               if (type != moduleType)
-                               {
-                                       list.Add(type);
-                               }
-                       }
-               }
-
-               public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
-               {
-                       return symbolWriter.DefineDocument(url, language, languageVendor, documentType);
-               }
-
-               public int __GetAssemblyToken(Assembly assembly)
-               {
-                       return ImportAssemblyRef(assembly);
-               }
-
-               public TypeToken GetTypeToken(string name)
-               {
-                       return new TypeToken(GetType(name, true, false).MetadataToken);
-               }
-
-               public TypeToken GetTypeToken(Type type)
-               {
-                       if (type.Module == this && !asm.IsWindowsRuntime)
-                       {
-                               return new TypeToken(type.GetModuleBuilderToken());
-                       }
-                       else
-                       {
-                               return new TypeToken(ImportType(type));
-                       }
-               }
-
-               internal int GetTypeTokenForMemberRef(Type type)
-               {
-                       if (type.__IsMissing)
-                       {
-                               return ImportType(type);
-                       }
-                       else if (type.IsGenericTypeDefinition)
-                       {
-                               int token;
-                               if (!memberRefTypeTokens.TryGetValue(type, out token))
-                               {
-                                       ByteBuffer spec = new ByteBuffer(5);
-                                       Signature.WriteTypeSpec(this, spec, type);
-                                       token = 0x1B000000 | this.TypeSpec.AddRecord(this.Blobs.Add(spec));
-                                       memberRefTypeTokens.Add(type, token);
-                               }
-                               return token;
-                       }
-                       else if (type.IsModulePseudoType)
-                       {
-                               return 0x1A000000 | this.ModuleRef.FindOrAddRecord(this.Strings.Add(type.Module.ScopeName));
-                       }
-                       else
-                       {
-                               return GetTypeToken(type).Token;
-                       }
-               }
-
-               private static bool IsFromGenericTypeDefinition(MemberInfo member)
-               {
-                       Type decl = member.DeclaringType;
-                       return decl != null && !decl.__IsMissing && decl.IsGenericTypeDefinition;
-               }
-
-               public FieldToken GetFieldToken(FieldInfo field)
-               {
-                       // NOTE for some reason, when TypeBuilder.GetFieldToken() is used on a field in a generic type definition,
-                       // a memberref token is returned (confirmed on .NET) unlike for Get(Method|Constructor)Token which always
-                       // simply returns the MethodDef token (if the method is from the same module).
-                       FieldBuilder fb = field as FieldBuilder;
-                       if (fb != null && fb.Module == this && !IsFromGenericTypeDefinition(fb))
-                       {
-                               return new FieldToken(fb.MetadataToken);
-                       }
-                       else
-                       {
-                               return new FieldToken(field.ImportTo(this));
-                       }
-               }
-
-               public MethodToken GetMethodToken(MethodInfo method)
-               {
-                       MethodBuilder mb = method as MethodBuilder;
-                       if (mb != null && mb.ModuleBuilder == this)
-                       {
-                               return new MethodToken(mb.MetadataToken);
-                       }
-                       else
-                       {
-                               return new MethodToken(method.ImportTo(this));
-                       }
-               }
-
-               // new in .NET 4.5
-               public MethodToken GetMethodToken(MethodInfo method, IEnumerable<Type> optionalParameterTypes)
-               {
-                       return __GetMethodToken(method, Util.ToArray(optionalParameterTypes), null);
-               }
-
-               public MethodToken __GetMethodToken(MethodInfo method, Type[] optionalParameterTypes, CustomModifiers[] customModifiers)
-               {
-                       ByteBuffer sig = new ByteBuffer(16);
-                       method.MethodSignature.WriteMethodRefSig(this, sig, optionalParameterTypes, customModifiers);
-                       MemberRefTable.Record record = new MemberRefTable.Record();
-                       if (method.Module == this)
-                       {
-                               record.Class = method.MetadataToken;
-                       }
-                       else
-                       {
-                               record.Class = GetTypeTokenForMemberRef(method.DeclaringType ?? method.Module.GetModuleType());
-                       }
-                       record.Name = Strings.Add(method.Name);
-                       record.Signature = Blobs.Add(sig);
-                       return new MethodToken(0x0A000000 | MemberRef.FindOrAddRecord(record));
-               }
-
-               // when we refer to a method on a generic type definition in the IL stream,
-               // we need to use a MemberRef (even if the method is in the same module)
-               internal MethodToken GetMethodTokenForIL(MethodInfo method)
-               {
-                       if (method.IsGenericMethodDefinition)
-                       {
-                               method = method.MakeGenericMethod(method.GetGenericArguments());
-                       }
-                       if (IsFromGenericTypeDefinition(method))
-                       {
-                               return new MethodToken(method.ImportTo(this));
-                       }
-                       else
-                       {
-                               return GetMethodToken(method);
-                       }
-               }
-
-               internal int GetMethodTokenWinRT(MethodInfo method)
-               {
-                       return asm.IsWindowsRuntime ? method.ImportTo(this) : GetMethodToken(method).Token;
-               }
-
-               public MethodToken GetConstructorToken(ConstructorInfo constructor)
-               {
-                       return GetMethodToken(constructor.GetMethodInfo());
-               }
-
-               // new in .NET 4.5
-               public MethodToken GetConstructorToken(ConstructorInfo constructor, IEnumerable<Type> optionalParameterTypes)
-               {
-                       return GetMethodToken(constructor.GetMethodInfo(), optionalParameterTypes);
-               }
-
-               public MethodToken __GetConstructorToken(ConstructorInfo constructor, Type[] optionalParameterTypes, CustomModifiers[] customModifiers)
-               {
-                       return __GetMethodToken(constructor.GetMethodInfo(), optionalParameterTypes, customModifiers);
-               }
-
-               internal int ImportMethodOrField(Type declaringType, string name, Signature sig)
-               {
-                       int token;
-                       MemberRefKey key = new MemberRefKey(declaringType, name, sig);
-                       if (!importedMemberRefs.TryGetValue(key, out token))
-                       {
-                               MemberRefTable.Record rec = new MemberRefTable.Record();
-                               rec.Class = GetTypeTokenForMemberRef(declaringType);
-                               rec.Name = this.Strings.Add(name);
-                               ByteBuffer bb = new ByteBuffer(16);
-                               sig.WriteSig(this, bb);
-                               rec.Signature = this.Blobs.Add(bb);
-                               token = 0x0A000000 | this.MemberRef.AddRecord(rec);
-                               importedMemberRefs.Add(key, token);
-                       }
-                       return token;
-               }
-
-               internal int ImportMethodSpec(Type declaringType, MethodInfo method, Type[] genericParameters)
-               {
-                       Debug.Assert(method.__IsMissing || method.GetMethodOnTypeDefinition() == method);
-                       int token;
-                       MethodSpecKey key = new MethodSpecKey(declaringType, method.Name, method.MethodSignature, genericParameters);
-                       if (!importedMethodSpecs.TryGetValue(key, out token))
-                       {
-                               MethodSpecTable.Record rec = new MethodSpecTable.Record();
-                               MethodBuilder mb = method as MethodBuilder;
-                               if (mb != null && mb.ModuleBuilder == this && !declaringType.IsGenericType)
-                               {
-                                       rec.Method = mb.MetadataToken;
-                               }
-                               else
-                               {
-                                       // we're calling ImportMethodOrField directly here, because 'method' may be a MethodDef on a generic TypeDef and 'declaringType' the type instance
-                                       // (in order words the method and type have already been decoupled by the caller)
-                                       rec.Method = ImportMethodOrField(declaringType, method.Name, method.MethodSignature);
-                               }
-                               Writer.ByteBuffer spec = new Writer.ByteBuffer(10);
-                               Signature.WriteMethodSpec(this, spec, genericParameters);
-                               rec.Instantiation = this.Blobs.Add(spec);
-                               token = 0x2B000000 | this.MethodSpec.FindOrAddRecord(rec);
-                               importedMethodSpecs.Add(key, token);
-                       }
-                       return token;
-               }
-
-               internal int ImportType(Type type)
-               {
-                       int token;
-                       if (!typeTokens.TryGetValue(type, out token))
-                       {
-                               if (type.HasElementType || type.IsConstructedGenericType || type.__IsFunctionPointer)
-                               {
-                                       ByteBuffer spec = new ByteBuffer(5);
-                                       Signature.WriteTypeSpec(this, spec, type);
-                                       token = 0x1B000000 | this.TypeSpec.AddRecord(this.Blobs.Add(spec));
-                               }
-                               else
-                               {
-                                       TypeRefTable.Record rec = new TypeRefTable.Record();
-                                       if (type.IsNested)
-                                       {
-                                               rec.ResolutionScope = GetTypeToken(type.DeclaringType).Token;
-                                       }
-                                       else if (type.Module == this)
-                                       {
-                                               rec.ResolutionScope = 1;
-                                       }
-                                       else
-                                       {
-                                               rec.ResolutionScope = ImportAssemblyRef(type.Assembly);
-                                       }
-                                       rec.TypeName = this.Strings.Add(type.__Name);
-                                       string ns = type.__Namespace;
-                                       rec.TypeNameSpace = ns == null ? 0 : this.Strings.Add(ns);
-                                       token = 0x01000000 | this.TypeRef.AddRecord(rec);
-                               }
-                               typeTokens.Add(type, token);
-                       }
-                       return token;
-               }
-
-               private int ImportAssemblyRef(Assembly asm)
-               {
-                       int token;
-                       if (!referencedAssemblies.TryGetValue(asm, out token))
-                       {
-                               // We can't write the AssemblyRef record here yet, because the identity of the assembly can still change
-                               // (if it's an AssemblyBuilder).
-                               token = AllocPseudoToken();
-                               referencedAssemblies.Add(asm, token);
-                       }
-                       return token;
-               }
-
-               internal void FillAssemblyRefTable()
-               {
-                       foreach (KeyValuePair<Assembly, int> kv in referencedAssemblies)
-                       {
-                               if (IsPseudoToken(kv.Value))
-                               {
-                                       RegisterTokenFixup(kv.Value, FindOrAddAssemblyRef(kv.Key.GetName(), false));
-                               }
-                       }
-               }
-
-               private int FindOrAddAssemblyRef(AssemblyName name, bool alwaysAdd)
-               {
-                       AssemblyRefTable.Record rec = new AssemblyRefTable.Record();
-                       Version ver = name.Version ?? new Version(0, 0, 0, 0);
-                       rec.MajorVersion = (ushort)ver.Major;
-                       rec.MinorVersion = (ushort)ver.Minor;
-                       rec.BuildNumber = (ushort)ver.Build;
-                       rec.RevisionNumber = (ushort)ver.Revision;
-                       rec.Flags = (int)(name.Flags & ~AssemblyNameFlags.PublicKey);
-                       const AssemblyNameFlags afPA_Specified = (AssemblyNameFlags)0x0080;
-                       const AssemblyNameFlags afPA_Mask = (AssemblyNameFlags)0x0070;
-                       if ((name.RawFlags & afPA_Specified) != 0)
-                       {
-                               rec.Flags |= (int)(name.RawFlags & afPA_Mask);
-                       }
-                       if (name.ContentType == AssemblyContentType.WindowsRuntime)
-                       {
-                               rec.Flags |= 0x0200;
-                       }
-                       byte[] publicKeyOrToken = null;
-                       if (usePublicKeyAssemblyReference)
-                       {
-                               publicKeyOrToken = name.GetPublicKey();
-                       }
-                       if (publicKeyOrToken == null || publicKeyOrToken.Length == 0)
-                       {
-                               publicKeyOrToken = name.GetPublicKeyToken() ?? Empty<byte>.Array;
-                       }
-                       else
-                       {
-                               const int PublicKey = 0x0001;
-                               rec.Flags |= PublicKey;
-                       }
-                       rec.PublicKeyOrToken = this.Blobs.Add(ByteBuffer.Wrap(publicKeyOrToken));
-                       rec.Name = this.Strings.Add(name.Name);
-                       rec.Culture = name.Culture == null ? 0 : this.Strings.Add(name.Culture);
-                       if (name.hash != null)
-                       {
-                               rec.HashValue = this.Blobs.Add(ByteBuffer.Wrap(name.hash));
-                       }
-                       else
-                       {
-                               rec.HashValue = 0;
-                       }
-                       return 0x23000000 | (alwaysAdd ? this.AssemblyRef.AddRecord(rec) : this.AssemblyRef.FindOrAddRecord(rec));
-               }
-
-               internal void WriteSymbolTokenMap()
-               {
-                       for (int i = 0; i < resolvedTokens.Count; i++)
-                       {
-                               int newToken = resolvedTokens[i];
-                               // The symbol API doesn't support remapping arbitrary integers, the types have to be the same,
-                               // so we copy the type from the newToken, because our pseudo tokens don't have a type.
-                               // (see MethodToken.SymbolToken)
-                               int oldToken = (i + 1) | (newToken & ~0xFFFFFF);
-                               SymbolSupport.RemapToken(symbolWriter, oldToken, newToken);
-                       }
-               }
-
-               internal void RegisterTokenFixup(int pseudoToken, int realToken)
-               {
-                       int index = -(pseudoToken + 1);
-                       while (resolvedTokens.Count <= index)
-                       {
-                               resolvedTokens.Add(0);
-                       }
-                       resolvedTokens[index] = realToken;
-               }
-
-               internal static bool IsPseudoToken(int token)
-               {
-                       return token < 0;
-               }
-
-               internal int ResolvePseudoToken(int pseudoToken)
-               {
-                       int index = -(pseudoToken + 1);
-                       return resolvedTokens[index];
-               }
-
-               internal void ApplyUnmanagedExports(ImageFileMachine imageFileMachine)
-               {
-                       if (unmanagedExports.Count != 0)
-                       {
-                               int type;
-                               int size;
-                               if (imageFileMachine == ImageFileMachine.I386)
-                               {
-                                       type = 0x05;
-                                       size = 4;
-                               }
-                               else
-                               {
-                                       type = 0x06;
-                                       size = 8;
-                               }
-                               List<MethodBuilder> methods = new List<MethodBuilder>();
-                               for (int i = 0; i < unmanagedExports.Count; i++)
-                               {
-                                       if (unmanagedExports[i].mb != null)
-                                       {
-                                               methods.Add(unmanagedExports[i].mb);
-                                       }
-                               }
-                               if (methods.Count != 0)
-                               {
-                                       RelativeVirtualAddress rva = __AddVTableFixups(methods.ToArray(), type);
-                                       for (int i = 0; i < unmanagedExports.Count; i++)
-                                       {
-                                               if (unmanagedExports[i].mb != null)
-                                               {
-                                                       UnmanagedExport exp = unmanagedExports[i];
-                                                       exp.rva = new RelativeVirtualAddress(rva.initializedDataOffset + (uint)(methods.IndexOf(unmanagedExports[i].mb) * size));
-                                                       unmanagedExports[i] = exp;
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               internal void FixupMethodBodyTokens()
-               {
-                       int methodToken = 0x06000001;
-                       int fieldToken = 0x04000001;
-                       int parameterToken = 0x08000001;
-                       foreach (TypeBuilder type in types)
-                       {
-                               type.ResolveMethodAndFieldTokens(ref methodToken, ref fieldToken, ref parameterToken);
-                       }
-                       foreach (int offset in tokenFixupOffsets)
-                       {
-                               methodBodies.Position = offset;
-                               int pseudoToken = methodBodies.GetInt32AtCurrentPosition();
-                               methodBodies.Write(ResolvePseudoToken(pseudoToken));
-                       }
-                       foreach (VTableFixups fixup in vtablefixups)
-                       {
-                               for (int i = 0; i < fixup.count; i++)
-                               {
-                                       initializedData.Position = (int)fixup.initializedDataOffset + i * fixup.SlotWidth;
-                                       initializedData.Write(ResolvePseudoToken(initializedData.GetInt32AtCurrentPosition()));
-                               }
-                       }
-               }
-
-               private int GetHeaderLength()
-               {
-                       return
-                               4 + // Signature
-                               2 + // MajorVersion
-                               2 + // MinorVersion
-                               4 + // Reserved
-                               4 + // ImageRuntimeVersion Length
-                               StringToPaddedUTF8Length(asm.ImageRuntimeVersion) +
-                               2 + // Flags
-                               2 + // Streams
-                               4 + // #~ Offset
-                               4 + // #~ Size
-                               4 + // StringToPaddedUTF8Length("#~")
-                               4 + // #Strings Offset
-                               4 + // #Strings Size
-                               12 + // StringToPaddedUTF8Length("#Strings")
-                               4 + // #US Offset
-                               4 + // #US Size
-                               4 + // StringToPaddedUTF8Length("#US")
-                               4 + // #GUID Offset
-                               4 + // #GUID Size
-                               8 + // StringToPaddedUTF8Length("#GUID")
-                               (Blobs.IsEmpty ? 0 :
-                               (
-                               4 + // #Blob Offset
-                               4 + // #Blob Size
-                               8   // StringToPaddedUTF8Length("#Blob")
-                               ));
-               }
-
-               internal int MetadataLength
-               {
-                       get
-                       {
-                               return GetHeaderLength() + (Blobs.IsEmpty ? 0 : Blobs.Length) + Tables.Length + Strings.Length + UserStrings.Length + Guids.Length;
-                       }
-               }
-
-               internal void WriteMetadata(MetadataWriter mw)
-               {
-                       mw.Write(0x424A5342);                   // Signature ("BSJB")
-                       mw.Write((ushort)1);                    // MajorVersion
-                       mw.Write((ushort)1);                    // MinorVersion
-                       mw.Write(0);                                    // Reserved
-                       byte[] version = StringToPaddedUTF8(asm.ImageRuntimeVersion);
-                       mw.Write(version.Length);               // Length
-                       mw.Write(version);
-                       mw.Write((ushort)0);                    // Flags
-                       // #Blob is the only optional heap
-                       if (Blobs.IsEmpty)
-                       {
-                               mw.Write((ushort)4);            // Streams
-                       }
-                       else
-                       {
-                               mw.Write((ushort)5);            // Streams
-                       }
-
-                       int offset = GetHeaderLength();
-
-                       // Streams
-                       mw.Write(offset);                               // Offset
-                       mw.Write(Tables.Length);                // Size
-                       mw.Write(StringToPaddedUTF8("#~"));
-                       offset += Tables.Length;
-
-                       mw.Write(offset);                               // Offset
-                       mw.Write(Strings.Length);               // Size
-                       mw.Write(StringToPaddedUTF8("#Strings"));
-                       offset += Strings.Length;
-
-                       mw.Write(offset);                               // Offset
-                       mw.Write(UserStrings.Length);   // Size
-                       mw.Write(StringToPaddedUTF8("#US"));
-                       offset += UserStrings.Length;
-
-                       mw.Write(offset);                               // Offset
-                       mw.Write(Guids.Length);                 // Size
-                       mw.Write(StringToPaddedUTF8("#GUID"));
-                       offset += Guids.Length;
-
-                       if (!Blobs.IsEmpty)
-                       {
-                               mw.Write(offset);                               // Offset
-                               mw.Write(Blobs.Length);                 // Size
-                               mw.Write(StringToPaddedUTF8("#Blob"));
-                       }
-
-                       Tables.Write(mw);
-                       Strings.Write(mw);
-                       UserStrings.Write(mw);
-                       Guids.Write(mw);
-                       if (!Blobs.IsEmpty)
-                       {
-                               Blobs.Write(mw);
-                       }
-               }
-
-               private static int StringToPaddedUTF8Length(string str)
-               {
-                       return (System.Text.Encoding.UTF8.GetByteCount(str) + 4) & ~3;
-               }
-
-               private static byte[] StringToPaddedUTF8(string str)
-               {
-                       byte[] buf = new byte[(System.Text.Encoding.UTF8.GetByteCount(str) + 4) & ~3];
-                       System.Text.Encoding.UTF8.GetBytes(str, 0, str.Length, buf, 0);
-                       return buf;
-               }
-
-               internal override void ExportTypes(int fileToken, ModuleBuilder manifestModule)
-               {
-                       manifestModule.ExportTypes(types.ToArray(), fileToken);
-               }
-
-               internal void ExportTypes(Type[] types, int fileToken)
-               {
-                       Dictionary<Type, int> declaringTypes = new Dictionary<Type, int>();
-                       foreach (Type type in types)
-                       {
-                               if (!type.IsModulePseudoType && IsVisible(type))
-                               {
-                                       ExportedTypeTable.Record rec = new ExportedTypeTable.Record();
-                                       rec.Flags = (int)type.Attributes;
-                                       // LAMESPEC ECMA says that TypeDefId is a row index, but it should be a token
-                                       rec.TypeDefId = type.MetadataToken;
-                                       rec.TypeName = this.Strings.Add(type.__Name);
-                                       string ns = type.__Namespace;
-                                       rec.TypeNamespace = ns == null ? 0 : this.Strings.Add(ns);
-                                       if (type.IsNested)
-                                       {
-                                               rec.Implementation = declaringTypes[type.DeclaringType];
-                                       }
-                                       else
-                                       {
-                                               rec.Implementation = fileToken;
-                                       }
-                                       int exportTypeToken = 0x27000000 | this.ExportedType.AddRecord(rec);
-                                       declaringTypes.Add(type, exportTypeToken);
-                               }
-                       }
-               }
-
-               private static bool IsVisible(Type type)
-               {
-                       // NOTE this is not the same as Type.IsVisible, because that doesn't take into account family access
-                       return type.IsPublic || ((type.IsNestedFamily || type.IsNestedFamORAssem || type.IsNestedPublic) && IsVisible(type.DeclaringType));
-               }
-
-               internal void AddConstant(int parentToken, object defaultValue)
-               {
-                       ConstantTable.Record rec = new ConstantTable.Record();
-                       rec.Parent = parentToken;
-                       ByteBuffer val = new ByteBuffer(16);
-                       if (defaultValue == null)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_CLASS;
-                               val.Write((int)0);
-                       }
-                       else if (defaultValue is bool)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_BOOLEAN;
-                               val.Write((bool)defaultValue ? (byte)1 : (byte)0);
-                       }
-                       else if (defaultValue is char)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_CHAR;
-                               val.Write((char)defaultValue);
-                       }
-                       else if (defaultValue is sbyte)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_I1;
-                               val.Write((sbyte)defaultValue);
-                       }
-                       else if (defaultValue is byte)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_U1;
-                               val.Write((byte)defaultValue);
-                       }
-                       else if (defaultValue is short)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_I2;
-                               val.Write((short)defaultValue);
-                       }
-                       else if (defaultValue is ushort)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_U2;
-                               val.Write((ushort)defaultValue);
-                       }
-                       else if (defaultValue is int)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_I4;
-                               val.Write((int)defaultValue);
-                       }
-                       else if (defaultValue is uint)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_U4;
-                               val.Write((uint)defaultValue);
-                       }
-                       else if (defaultValue is long)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_I8;
-                               val.Write((long)defaultValue);
-                       }
-                       else if (defaultValue is ulong)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_U8;
-                               val.Write((ulong)defaultValue);
-                       }
-                       else if (defaultValue is float)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_R4;
-                               val.Write((float)defaultValue);
-                       }
-                       else if (defaultValue is double)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_R8;
-                               val.Write((double)defaultValue);
-                       }
-                       else if (defaultValue is string)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_STRING;
-                               foreach (char c in (string)defaultValue)
-                               {
-                                       val.Write(c);
-                               }
-                       }
-                       else if (defaultValue is DateTime)
-                       {
-                               rec.Type = Signature.ELEMENT_TYPE_I8;
-                               val.Write(((DateTime)defaultValue).Ticks);
-                       }
-                       else
-                       {
-                               throw new ArgumentException();
-                       }
-                       rec.Value = this.Blobs.Add(val);
-                       this.Constant.AddRecord(rec);
-               }
-
-               ModuleBuilder ITypeOwner.ModuleBuilder
-               {
-                       get { return this; }
-               }
-
-               internal override Type ResolveType(int metadataToken, IGenericContext context)
-               {
-                       if (metadataToken >> 24 != TypeDefTable.Index)
-                       {
-                               throw new NotImplementedException();
-                       }
-                       return types[(metadataToken & 0xFFFFFF) - 1];
-               }
-
-               public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       if (genericTypeArguments != null || genericMethodArguments != null)
-                       {
-                               throw new NotImplementedException();
-                       }
-                       // this method is inefficient, but since it isn't used we don't care
-                       if ((metadataToken >> 24) == MemberRefTable.Index)
-                       {
-                               foreach (KeyValuePair<MemberRefKey, int> kv in importedMemberRefs)
-                               {
-                                       if (kv.Value == metadataToken)
-                                       {
-                                               return kv.Key.LookupMethod();
-                                       }
-                               }
-                       }
-                       // HACK if we're given a SymbolToken, we need to convert back
-                       if ((metadataToken & 0xFF000000) == 0x06000000)
-                       {
-                               metadataToken = -(metadataToken & 0x00FFFFFF);
-                       }
-                       foreach (Type type in types)
-                       {
-                               MethodBase method = ((TypeBuilder)type).LookupMethod(metadataToken);
-                               if (method != null)
-                               {
-                                       return method;
-                               }
-                       }
-                       return ((TypeBuilder)moduleType).LookupMethod(metadataToken);
-               }
-
-               public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override string ResolveString(int metadataToken)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override string FullyQualifiedName
-               {
-                       get { return Path.GetFullPath(Path.Combine(asm.dir, fileName)); }
-               }
-
-               public override string Name
-               {
-                       get { return fileName; }
-               }
-
-               public override Guid ModuleVersionId
-               {
-                       get { return mvid; }
-               }
-
-               public void __SetModuleVersionId(Guid guid)
-               {
-                       mvid = guid;
-               }
-
-               public override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override string ScopeName
-               {
-                       get { return moduleName; }
-               }
-
-               public ISymbolWriter GetSymWriter()
-               {
-                       return symbolWriter;
-               }
-
-               public void DefineUnmanagedResource(string resourceFileName)
-               {
-                       // This method reads the specified resource file (Win32 .res file) and converts it into the appropriate format and embeds it in the .rsrc section,
-                       // also setting the Resource Directory entry.
-                       unmanagedResources = new ResourceSection();
-                       unmanagedResources.ExtractResources(System.IO.File.ReadAllBytes(resourceFileName));
-               }
-
-               public bool IsTransient()
-               {
-                       return false;
-               }
-
-               public void SetUserEntryPoint(MethodInfo entryPoint)
-               {
-                       int token = entryPoint.MetadataToken;
-                       if (token < 0)
-                       {
-                               token = -token | 0x06000000;
-                       }
-                       if (symbolWriter != null)
-                       {
-                               symbolWriter.SetUserEntryPoint(new SymbolToken(token));
-                       }
-               }
-
-               public StringToken GetStringConstant(string str)
-               {
-                       return new StringToken(this.UserStrings.Add(str) | (0x70 << 24));
-               }
-
-               public SignatureToken GetSignatureToken(SignatureHelper sigHelper)
-               {
-                       return new SignatureToken(this.StandAloneSig.FindOrAddRecord(this.Blobs.Add(sigHelper.GetSignature(this))) | (StandAloneSigTable.Index << 24));
-               }
-
-               public SignatureToken GetSignatureToken(byte[] sigBytes, int sigLength)
-               {
-                       return new SignatureToken(this.StandAloneSig.FindOrAddRecord(this.Blobs.Add(ByteBuffer.Wrap(sigBytes, sigLength))) | (StandAloneSigTable.Index << 24));
-               }
-
-               public MethodInfo GetArrayMethod(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       return new ArrayMethod(this, arrayClass, methodName, callingConvention, returnType, parameterTypes);
-               }
-
-               public MethodToken GetArrayMethodToken(Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       return GetMethodToken(GetArrayMethod(arrayClass, methodName, callingConvention, returnType, parameterTypes));
-               }
-
-               internal override Type GetModuleType()
-               {
-                       return moduleType;
-               }
-
-               internal override IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
-               {
-                       return Blobs.GetBlob(blobIndex);
-               }
-
-               internal int GetSignatureBlobIndex(Signature sig)
-               {
-                       ByteBuffer bb = new ByteBuffer(16);
-                       sig.WriteSig(this, bb);
-                       return this.Blobs.Add(bb);
-               }
-
-               // non-standard API
-               public new long __ImageBase
-               {
-                       get { return imageBaseAddress; }
-                       set { imageBaseAddress = value; }
-               }
-
-               protected override long GetImageBaseImpl()
-               {
-                       return imageBaseAddress;
-               }
-
-               public new long __StackReserve
-               {
-                       get { return stackReserve; }
-                       set { stackReserve = value; }
-               }
-
-               protected override long GetStackReserveImpl()
-               {
-                       return stackReserve;
-               }
-
-               [Obsolete("Use __StackReserve property.")]
-               public void __SetStackReserve(long stackReserve)
-               {
-                       __StackReserve = stackReserve;
-               }
-
-               internal ulong GetStackReserve(ulong defaultValue)
-               {
-                       return stackReserve == -1 ? defaultValue : (ulong)stackReserve;
-               }
-
-               public new int __FileAlignment
-               {
-                       get { return fileAlignment; }
-                       set { fileAlignment = value; }
-               }
-
-               protected override int GetFileAlignmentImpl()
-               {
-                       return fileAlignment;
-               }
-
-               public new DllCharacteristics __DllCharacteristics
-               {
-                       get { return dllCharacteristics; }
-                       set { dllCharacteristics = value; }
-               }
-
-               protected override DllCharacteristics GetDllCharacteristicsImpl()
-               {
-                       return dllCharacteristics;
-               }
-
-               public override int MDStreamVersion
-               {
-                       get { return asm.mdStreamVersion; }
-               }
-
-               private int AddTypeRefByName(int resolutionScope, string ns, string name)
-               {
-                       TypeRefTable.Record rec = new TypeRefTable.Record();
-                       rec.ResolutionScope = resolutionScope;
-                       rec.TypeName = this.Strings.Add(name);
-                       rec.TypeNameSpace = ns == null ? 0 : this.Strings.Add(ns);
-                       return 0x01000000 | this.TypeRef.AddRecord(rec);
-               }
-
-               public void __Save(PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       SaveImpl(null, portableExecutableKind, imageFileMachine);
-               }
-
-               public void __Save(Stream stream, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       if (!stream.CanRead || !stream.CanWrite || !stream.CanSeek || stream.Position != 0)
-                       {
-                               throw new ArgumentException("Stream must support read/write/seek and current position must be zero.", "stream");
-                       }
-                       SaveImpl(stream, portableExecutableKind, imageFileMachine);
-               }
-
-               private void SaveImpl(Stream streamOrNull, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine)
-               {
-                       SetIsSaved();
-                       PopulatePropertyAndEventTables();
-                       IList<CustomAttributeData> attributes = asm.GetCustomAttributesData(null);
-                       if (attributes.Count > 0)
-                       {
-                               int mscorlib = ImportAssemblyRef(universe.Mscorlib);
-                               int[] placeholderTokens = new int[4];
-                               string[] placeholderTypeNames = new string[] { "AssemblyAttributesGoHere", "AssemblyAttributesGoHereM", "AssemblyAttributesGoHereS", "AssemblyAttributesGoHereSM" };
-                               foreach (CustomAttributeData cad in attributes)
-                               {
-                                       int index;
-                                       if (cad.Constructor.DeclaringType.BaseType == universe.System_Security_Permissions_CodeAccessSecurityAttribute)
-                                       {
-                                               if (cad.Constructor.DeclaringType.IsAllowMultipleCustomAttribute)
-                                               {
-                                                       index = 3;
-                                               }
-                                               else
-                                               {
-                                                       index = 2;
-                                               }
-                                       }
-                                       else if (cad.Constructor.DeclaringType.IsAllowMultipleCustomAttribute)
-                                       {
-                                               index = 1;
-                                       }
-                                       else
-                                       {
-                                               index = 0;
-                                       }
-                                       if (placeholderTokens[index] == 0)
-                                       {
-                                               // we manually add a TypeRef without looking it up in mscorlib, because Mono and Silverlight's mscorlib don't have these types
-                                               placeholderTokens[index] = AddTypeRefByName(mscorlib, "System.Runtime.CompilerServices", placeholderTypeNames[index]);
-                                       }
-                                       SetCustomAttribute(placeholderTokens[index], cad.__ToBuilder());
-                               }
-                       }
-                       FillAssemblyRefTable();
-                       EmitResources();
-                       ModuleWriter.WriteModule(null, null, this, PEFileKinds.Dll, portableExecutableKind, imageFileMachine, unmanagedResources, 0, streamOrNull);
-               }
-
-               public void __AddAssemblyReference(AssemblyName assemblyName)
-               {
-                       __AddAssemblyReference(assemblyName, null);
-               }
-
-               public void __AddAssemblyReference(AssemblyName assemblyName, Assembly assembly)
-               {
-                       if (referencedAssemblyNames == null)
-                       {
-                               referencedAssemblyNames = new List<AssemblyName>();
-                       }
-                       referencedAssemblyNames.Add((AssemblyName)assemblyName.Clone());
-                       int token = FindOrAddAssemblyRef(assemblyName, true);
-                       if (assembly != null)
-                       {
-                               referencedAssemblies.Add(assembly, token);
-                       }
-               }
-
-               public override AssemblyName[] __GetReferencedAssemblies()
-               {
-                       List<AssemblyName> list = new List<AssemblyName>();
-                       if (referencedAssemblyNames != null)
-                       {
-                               foreach (AssemblyName name in referencedAssemblyNames)
-                               {
-                                       if (!list.Contains(name))
-                                       {
-                                               list.Add(name);
-                                       }
-                               }
-                       }
-                       foreach (Assembly asm in referencedAssemblies.Keys)
-                       {
-                               AssemblyName name = asm.GetName();
-                               if (!list.Contains(name))
-                               {
-                                       list.Add(name);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public void __AddModuleReference(string module)
-               {
-                       this.ModuleRef.FindOrAddRecord(module == null ? 0 : this.Strings.Add(module));
-               }
-
-               public override string[] __GetReferencedModules()
-               {
-                       string[] arr = new string[this.ModuleRef.RowCount];
-                       for (int i = 0; i < arr.Length; i++)
-                       {
-                               arr[i] = this.Strings.Find(this.ModuleRef.records[i]);
-                       }
-                       return arr;
-               }
-
-               public override Type[] __GetReferencedTypes()
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (KeyValuePair<Type, int> kv in typeTokens)
-                       {
-                               if (kv.Value >> 24 == TypeRefTable.Index)
-                               {
-                                       list.Add(kv.Key);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public override Type[] __GetExportedTypes()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public int __AddModule(int flags, string name, byte[] hash)
-               {
-                       FileTable.Record file = new FileTable.Record();
-                       file.Flags = flags;
-                       file.Name = this.Strings.Add(name);
-                       file.HashValue = this.Blobs.Add(ByteBuffer.Wrap(hash));
-                       return 0x26000000 + this.File.AddRecord(file);
-               }
-
-               public int __AddManifestResource(int offset, ResourceAttributes flags, string name, int implementation)
-               {
-                       ManifestResourceTable.Record res = new ManifestResourceTable.Record();
-                       res.Offset = offset;
-                       res.Flags = (int)flags;
-                       res.Name = this.Strings.Add(name);
-                       res.Implementation = implementation;
-                       return 0x28000000 + this.ManifestResource.AddRecord(res);
-               }
-
-               public void __SetCustomAttributeFor(int token, CustomAttributeBuilder customBuilder)
-               {
-                       SetCustomAttribute(token, customBuilder);
-               }
-
-               public RelativeVirtualAddress __AddVTableFixups(MethodBuilder[] methods, int type)
-               {
-                       initializedData.Align(8);
-                       VTableFixups fixups;
-                       fixups.initializedDataOffset = (uint)initializedData.Position;
-                       fixups.count = (ushort)methods.Length;
-                       fixups.type = (ushort)type;
-                       foreach (MethodBuilder mb in methods)
-                       {
-                               initializedData.Write(mb.MetadataToken);
-                               if (fixups.SlotWidth == 8)
-                               {
-                                       initializedData.Write(0);
-                               }
-                       }
-                       vtablefixups.Add(fixups);
-                       return new RelativeVirtualAddress(fixups.initializedDataOffset);
-               }
-
-               public void __AddUnmanagedExportStub(string name, int ordinal, RelativeVirtualAddress rva)
-               {
-                       AddUnmanagedExport(name, ordinal, null, rva);
-               }
-
-               internal void AddUnmanagedExport(string name, int ordinal, MethodBuilder methodBuilder, RelativeVirtualAddress rva)
-               {
-                       UnmanagedExport export;
-                       export.name = name;
-                       export.ordinal = ordinal;
-                       export.mb = methodBuilder;
-                       export.rva = rva;
-                       unmanagedExports.Add(export);
-               }
-
-               internal void SetInterfaceImplementationCustomAttribute(TypeBuilder typeBuilder, Type interfaceType, CustomAttributeBuilder cab)
-               {
-                       // NOTE since interfaceimpls are extremely common and custom attributes on them are extremely rare,
-                       // we store (and resolve) the custom attributes in such away as to avoid impacting the common case performance
-                       if (interfaceImplCustomAttributes == null)
-                       {
-                               interfaceImplCustomAttributes = new List<InterfaceImplCustomAttribute>();
-                       }
-                       InterfaceImplCustomAttribute rec;
-                       rec.type = typeBuilder.MetadataToken;
-                       int token = GetTypeToken(interfaceType).Token;
-                       switch (token >> 24)
-                       {
-                               case TypeDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 0;
-                                       break;
-                               case TypeRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 1;
-                                       break;
-                               case TypeSpecTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 2;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       rec.interfaceType = token;
-                       rec.pseudoToken = AllocPseudoToken();
-                       interfaceImplCustomAttributes.Add(rec);
-                       SetCustomAttribute(rec.pseudoToken, cab);
-               }
-
-               internal void ResolveInterfaceImplPseudoTokens()
-               {
-                       if (interfaceImplCustomAttributes != null)
-                       {
-                               foreach (InterfaceImplCustomAttribute rec in interfaceImplCustomAttributes)
-                               {
-                                       for (int i = 0; i < InterfaceImpl.records.Length; i++)
-                                       {
-                                               if (InterfaceImpl.records[i].Class == rec.type && InterfaceImpl.records[i].Interface == rec.interfaceType)
-                                               {
-                                                       RegisterTokenFixup(rec.pseudoToken, (InterfaceImplTable.Index << 24) | (i + 1));
-                                                       break;
-                                               }
-                                       }
-                               }
-                       }
-               }
-
-               internal void FixupPseudoToken(ref int token)
-               {
-                       if (IsPseudoToken(token))
-                       {
-                               token = ResolvePseudoToken(token);
-                       }
-               }
-
-               internal void SetIsSaved()
-               {
-                       if (saved)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       saved = true;
-               }
-
-               internal bool IsSaved
-               {
-                       get { return saved; }
-               }
-
-               internal override string GetString(int index)
-               {
-                       return this.Strings.Find(index);
-               }
-       }
-
-       struct UnmanagedExport
-       {
-               internal string name;
-               internal int ordinal;
-               internal RelativeVirtualAddress rva;
-               internal MethodBuilder mb;
-       }
-
-       public struct RelativeVirtualAddress
-       {
-               internal readonly uint initializedDataOffset;
-
-               internal RelativeVirtualAddress(uint initializedDataOffset)
-               {
-                       this.initializedDataOffset = initializedDataOffset;
-               }
-
-               public static RelativeVirtualAddress operator +(RelativeVirtualAddress rva, int offset)
-               {
-                       return new RelativeVirtualAddress(rva.initializedDataOffset + (uint)offset);
-               }
-       }
-
-       class ArrayMethod : MethodInfo
-       {
-               private readonly Module module;
-               private readonly Type arrayClass;
-               private readonly string methodName;
-               private readonly CallingConventions callingConvention;
-               private readonly Type returnType;
-               protected readonly Type[] parameterTypes;
-               private MethodSignature methodSignature;
-
-               internal ArrayMethod(Module module, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       this.module = module;
-                       this.arrayClass = arrayClass;
-                       this.methodName = methodName;
-                       this.callingConvention = callingConvention;
-                       this.returnType = returnType ?? module.universe.System_Void;
-                       this.parameterTypes = Util.Copy(parameterTypes);
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public override int __MethodRVA
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       throw new NotSupportedException();
-               }
-
-               internal override int ImportTo(ModuleBuilder module)
-               {
-                       return module.ImportMethodOrField(arrayClass, methodName, MethodSignature);
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return callingConvention; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return arrayClass; }
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get
-                       {
-                               if (methodSignature == null)
-                               {
-                                       methodSignature = MethodSignature.MakeFromBuilder(returnType, parameterTypes, new PackedCustomModifiers(), callingConvention, 0);
-                               }
-                               return methodSignature;
-                       }
-               }
-
-               public override Module Module
-               {
-                       // FXBUG like .NET, we return the module that GetArrayMethod was called on, not the module associated with the array type
-                       get { return module; }
-               }
-
-               public override string Name
-               {
-                       get { return methodName; }
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return parameterTypes.Length; }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       // FXBUG like .NET, we throw NotImplementedException
-                       get { throw new NotImplementedException(); }
-               }
-
-               public override Type ReturnType
-               {
-                       get { return returnType; }
-               }
-
-               internal override bool HasThis
-               {
-                       get { return (callingConvention & (CallingConventions.HasThis | CallingConventions.ExplicitThis)) == CallingConventions.HasThis; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return arrayClass.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/OpCode.cs b/mcs/class/IKVM.Reflection/Emit/OpCode.cs
deleted file mode 100644 (file)
index 1d75a0a..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
-  Copyright (C) 2008, 2010 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Diagnostics;
-
-namespace IKVM.Reflection.Emit
-{
-       public struct OpCode
-       {
-               private const int ValueCount = 1024;
-               private const int OperandTypeCount = 19;
-               private const int FlowControlCount = 9;
-               private const int StackDiffCount = 5;
-               private const int OpCodeTypeCount = 6;
-               private const int StackBehaviourPopCount = 20;
-               private const int StackBehaviourPushCount = 9;
-               private static readonly StackBehaviour[] pop = {
-                       StackBehaviour.Pop0,
-                       StackBehaviour.Pop1,
-                       StackBehaviour.Pop1_pop1,
-                       StackBehaviour.Popi,
-                       StackBehaviour.Popi_pop1,
-                       StackBehaviour.Popi_popi,
-                       StackBehaviour.Popi_popi8,
-                       StackBehaviour.Popi_popi_popi,
-                       StackBehaviour.Popi_popr4,
-                       StackBehaviour.Popi_popr8,
-                       StackBehaviour.Popref,
-                       StackBehaviour.Popref_pop1,
-                       StackBehaviour.Popref_popi,
-                       StackBehaviour.Popref_popi_popi,
-                       StackBehaviour.Popref_popi_popi8,
-                       StackBehaviour.Popref_popi_popr4,
-                       StackBehaviour.Popref_popi_popr8,
-                       StackBehaviour.Popref_popi_popref,
-                       StackBehaviour.Varpop,
-                       StackBehaviour.Popref_popi_pop1
-               };
-               private static readonly StackBehaviour[] push = {
-                       StackBehaviour.Push0,
-                       StackBehaviour.Push1,
-                       StackBehaviour.Push1_push1,
-                       StackBehaviour.Pushi,
-                       StackBehaviour.Pushi8,
-                       StackBehaviour.Pushr4,
-                       StackBehaviour.Pushr8,
-                       StackBehaviour.Pushref,
-                       StackBehaviour.Varpush
-               };
-               private readonly int value;
-
-               internal OpCode(int value)
-               {
-                       this.value = value;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return this == obj as OpCode?;
-               }
-
-               public override int GetHashCode()
-               {
-                       return value;
-               }
-
-               public bool Equals(OpCode other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(OpCode a, OpCode b)
-               {
-                       return a.value == b.value;
-               }
-
-               public static bool operator !=(OpCode a, OpCode b)
-               {
-                       return !(a == b);
-               }
-
-               public short Value
-               {
-                       get { return (short)(value >> 22); }
-               }
-
-               public int Size
-               {
-                       get { return value < 0 ? 2 : 1; }
-               }
-
-#if !GENERATOR
-               public string Name
-               {
-                       get { return OpCodes.GetName(this.Value); }
-               }
-#endif
-
-               public OperandType OperandType
-               {
-                       get { return (OperandType)((value & 0x3FFFFF) % OperandTypeCount); }
-               }
-
-               public FlowControl FlowControl
-               {
-                       get { return (FlowControl)(((value & 0x3FFFFF) / OperandTypeCount) % FlowControlCount); }
-               }
-
-               internal int StackDiff
-               {
-                       get { return ((((value & 0x3FFFFF) / (OperandTypeCount * FlowControlCount)) % StackDiffCount) - 3); }
-               }
-
-               public OpCodeType OpCodeType
-               {
-                       get { return (OpCodeType)(((value & 0x3FFFFF) / (OperandTypeCount * FlowControlCount * StackDiffCount)) % OpCodeTypeCount); }
-               }
-
-               public StackBehaviour StackBehaviourPop
-               {
-                       get { return pop[(((value & 0x3FFFFF) / (OperandTypeCount * FlowControlCount * StackDiffCount * OpCodeTypeCount)) % StackBehaviourPopCount)]; }
-               }
-
-               public StackBehaviour StackBehaviourPush
-               {
-                       get { return push[(((value & 0x3FFFFF) / (OperandTypeCount * FlowControlCount * StackDiffCount * OpCodeTypeCount * StackBehaviourPopCount)) % StackBehaviourPushCount)]; }
-               }
-
-#if GENERATOR
-               static void Main(string[] args)
-               {
-                       Debug.Assert(pop.Length == StackBehaviourPopCount);
-                       Debug.Assert(push.Length == StackBehaviourPushCount);
-                       CheckEnumRange(typeof(FlowControl), FlowControlCount);
-                       CheckEnumRange(typeof(OpCodeType), OpCodeTypeCount);
-                       CheckEnumRange(typeof(OperandType), OperandTypeCount);
-                       foreach (var field in typeof(System.Reflection.Emit.OpCodes).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
-                       {
-                               System.Reflection.Emit.OpCode opc1 = (System.Reflection.Emit.OpCode)field.GetValue(null);
-                               IKVM.Reflection.Emit.OpCode opc2 = new IKVM.Reflection.Emit.OpCode(Pack(opc1));
-                               Debug.Assert(opc1.Value == opc2.Value);
-                               Debug.Assert(opc1.Size == opc2.Size);
-                               Debug.Assert((int)opc1.FlowControl == (int)opc2.FlowControl);
-                               Debug.Assert((int)opc1.OpCodeType == (int)opc2.OpCodeType);
-                               Debug.Assert((int)opc1.OperandType == (int)opc2.OperandType);
-                               Debug.Assert((int)opc1.StackBehaviourPop == (int)opc2.StackBehaviourPop);
-                               Debug.Assert((int)opc1.StackBehaviourPush == (int)opc2.StackBehaviourPush);
-                               Console.WriteLine("\t\tpublic static readonly OpCode {0} = new OpCode({1});", field.Name, Pack(opc1));
-                       }
-                       Console.WriteLine();
-                       Console.WriteLine("\t\tinternal static string GetName(int value)");
-                       Console.WriteLine("\t\t{");
-                       Console.WriteLine("\t\t\tswitch (value)");
-                       Console.WriteLine("\t\t\t{");
-                       foreach (var field in typeof(System.Reflection.Emit.OpCodes).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
-                       {
-                               System.Reflection.Emit.OpCode opc1 = (System.Reflection.Emit.OpCode)field.GetValue(null);
-                               Console.WriteLine("\t\t\t\tcase {0}:", opc1.Value);
-                               Console.WriteLine("\t\t\t\t\treturn \"{0}\";", opc1.Name);
-                       }
-                       Console.WriteLine("\t\t\t}");
-                       Console.WriteLine("\t\t\tthrow new ArgumentOutOfRangeException();");
-                       Console.WriteLine("\t\t}");
-                       Console.WriteLine();
-                       Console.WriteLine("\t\tpublic static bool TakesSingleByteArgument(OpCode inst)");
-                       Console.WriteLine("\t\t{");
-                       Console.WriteLine("\t\t\tswitch (inst.Value)");
-                       Console.WriteLine("\t\t\t{");
-                       foreach (var field in typeof(System.Reflection.Emit.OpCodes).GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
-                       {
-                               System.Reflection.Emit.OpCode opc1 = (System.Reflection.Emit.OpCode)field.GetValue(null);
-                               if (System.Reflection.Emit.OpCodes.TakesSingleByteArgument(opc1))
-                               {
-                                       Console.WriteLine("\t\t\t\tcase {0}:", opc1.Value);
-                               }
-                       }
-                       Console.WriteLine("\t\t\t\t\treturn true;");
-                       Console.WriteLine("\t\t\t\tdefault:");
-                       Console.WriteLine("\t\t\t\t\treturn false;");
-                       Console.WriteLine("\t\t\t}");
-                       Console.WriteLine("\t\t}");
-               }
-
-               private static void CheckEnumRange(System.Type type, int count)
-               {
-                       foreach (var field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static))
-                       {
-                               int value = (int)field.GetValue(null);
-                               Debug.Assert(value >= 0 && value < count);
-                       }
-               }
-
-               static int Pack(System.Reflection.Emit.OpCode opcode)
-               {
-                       int value = 0;
-                       value *= StackBehaviourPushCount;
-                       value += Map(push, opcode.StackBehaviourPush);
-                       value *= StackBehaviourPopCount;
-                       value += Map(pop, opcode.StackBehaviourPop);
-                       value *= OpCodeTypeCount;
-                       value += (int)opcode.OpCodeType;
-                       value *= StackDiffCount;
-                       value += 3 + GetStackDiff(opcode.StackBehaviourPush) + GetStackDiff(opcode.StackBehaviourPop);
-                       value *= FlowControlCount;
-                       value += (int)opcode.FlowControl;
-                       value *= OperandTypeCount;
-                       value += (int)opcode.OperandType;
-                       return (opcode.Value << 22) | value;
-               }
-
-               private static int Map(StackBehaviour[] array, System.Reflection.Emit.StackBehaviour stackBehaviour)
-               {
-                       for (int i = 0; i < array.Length; i++)
-                       {
-                               if ((int)array[i] == (int)stackBehaviour)
-                               {
-                                       return i;
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               static int GetStackDiff(System.Reflection.Emit.StackBehaviour sb)
-               {
-                       switch (sb)
-                       {
-                               case System.Reflection.Emit.StackBehaviour.Pop0:
-                               case System.Reflection.Emit.StackBehaviour.Push0:
-                               case System.Reflection.Emit.StackBehaviour.Varpop:
-                               case System.Reflection.Emit.StackBehaviour.Varpush:
-                                       return 0;
-                               case System.Reflection.Emit.StackBehaviour.Pop1:
-                               case System.Reflection.Emit.StackBehaviour.Popi:
-                               case System.Reflection.Emit.StackBehaviour.Popref:
-                                       return -1;
-                               case System.Reflection.Emit.StackBehaviour.Pop1_pop1:
-                               case System.Reflection.Emit.StackBehaviour.Popi_pop1:
-                               case System.Reflection.Emit.StackBehaviour.Popi_popi:
-                               case System.Reflection.Emit.StackBehaviour.Popi_popi8:
-                               case System.Reflection.Emit.StackBehaviour.Popi_popr4:
-                               case System.Reflection.Emit.StackBehaviour.Popi_popr8:
-                               case System.Reflection.Emit.StackBehaviour.Popref_pop1:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi:
-                                       return -2;
-                               case System.Reflection.Emit.StackBehaviour.Popi_popi_popi:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_pop1:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_popi:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_popi8:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_popr4:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_popr8:
-                               case System.Reflection.Emit.StackBehaviour.Popref_popi_popref:
-                                       return -3;
-                               case System.Reflection.Emit.StackBehaviour.Push1:
-                               case System.Reflection.Emit.StackBehaviour.Pushi:
-                               case System.Reflection.Emit.StackBehaviour.Pushi8:
-                               case System.Reflection.Emit.StackBehaviour.Pushr4:
-                               case System.Reflection.Emit.StackBehaviour.Pushr8:
-                               case System.Reflection.Emit.StackBehaviour.Pushref:
-                                       return 1;
-                               case System.Reflection.Emit.StackBehaviour.Push1_push1:
-                                       return 2;
-                       }
-                       throw new InvalidOperationException();
-               }
-#endif // GENERATOR
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/OpCodes.cs b/mcs/class/IKVM.Reflection/Emit/OpCodes.cs
deleted file mode 100644 (file)
index bb2ddd8..0000000
+++ /dev/null
@@ -1,749 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class OpCodes
-       {
-               public static readonly OpCode Nop = new OpCode(4888);
-               public static readonly OpCode Break = new OpCode(4199116);
-               public static readonly OpCode Ldarg_0 = new OpCode(8492847);
-               public static readonly OpCode Ldarg_1 = new OpCode(12687151);
-               public static readonly OpCode Ldarg_2 = new OpCode(16881455);
-               public static readonly OpCode Ldarg_3 = new OpCode(21075759);
-               public static readonly OpCode Ldloc_0 = new OpCode(25270063);
-               public static readonly OpCode Ldloc_1 = new OpCode(29464367);
-               public static readonly OpCode Ldloc_2 = new OpCode(33658671);
-               public static readonly OpCode Ldloc_3 = new OpCode(37852975);
-               public static readonly OpCode Stloc_0 = new OpCode(41949467);
-               public static readonly OpCode Stloc_1 = new OpCode(46143771);
-               public static readonly OpCode Stloc_2 = new OpCode(50338075);
-               public static readonly OpCode Stloc_3 = new OpCode(54532379);
-               public static readonly OpCode Ldarg_S = new OpCode(58824508);
-               public static readonly OpCode Ldarga_S = new OpCode(63224012);
-               public static readonly OpCode Starg_S = new OpCode(67115304);
-               public static readonly OpCode Ldloc_S = new OpCode(71407420);
-               public static readonly OpCode Ldloca_S = new OpCode(75806924);
-               public static readonly OpCode Stloc_S = new OpCode(79698216);
-               public static readonly OpCode Ldnull = new OpCode(84609339);
-               public static readonly OpCode Ldc_I4_M1 = new OpCode(88389823);
-               public static readonly OpCode Ldc_I4_0 = new OpCode(92584127);
-               public static readonly OpCode Ldc_I4_1 = new OpCode(96778431);
-               public static readonly OpCode Ldc_I4_2 = new OpCode(100972735);
-               public static readonly OpCode Ldc_I4_3 = new OpCode(105167039);
-               public static readonly OpCode Ldc_I4_4 = new OpCode(109361343);
-               public static readonly OpCode Ldc_I4_5 = new OpCode(113555647);
-               public static readonly OpCode Ldc_I4_6 = new OpCode(117749951);
-               public static readonly OpCode Ldc_I4_7 = new OpCode(121944255);
-               public static readonly OpCode Ldc_I4_8 = new OpCode(126138559);
-               public static readonly OpCode Ldc_I4_S = new OpCode(130332874);
-               public static readonly OpCode Ldc_I4 = new OpCode(134530584);
-               public static readonly OpCode Ldc_I8 = new OpCode(138827489);
-               public static readonly OpCode Ldc_R4 = new OpCode(143124407);
-               public static readonly OpCode Ldc_R8 = new OpCode(147421301);
-               public static readonly OpCode Dup = new OpCode(155404637);
-               public static readonly OpCode Pop = new OpCode(159393399);
-               public static readonly OpCode Jmp = new OpCode(163582686);
-               public static readonly OpCode Call = new OpCode(168690130);
-               public static readonly OpCode Calli = new OpCode(172884439);
-               public static readonly OpCode Ret = new OpCode(176258034);
-               public static readonly OpCode Br_S = new OpCode(180356455);
-               public static readonly OpCode Brfalse_S = new OpCode(184566035);
-               public static readonly OpCode Brtrue_S = new OpCode(188760339);
-               public static readonly OpCode Beq_S = new OpCode(192949342);
-               public static readonly OpCode Bge_S = new OpCode(197143646);
-               public static readonly OpCode Bgt_S = new OpCode(201337950);
-               public static readonly OpCode Ble_S = new OpCode(205532254);
-               public static readonly OpCode Blt_S = new OpCode(209726558);
-               public static readonly OpCode Bne_Un_S = new OpCode(213920862);
-               public static readonly OpCode Bge_Un_S = new OpCode(218115166);
-               public static readonly OpCode Bgt_Un_S = new OpCode(222309470);
-               public static readonly OpCode Ble_Un_S = new OpCode(226503774);
-               public static readonly OpCode Blt_Un_S = new OpCode(230698078);
-               public static readonly OpCode Br = new OpCode(234885812);
-               public static readonly OpCode Brfalse = new OpCode(239095392);
-               public static readonly OpCode Brtrue = new OpCode(243289696);
-               public static readonly OpCode Beq = new OpCode(247475279);
-               public static readonly OpCode Bge = new OpCode(251669583);
-               public static readonly OpCode Bgt = new OpCode(255863887);
-               public static readonly OpCode Ble = new OpCode(260058191);
-               public static readonly OpCode Blt = new OpCode(264252495);
-               public static readonly OpCode Bne_Un = new OpCode(268446799);
-               public static readonly OpCode Bge_Un = new OpCode(272641103);
-               public static readonly OpCode Bgt_Un = new OpCode(276835407);
-               public static readonly OpCode Ble_Un = new OpCode(281029711);
-               public static readonly OpCode Blt_Un = new OpCode(285224015);
-               public static readonly OpCode Switch = new OpCode(289427051);
-               public static readonly OpCode Ldind_I1 = new OpCode(293929358);
-               public static readonly OpCode Ldind_U1 = new OpCode(298123662);
-               public static readonly OpCode Ldind_I2 = new OpCode(302317966);
-               public static readonly OpCode Ldind_U2 = new OpCode(306512270);
-               public static readonly OpCode Ldind_I4 = new OpCode(310706574);
-               public static readonly OpCode Ldind_U4 = new OpCode(314900878);
-               public static readonly OpCode Ldind_I8 = new OpCode(319197782);
-               public static readonly OpCode Ldind_I = new OpCode(323289486);
-               public static readonly OpCode Ldind_R4 = new OpCode(327688990);
-               public static readonly OpCode Ldind_R8 = new OpCode(331985894);
-               public static readonly OpCode Ldind_Ref = new OpCode(336282798);
-               public static readonly OpCode Stind_Ref = new OpCode(339768820);
-               public static readonly OpCode Stind_I1 = new OpCode(343963124);
-               public static readonly OpCode Stind_I2 = new OpCode(348157428);
-               public static readonly OpCode Stind_I4 = new OpCode(352351732);
-               public static readonly OpCode Stind_I8 = new OpCode(356551166);
-               public static readonly OpCode Stind_R4 = new OpCode(360755730);
-               public static readonly OpCode Stind_R8 = new OpCode(364955164);
-               public static readonly OpCode Add = new OpCode(369216329);
-               public static readonly OpCode Sub = new OpCode(373410633);
-               public static readonly OpCode Mul = new OpCode(377604937);
-               public static readonly OpCode Div = new OpCode(381799241);
-               public static readonly OpCode Div_Un = new OpCode(385993545);
-               public static readonly OpCode Rem = new OpCode(390187849);
-               public static readonly OpCode Rem_Un = new OpCode(394382153);
-               public static readonly OpCode And = new OpCode(398576457);
-               public static readonly OpCode Or = new OpCode(402770761);
-               public static readonly OpCode Xor = new OpCode(406965065);
-               public static readonly OpCode Shl = new OpCode(411159369);
-               public static readonly OpCode Shr = new OpCode(415353673);
-               public static readonly OpCode Shr_Un = new OpCode(419547977);
-               public static readonly OpCode Neg = new OpCode(423737322);
-               public static readonly OpCode Not = new OpCode(427931626);
-               public static readonly OpCode Conv_I1 = new OpCode(432331130);
-               public static readonly OpCode Conv_I2 = new OpCode(436525434);
-               public static readonly OpCode Conv_I4 = new OpCode(440719738);
-               public static readonly OpCode Conv_I8 = new OpCode(445016642);
-               public static readonly OpCode Conv_R4 = new OpCode(449313546);
-               public static readonly OpCode Conv_R8 = new OpCode(453610450);
-               public static readonly OpCode Conv_U4 = new OpCode(457496954);
-               public static readonly OpCode Conv_U8 = new OpCode(461793858);
-               public static readonly OpCode Callvirt = new OpCode(466484004);
-               public static readonly OpCode Cpobj = new OpCode(469790542);
-               public static readonly OpCode Ldobj = new OpCode(474077528);
-               public static readonly OpCode Ldstr = new OpCode(478872210);
-               public static readonly OpCode Newobj = new OpCode(483158791);
-               public static readonly OpCode Castclass = new OpCode(487311950);
-               public static readonly OpCode Isinst = new OpCode(491095854);
-               public static readonly OpCode Conv_R_Un = new OpCode(495553490);
-               public static readonly OpCode Unbox = new OpCode(507874780);
-               public static readonly OpCode Throw = new OpCode(511759452);
-               public static readonly OpCode Ldfld = new OpCode(516056466);
-               public static readonly OpCode Ldflda = new OpCode(520455970);
-               public static readonly OpCode Stfld = new OpCode(524347262);
-               public static readonly OpCode Ldsfld = new OpCode(528588249);
-               public static readonly OpCode Ldsflda = new OpCode(532987753);
-               public static readonly OpCode Stsfld = new OpCode(536879045);
-               public static readonly OpCode Stobj = new OpCode(541090290);
-               public static readonly OpCode Conv_Ovf_I1_Un = new OpCode(545577338);
-               public static readonly OpCode Conv_Ovf_I2_Un = new OpCode(549771642);
-               public static readonly OpCode Conv_Ovf_I4_Un = new OpCode(553965946);
-               public static readonly OpCode Conv_Ovf_I8_Un = new OpCode(558262850);
-               public static readonly OpCode Conv_Ovf_U1_Un = new OpCode(562354554);
-               public static readonly OpCode Conv_Ovf_U2_Un = new OpCode(566548858);
-               public static readonly OpCode Conv_Ovf_U4_Un = new OpCode(570743162);
-               public static readonly OpCode Conv_Ovf_U8_Un = new OpCode(575040066);
-               public static readonly OpCode Conv_Ovf_I_Un = new OpCode(579131770);
-               public static readonly OpCode Conv_Ovf_U_Un = new OpCode(583326074);
-               public static readonly OpCode Box = new OpCode(587930786);
-               public static readonly OpCode Newarr = new OpCode(592133640);
-               public static readonly OpCode Ldlen = new OpCode(595953446);
-               public static readonly OpCode Ldelema = new OpCode(600157847);
-               public static readonly OpCode Ldelem_I1 = new OpCode(604352143);
-               public static readonly OpCode Ldelem_U1 = new OpCode(608546447);
-               public static readonly OpCode Ldelem_I2 = new OpCode(612740751);
-               public static readonly OpCode Ldelem_U2 = new OpCode(616935055);
-               public static readonly OpCode Ldelem_I4 = new OpCode(621129359);
-               public static readonly OpCode Ldelem_U4 = new OpCode(625323663);
-               public static readonly OpCode Ldelem_I8 = new OpCode(629620567);
-               public static readonly OpCode Ldelem_I = new OpCode(633712271);
-               public static readonly OpCode Ldelem_R4 = new OpCode(638111775);
-               public static readonly OpCode Ldelem_R8 = new OpCode(642408679);
-               public static readonly OpCode Ldelem_Ref = new OpCode(646705583);
-               public static readonly OpCode Stelem_I = new OpCode(650186475);
-               public static readonly OpCode Stelem_I1 = new OpCode(654380779);
-               public static readonly OpCode Stelem_I2 = new OpCode(658575083);
-               public static readonly OpCode Stelem_I4 = new OpCode(662769387);
-               public static readonly OpCode Stelem_I8 = new OpCode(666968821);
-               public static readonly OpCode Stelem_R4 = new OpCode(671168255);
-               public static readonly OpCode Stelem_R8 = new OpCode(675367689);
-               public static readonly OpCode Stelem_Ref = new OpCode(679567123);
-               public static readonly OpCode Ldelem = new OpCode(683838727);
-               public static readonly OpCode Stelem = new OpCode(687965999);
-               public static readonly OpCode Unbox_Any = new OpCode(692217246);
-               public static readonly OpCode Conv_Ovf_I1 = new OpCode(751098234);
-               public static readonly OpCode Conv_Ovf_U1 = new OpCode(755292538);
-               public static readonly OpCode Conv_Ovf_I2 = new OpCode(759486842);
-               public static readonly OpCode Conv_Ovf_U2 = new OpCode(763681146);
-               public static readonly OpCode Conv_Ovf_I4 = new OpCode(767875450);
-               public static readonly OpCode Conv_Ovf_U4 = new OpCode(772069754);
-               public static readonly OpCode Conv_Ovf_I8 = new OpCode(776366658);
-               public static readonly OpCode Conv_Ovf_U8 = new OpCode(780560962);
-               public static readonly OpCode Refanyval = new OpCode(814012802);
-               public static readonly OpCode Ckfinite = new OpCode(818514898);
-               public static readonly OpCode Mkrefany = new OpCode(830595078);
-               public static readonly OpCode Ldtoken = new OpCode(872728098);
-               public static readonly OpCode Conv_U2 = new OpCode(876927354);
-               public static readonly OpCode Conv_U1 = new OpCode(881121658);
-               public static readonly OpCode Conv_I = new OpCode(885315962);
-               public static readonly OpCode Conv_Ovf_I = new OpCode(889510266);
-               public static readonly OpCode Conv_Ovf_U = new OpCode(893704570);
-               public static readonly OpCode Add_Ovf = new OpCode(897698633);
-               public static readonly OpCode Add_Ovf_Un = new OpCode(901892937);
-               public static readonly OpCode Mul_Ovf = new OpCode(906087241);
-               public static readonly OpCode Mul_Ovf_Un = new OpCode(910281545);
-               public static readonly OpCode Sub_Ovf = new OpCode(914475849);
-               public static readonly OpCode Sub_Ovf_Un = new OpCode(918670153);
-               public static readonly OpCode Endfinally = new OpCode(922751806);
-               public static readonly OpCode Leave = new OpCode(926945972);
-               public static readonly OpCode Leave_S = new OpCode(931140291);
-               public static readonly OpCode Stind_I = new OpCode(935359988);
-               public static readonly OpCode Conv_U = new OpCode(939841914);
-               public static readonly OpCode Prefix7 = new OpCode(1040189696);
-               public static readonly OpCode Prefix6 = new OpCode(1044384000);
-               public static readonly OpCode Prefix5 = new OpCode(1048578304);
-               public static readonly OpCode Prefix4 = new OpCode(1052772608);
-               public static readonly OpCode Prefix3 = new OpCode(1056966912);
-               public static readonly OpCode Prefix2 = new OpCode(1061161216);
-               public static readonly OpCode Prefix1 = new OpCode(1065355520);
-               public static readonly OpCode Prefixref = new OpCode(1069549824);
-               public static readonly OpCode Arglist = new OpCode(-2147170789);
-               public static readonly OpCode Ceq = new OpCode(-2142966567);
-               public static readonly OpCode Cgt = new OpCode(-2138772263);
-               public static readonly OpCode Cgt_Un = new OpCode(-2134577959);
-               public static readonly OpCode Clt = new OpCode(-2130383655);
-               public static readonly OpCode Clt_Un = new OpCode(-2126189351);
-               public static readonly OpCode Ldftn = new OpCode(-2122004966);
-               public static readonly OpCode Ldvirtftn = new OpCode(-2117759533);
-               public static readonly OpCode Ldarg = new OpCode(-2109627244);
-               public static readonly OpCode Ldarga = new OpCode(-2105227740);
-               public static readonly OpCode Starg = new OpCode(-2101336448);
-               public static readonly OpCode Ldloc = new OpCode(-2097044332);
-               public static readonly OpCode Ldloca = new OpCode(-2092644828);
-               public static readonly OpCode Stloc = new OpCode(-2088753536);
-               public static readonly OpCode Localloc = new OpCode(-2084241010);
-               public static readonly OpCode Endfilter = new OpCode(-2076160335);
-               public static readonly OpCode Unaligned = new OpCode(-2071982151);
-               public static readonly OpCode Volatile = new OpCode(-2067787858);
-               public static readonly OpCode Tailcall = new OpCode(-2063593554);
-               public static readonly OpCode Initobj = new OpCode(-2059384859);
-               public static readonly OpCode Constrained = new OpCode(-2055204938);
-               public static readonly OpCode Cpblk = new OpCode(-2050974371);
-               public static readonly OpCode Initblk = new OpCode(-2046780067);
-               public static readonly OpCode Rethrow = new OpCode(-2038428509);
-               public static readonly OpCode Sizeof = new OpCode(-2029730269);
-               public static readonly OpCode Refanytype = new OpCode(-2025531014);
-               public static readonly OpCode Readonly = new OpCode(-2021650514);
-
-               internal static string GetName(int value)
-               {
-                       switch (value)
-                       {
-                               case 0:
-                                       return "nop";
-                               case 1:
-                                       return "break";
-                               case 2:
-                                       return "ldarg.0";
-                               case 3:
-                                       return "ldarg.1";
-                               case 4:
-                                       return "ldarg.2";
-                               case 5:
-                                       return "ldarg.3";
-                               case 6:
-                                       return "ldloc.0";
-                               case 7:
-                                       return "ldloc.1";
-                               case 8:
-                                       return "ldloc.2";
-                               case 9:
-                                       return "ldloc.3";
-                               case 10:
-                                       return "stloc.0";
-                               case 11:
-                                       return "stloc.1";
-                               case 12:
-                                       return "stloc.2";
-                               case 13:
-                                       return "stloc.3";
-                               case 14:
-                                       return "ldarg.s";
-                               case 15:
-                                       return "ldarga.s";
-                               case 16:
-                                       return "starg.s";
-                               case 17:
-                                       return "ldloc.s";
-                               case 18:
-                                       return "ldloca.s";
-                               case 19:
-                                       return "stloc.s";
-                               case 20:
-                                       return "ldnull";
-                               case 21:
-                                       return "ldc.i4.m1";
-                               case 22:
-                                       return "ldc.i4.0";
-                               case 23:
-                                       return "ldc.i4.1";
-                               case 24:
-                                       return "ldc.i4.2";
-                               case 25:
-                                       return "ldc.i4.3";
-                               case 26:
-                                       return "ldc.i4.4";
-                               case 27:
-                                       return "ldc.i4.5";
-                               case 28:
-                                       return "ldc.i4.6";
-                               case 29:
-                                       return "ldc.i4.7";
-                               case 30:
-                                       return "ldc.i4.8";
-                               case 31:
-                                       return "ldc.i4.s";
-                               case 32:
-                                       return "ldc.i4";
-                               case 33:
-                                       return "ldc.i8";
-                               case 34:
-                                       return "ldc.r4";
-                               case 35:
-                                       return "ldc.r8";
-                               case 37:
-                                       return "dup";
-                               case 38:
-                                       return "pop";
-                               case 39:
-                                       return "jmp";
-                               case 40:
-                                       return "call";
-                               case 41:
-                                       return "calli";
-                               case 42:
-                                       return "ret";
-                               case 43:
-                                       return "br.s";
-                               case 44:
-                                       return "brfalse.s";
-                               case 45:
-                                       return "brtrue.s";
-                               case 46:
-                                       return "beq.s";
-                               case 47:
-                                       return "bge.s";
-                               case 48:
-                                       return "bgt.s";
-                               case 49:
-                                       return "ble.s";
-                               case 50:
-                                       return "blt.s";
-                               case 51:
-                                       return "bne.un.s";
-                               case 52:
-                                       return "bge.un.s";
-                               case 53:
-                                       return "bgt.un.s";
-                               case 54:
-                                       return "ble.un.s";
-                               case 55:
-                                       return "blt.un.s";
-                               case 56:
-                                       return "br";
-                               case 57:
-                                       return "brfalse";
-                               case 58:
-                                       return "brtrue";
-                               case 59:
-                                       return "beq";
-                               case 60:
-                                       return "bge";
-                               case 61:
-                                       return "bgt";
-                               case 62:
-                                       return "ble";
-                               case 63:
-                                       return "blt";
-                               case 64:
-                                       return "bne.un";
-                               case 65:
-                                       return "bge.un";
-                               case 66:
-                                       return "bgt.un";
-                               case 67:
-                                       return "ble.un";
-                               case 68:
-                                       return "blt.un";
-                               case 69:
-                                       return "switch";
-                               case 70:
-                                       return "ldind.i1";
-                               case 71:
-                                       return "ldind.u1";
-                               case 72:
-                                       return "ldind.i2";
-                               case 73:
-                                       return "ldind.u2";
-                               case 74:
-                                       return "ldind.i4";
-                               case 75:
-                                       return "ldind.u4";
-                               case 76:
-                                       return "ldind.i8";
-                               case 77:
-                                       return "ldind.i";
-                               case 78:
-                                       return "ldind.r4";
-                               case 79:
-                                       return "ldind.r8";
-                               case 80:
-                                       return "ldind.ref";
-                               case 81:
-                                       return "stind.ref";
-                               case 82:
-                                       return "stind.i1";
-                               case 83:
-                                       return "stind.i2";
-                               case 84:
-                                       return "stind.i4";
-                               case 85:
-                                       return "stind.i8";
-                               case 86:
-                                       return "stind.r4";
-                               case 87:
-                                       return "stind.r8";
-                               case 88:
-                                       return "add";
-                               case 89:
-                                       return "sub";
-                               case 90:
-                                       return "mul";
-                               case 91:
-                                       return "div";
-                               case 92:
-                                       return "div.un";
-                               case 93:
-                                       return "rem";
-                               case 94:
-                                       return "rem.un";
-                               case 95:
-                                       return "and";
-                               case 96:
-                                       return "or";
-                               case 97:
-                                       return "xor";
-                               case 98:
-                                       return "shl";
-                               case 99:
-                                       return "shr";
-                               case 100:
-                                       return "shr.un";
-                               case 101:
-                                       return "neg";
-                               case 102:
-                                       return "not";
-                               case 103:
-                                       return "conv.i1";
-                               case 104:
-                                       return "conv.i2";
-                               case 105:
-                                       return "conv.i4";
-                               case 106:
-                                       return "conv.i8";
-                               case 107:
-                                       return "conv.r4";
-                               case 108:
-                                       return "conv.r8";
-                               case 109:
-                                       return "conv.u4";
-                               case 110:
-                                       return "conv.u8";
-                               case 111:
-                                       return "callvirt";
-                               case 112:
-                                       return "cpobj";
-                               case 113:
-                                       return "ldobj";
-                               case 114:
-                                       return "ldstr";
-                               case 115:
-                                       return "newobj";
-                               case 116:
-                                       return "castclass";
-                               case 117:
-                                       return "isinst";
-                               case 118:
-                                       return "conv.r.un";
-                               case 121:
-                                       return "unbox";
-                               case 122:
-                                       return "throw";
-                               case 123:
-                                       return "ldfld";
-                               case 124:
-                                       return "ldflda";
-                               case 125:
-                                       return "stfld";
-                               case 126:
-                                       return "ldsfld";
-                               case 127:
-                                       return "ldsflda";
-                               case 128:
-                                       return "stsfld";
-                               case 129:
-                                       return "stobj";
-                               case 130:
-                                       return "conv.ovf.i1.un";
-                               case 131:
-                                       return "conv.ovf.i2.un";
-                               case 132:
-                                       return "conv.ovf.i4.un";
-                               case 133:
-                                       return "conv.ovf.i8.un";
-                               case 134:
-                                       return "conv.ovf.u1.un";
-                               case 135:
-                                       return "conv.ovf.u2.un";
-                               case 136:
-                                       return "conv.ovf.u4.un";
-                               case 137:
-                                       return "conv.ovf.u8.un";
-                               case 138:
-                                       return "conv.ovf.i.un";
-                               case 139:
-                                       return "conv.ovf.u.un";
-                               case 140:
-                                       return "box";
-                               case 141:
-                                       return "newarr";
-                               case 142:
-                                       return "ldlen";
-                               case 143:
-                                       return "ldelema";
-                               case 144:
-                                       return "ldelem.i1";
-                               case 145:
-                                       return "ldelem.u1";
-                               case 146:
-                                       return "ldelem.i2";
-                               case 147:
-                                       return "ldelem.u2";
-                               case 148:
-                                       return "ldelem.i4";
-                               case 149:
-                                       return "ldelem.u4";
-                               case 150:
-                                       return "ldelem.i8";
-                               case 151:
-                                       return "ldelem.i";
-                               case 152:
-                                       return "ldelem.r4";
-                               case 153:
-                                       return "ldelem.r8";
-                               case 154:
-                                       return "ldelem.ref";
-                               case 155:
-                                       return "stelem.i";
-                               case 156:
-                                       return "stelem.i1";
-                               case 157:
-                                       return "stelem.i2";
-                               case 158:
-                                       return "stelem.i4";
-                               case 159:
-                                       return "stelem.i8";
-                               case 160:
-                                       return "stelem.r4";
-                               case 161:
-                                       return "stelem.r8";
-                               case 162:
-                                       return "stelem.ref";
-                               case 163:
-                                       return "ldelem";
-                               case 164:
-                                       return "stelem";
-                               case 165:
-                                       return "unbox.any";
-                               case 179:
-                                       return "conv.ovf.i1";
-                               case 180:
-                                       return "conv.ovf.u1";
-                               case 181:
-                                       return "conv.ovf.i2";
-                               case 182:
-                                       return "conv.ovf.u2";
-                               case 183:
-                                       return "conv.ovf.i4";
-                               case 184:
-                                       return "conv.ovf.u4";
-                               case 185:
-                                       return "conv.ovf.i8";
-                               case 186:
-                                       return "conv.ovf.u8";
-                               case 194:
-                                       return "refanyval";
-                               case 195:
-                                       return "ckfinite";
-                               case 198:
-                                       return "mkrefany";
-                               case 208:
-                                       return "ldtoken";
-                               case 209:
-                                       return "conv.u2";
-                               case 210:
-                                       return "conv.u1";
-                               case 211:
-                                       return "conv.i";
-                               case 212:
-                                       return "conv.ovf.i";
-                               case 213:
-                                       return "conv.ovf.u";
-                               case 214:
-                                       return "add.ovf";
-                               case 215:
-                                       return "add.ovf.un";
-                               case 216:
-                                       return "mul.ovf";
-                               case 217:
-                                       return "mul.ovf.un";
-                               case 218:
-                                       return "sub.ovf";
-                               case 219:
-                                       return "sub.ovf.un";
-                               case 220:
-                                       return "endfinally";
-                               case 221:
-                                       return "leave";
-                               case 222:
-                                       return "leave.s";
-                               case 223:
-                                       return "stind.i";
-                               case 224:
-                                       return "conv.u";
-                               case 248:
-                                       return "prefix7";
-                               case 249:
-                                       return "prefix6";
-                               case 250:
-                                       return "prefix5";
-                               case 251:
-                                       return "prefix4";
-                               case 252:
-                                       return "prefix3";
-                               case 253:
-                                       return "prefix2";
-                               case 254:
-                                       return "prefix1";
-                               case 255:
-                                       return "prefixref";
-                               case -512:
-                                       return "arglist";
-                               case -511:
-                                       return "ceq";
-                               case -510:
-                                       return "cgt";
-                               case -509:
-                                       return "cgt.un";
-                               case -508:
-                                       return "clt";
-                               case -507:
-                                       return "clt.un";
-                               case -506:
-                                       return "ldftn";
-                               case -505:
-                                       return "ldvirtftn";
-                               case -503:
-                                       return "ldarg";
-                               case -502:
-                                       return "ldarga";
-                               case -501:
-                                       return "starg";
-                               case -500:
-                                       return "ldloc";
-                               case -499:
-                                       return "ldloca";
-                               case -498:
-                                       return "stloc";
-                               case -497:
-                                       return "localloc";
-                               case -495:
-                                       return "endfilter";
-                               case -494:
-                                       return "unaligned.";
-                               case -493:
-                                       return "volatile.";
-                               case -492:
-                                       return "tail.";
-                               case -491:
-                                       return "initobj";
-                               case -490:
-                                       return "constrained.";
-                               case -489:
-                                       return "cpblk";
-                               case -488:
-                                       return "initblk";
-                               case -486:
-                                       return "rethrow";
-                               case -484:
-                                       return "sizeof";
-                               case -483:
-                                       return "refanytype";
-                               case -482:
-                                       return "readonly.";
-                       }
-                       throw new ArgumentOutOfRangeException();
-               }
-
-               public static bool TakesSingleByteArgument(OpCode inst)
-               {
-                       switch (inst.Value)
-                       {
-                               case 14:
-                               case 15:
-                               case 16:
-                               case 17:
-                               case 18:
-                               case 19:
-                               case 31:
-                               case 43:
-                               case 44:
-                               case 45:
-                               case 46:
-                               case 47:
-                               case 48:
-                               case 49:
-                               case 50:
-                               case 51:
-                               case 52:
-                               case 53:
-                               case 54:
-                               case 55:
-                               case 222:
-                               case -494:
-                                       return true;
-                               default:
-                                       return false;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/ParameterBuilder.cs b/mcs/class/IKVM.Reflection/Emit/ParameterBuilder.cs
deleted file mode 100644 (file)
index 8b01efc..0000000
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class ParameterBuilder
-       {
-               private readonly ModuleBuilder moduleBuilder;
-               private short flags;
-               private readonly short sequence;
-               private readonly int nameIndex;
-               private readonly string name;
-               private int lazyPseudoToken;
-
-               internal ParameterBuilder(ModuleBuilder moduleBuilder, int sequence, ParameterAttributes attribs, string name)
-               {
-                       this.moduleBuilder = moduleBuilder;
-                       this.flags = (short)attribs;
-                       this.sequence = (short)sequence;
-                       this.nameIndex = name == null ? 0 : moduleBuilder.Strings.Add(name);
-                       this.name = name;
-               }
-
-               internal int PseudoToken
-               {
-                       get
-                       {
-                               if (lazyPseudoToken == 0)
-                               {
-                                       // we lazily create the token, because if we don't need it we don't want the token fixup cost
-                                       lazyPseudoToken = moduleBuilder.AllocPseudoToken();
-                               }
-                               return lazyPseudoToken;
-                       }
-               }
-
-               public string Name
-               {
-                       get { return name; }
-               }
-
-               public int Position
-               {
-                       // note that this differs from ParameterInfo.Position, which is zero based
-                       get { return sequence; }
-               }
-
-               public int Attributes
-               {
-                       get { return flags; }
-               }
-
-               public bool IsIn
-               {
-                       get { return (flags & (short)ParameterAttributes.In) != 0; }
-               }
-
-               public bool IsOut
-               {
-                       get { return (flags & (short)ParameterAttributes.Out) != 0; }
-               }
-
-               public bool IsOptional
-               {
-                       get { return (flags & (short)ParameterAttributes.Optional) != 0; }
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customAttributeBuilder)
-               {
-                       Universe u = moduleBuilder.universe;
-                       if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_InAttribute)
-                       {
-                               flags |= (short)ParameterAttributes.In;
-                       }
-                       else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OutAttribute)
-                       {
-                               flags |= (short)ParameterAttributes.Out;
-                       }
-                       else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_OptionalAttribute)
-                       {
-                               flags |= (short)ParameterAttributes.Optional;
-                       }
-                       else if (customAttributeBuilder.Constructor.DeclaringType == u.System_Runtime_InteropServices_MarshalAsAttribute)
-                       {
-                               FieldMarshal.SetMarshalAsAttribute(moduleBuilder, PseudoToken, customAttributeBuilder);
-                               flags |= (short)ParameterAttributes.HasFieldMarshal;
-                       }
-                       else
-                       {
-                               moduleBuilder.SetCustomAttribute(PseudoToken, customAttributeBuilder);
-                       }
-               }
-
-               public void SetConstant(object defaultValue)
-               {
-                       flags |= (short)ParameterAttributes.HasDefault;
-                       moduleBuilder.AddConstant(PseudoToken, defaultValue);
-               }
-
-               internal void WriteParamRecord(MetadataWriter mw)
-               {
-                       mw.Write(flags);
-                       mw.Write(sequence);
-                       mw.WriteStringIndex(nameIndex);
-               }
-
-               internal void FixupToken(int parameterToken)
-               {
-                       if (lazyPseudoToken != 0)
-                       {
-                               moduleBuilder.RegisterTokenFixup(lazyPseudoToken, parameterToken);
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/PropertyBuilder.cs b/mcs/class/IKVM.Reflection/Emit/PropertyBuilder.cs
deleted file mode 100644 (file)
index 6e3c741..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.CompilerServices;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class PropertyBuilder : PropertyInfo
-       {
-               private readonly TypeBuilder typeBuilder;
-               private readonly string name;
-               private PropertyAttributes attributes;
-               private PropertySignature sig;
-               private MethodBuilder getter;
-               private MethodBuilder setter;
-               private readonly List<Accessor> accessors = new List<Accessor>();
-               private int lazyPseudoToken;
-               private bool patchCallingConvention;
-
-               private struct Accessor
-               {
-                       internal short Semantics;
-                       internal MethodBuilder Method;
-               }
-
-               internal PropertyBuilder(TypeBuilder typeBuilder, string name, PropertyAttributes attributes, PropertySignature sig, bool patchCallingConvention)
-               {
-                       this.typeBuilder = typeBuilder;
-                       this.name = name;
-                       this.attributes = attributes;
-                       this.sig = sig;
-                       this.patchCallingConvention = patchCallingConvention;
-               }
-
-               internal override PropertySignature PropertySignature
-               {
-                       get { return sig; }
-               }
-
-               public void SetGetMethod(MethodBuilder mdBuilder)
-               {
-                       getter = mdBuilder;
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.Getter;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void SetSetMethod(MethodBuilder mdBuilder)
-               {
-                       setter = mdBuilder;
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.Setter;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void AddOtherMethod(MethodBuilder mdBuilder)
-               {
-                       Accessor acc;
-                       acc.Semantics = MethodSemanticsTable.Other;
-                       acc.Method = mdBuilder;
-                       accessors.Add(acc);
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       Universe u = typeBuilder.ModuleBuilder.universe;
-                       if (customBuilder.Constructor.DeclaringType == u.System_Runtime_CompilerServices_SpecialNameAttribute)
-                       {
-                               attributes |= PropertyAttributes.SpecialName;
-                       }
-                       else
-                       {
-                               if (lazyPseudoToken == 0)
-                               {
-                                       lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
-                               }
-                               typeBuilder.ModuleBuilder.SetCustomAttribute(lazyPseudoToken, customBuilder);
-                       }
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       if (lazyPseudoToken != 0)
-                       {
-                               return typeBuilder.ModuleBuilder.Constant.GetRawConstantValue(typeBuilder.ModuleBuilder, lazyPseudoToken);
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               public override PropertyAttributes Attributes
-               {
-                       get { return attributes; }
-               }
-
-               public override bool CanRead
-               {
-                       get { return getter != null; }
-               }
-
-               public override bool CanWrite
-               {
-                       get { return setter != null; }
-               }
-
-               public override MethodInfo GetGetMethod(bool nonPublic)
-               {
-                       return nonPublic || (getter != null && getter.IsPublic) ? getter : null;
-               }
-
-               public override MethodInfo GetSetMethod(bool nonPublic)
-               {
-                       return nonPublic || (setter != null && setter.IsPublic) ? setter : null;
-               }
-
-               public override MethodInfo[] GetAccessors(bool nonPublic)
-               {
-                       List<MethodInfo> list = new List<MethodInfo>();
-                       foreach (Accessor acc in accessors)
-                       {
-                               AddAccessor(list, nonPublic, acc.Method);
-                       }
-                       return list.ToArray();
-               }
-
-               private static void AddAccessor(List<MethodInfo> list, bool nonPublic, MethodInfo method)
-               {
-                       if (method != null && (nonPublic || method.IsPublic))
-                       {
-                               list.Add(method);
-                       }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeBuilder; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeBuilder.Module; }
-               }
-
-               public void SetConstant(object defaultValue)
-               {
-                       if (lazyPseudoToken == 0)
-                       {
-                               lazyPseudoToken = typeBuilder.ModuleBuilder.AllocPseudoToken();
-                       }
-                       attributes |= PropertyAttributes.HasDefault;
-                       typeBuilder.ModuleBuilder.AddConstant(lazyPseudoToken, defaultValue);
-               }
-
-               internal void Bake()
-               {
-                       if (patchCallingConvention)
-                       {
-                               sig.HasThis = !this.IsStatic;
-                       }
-
-                       PropertyTable.Record rec = new PropertyTable.Record();
-                       rec.Flags = (short)attributes;
-                       rec.Name = typeBuilder.ModuleBuilder.Strings.Add(name);
-                       rec.Type = typeBuilder.ModuleBuilder.GetSignatureBlobIndex(sig);
-                       int token = 0x17000000 | typeBuilder.ModuleBuilder.Property.AddRecord(rec);
-
-                       if (lazyPseudoToken == 0)
-                       {
-                               lazyPseudoToken = token;
-                       }
-                       else
-                       {
-                               typeBuilder.ModuleBuilder.RegisterTokenFixup(lazyPseudoToken, token);
-                       }
-
-                       foreach (Accessor acc in accessors)
-                       {
-                               AddMethodSemantics(acc.Semantics, acc.Method.MetadataToken, token);
-                       }
-               }
-
-               private void AddMethodSemantics(short semantics, int methodToken, int propertyToken)
-               {
-                       MethodSemanticsTable.Record rec = new MethodSemanticsTable.Record();
-                       rec.Semantics = semantics;
-                       rec.Method = methodToken;
-                       rec.Association = propertyToken;
-                       typeBuilder.ModuleBuilder.MethodSemantics.AddRecord(rec);
-               }
-
-               internal override bool IsPublic
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if (acc.Method.IsPublic)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if ((acc.Method.Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsStatic
-               {
-                       get
-                       {
-                               foreach (Accessor acc in accessors)
-                               {
-                                       if (acc.Method.IsStatic)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return typeBuilder.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       if (typeBuilder.ModuleBuilder.IsSaved && ModuleBuilder.IsPseudoToken(lazyPseudoToken))
-                       {
-                               return typeBuilder.ModuleBuilder.ResolvePseudoToken(lazyPseudoToken);
-                       }
-                       else
-                       {
-                               return lazyPseudoToken;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/SignatureHelper.cs b/mcs/class/IKVM.Reflection/Emit/SignatureHelper.cs
deleted file mode 100644 (file)
index 64dc18d..0000000
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using IKVM.Reflection;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public abstract class SignatureHelper
-       {
-               protected readonly byte type;
-               protected ushort paramCount;
-
-               sealed class Lazy : SignatureHelper
-               {
-                       private readonly List<Type> args = new List<Type>();
-
-                       internal Lazy(byte type)
-                               : base(type)
-                       {
-                       }
-
-                       internal override Type ReturnType
-                       {
-                               get { return args[0]; }
-                       }
-
-                       public override byte[] GetSignature()
-                       {
-                               throw new NotSupportedException();
-                       }
-
-                       internal override ByteBuffer GetSignature(ModuleBuilder module)
-                       {
-                               ByteBuffer bb = new ByteBuffer(16);
-                               Signature.WriteSignatureHelper(module, bb, type, paramCount, args);
-                               return bb;
-                       }
-
-                       public override void AddSentinel()
-                       {
-                               args.Add(MarkerType.Sentinel);
-                       }
-
-                       public override void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers)
-                       {
-                               if (pinned)
-                               {
-                                       args.Add(MarkerType.Pinned);
-                               }
-                               foreach (CustomModifiers.Entry mod in customModifiers)
-                               {
-                                       args.Add(mod.IsRequired ? MarkerType.ModReq : MarkerType.ModOpt);
-                                       args.Add(mod.Type);
-                               }
-                               args.Add(argument);
-                               paramCount++;
-                       }
-               }
-
-               sealed class Eager : SignatureHelper
-               {
-                       private readonly ModuleBuilder module;
-                       private readonly ByteBuffer bb = new ByteBuffer(16);
-                       private readonly Type returnType;
-
-                       internal Eager(ModuleBuilder module, byte type, Type returnType)
-                               : base(type)
-                       {
-                               this.module = module;
-                               this.returnType = returnType;
-                               bb.Write(type);
-                               if (type != Signature.FIELD)
-                               {
-                                       // space for parameterCount
-                                       bb.Write((byte)0);
-                               }
-                       }
-
-                       internal override Type ReturnType
-                       {
-                               get { return returnType; }
-                       }
-
-                       public override byte[] GetSignature()
-                       {
-                               return GetSignature(null).ToArray();
-                       }
-
-                       internal override ByteBuffer GetSignature(ModuleBuilder module)
-                       {
-                               if (type != Signature.FIELD)
-                               {
-                                       bb.Position = 1;
-                                       bb.Insert(MetadataWriter.GetCompressedUIntLength(paramCount) - bb.GetCompressedUIntLength());
-                                       bb.WriteCompressedUInt(paramCount);
-                               }
-                               return bb;
-                       }
-
-                       public override void AddSentinel()
-                       {
-                               bb.Write(Signature.SENTINEL);
-                       }
-
-                       public override void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers)
-                       {
-                               if (pinned)
-                               {
-                                       bb.Write(Signature.ELEMENT_TYPE_PINNED);
-                               }
-                               foreach (CustomModifiers.Entry mod in customModifiers)
-                               {
-                                       bb.Write(mod.IsRequired ? Signature.ELEMENT_TYPE_CMOD_REQD : Signature.ELEMENT_TYPE_CMOD_OPT);
-                                       Signature.WriteTypeSpec(module, bb, mod.Type);
-                               }
-                               Signature.WriteTypeSpec(module, bb, argument ?? module.universe.System_Void);
-                               paramCount++;
-                       }
-               }
-
-               private SignatureHelper(byte type)
-               {
-                       this.type = type;
-               }
-
-               internal bool HasThis
-               {
-                       get { return (type & Signature.HASTHIS) != 0; }
-               }
-
-               internal abstract Type ReturnType
-               {
-                       get;
-               }
-
-               internal int ParameterCount
-               {
-                       get { return paramCount; }
-               }
-
-               private static SignatureHelper Create(Module mod, byte type, Type returnType)
-               {
-                       ModuleBuilder mb = mod as ModuleBuilder;
-                       return mb == null
-                               ? (SignatureHelper)new Lazy(type)
-                               : new Eager(mb, type, returnType);
-               }
-
-               public static SignatureHelper GetFieldSigHelper(Module mod)
-               {
-                       return Create(mod, Signature.FIELD, null);
-               }
-
-               public static SignatureHelper GetLocalVarSigHelper()
-               {
-                       return new Lazy(Signature.LOCAL_SIG);
-               }
-
-               public static SignatureHelper GetLocalVarSigHelper(Module mod)
-               {
-                       return Create(mod, Signature.LOCAL_SIG, null);
-               }
-
-               public static SignatureHelper GetPropertySigHelper(Module mod, Type returnType, Type[] parameterTypes)
-               {
-                       SignatureHelper sig = Create(mod, Signature.PROPERTY, returnType);
-                       sig.AddArgument(returnType);
-                       sig.paramCount = 0;
-                       sig.AddArguments(parameterTypes, null, null);
-                       return sig;
-               }
-
-               public static SignatureHelper GetPropertySigHelper(Module mod, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
-               {
-                       return GetPropertySigHelper(mod, CallingConventions.Standard, returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers, parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
-               }
-
-               public static SignatureHelper GetPropertySigHelper(Module mod, CallingConventions callingConvention, Type returnType, Type[] requiredReturnTypeCustomModifiers, Type[] optionalReturnTypeCustomModifiers, Type[] parameterTypes, Type[][] requiredParameterTypeCustomModifiers, Type[][] optionalParameterTypeCustomModifiers)
-               {
-                       byte type = Signature.PROPERTY;
-                       if ((callingConvention & CallingConventions.HasThis) != 0)
-                       {
-                               type |= Signature.HASTHIS;
-                       }
-                       SignatureHelper sig = Create(mod, type, returnType);
-                       sig.AddArgument(returnType, requiredReturnTypeCustomModifiers, optionalReturnTypeCustomModifiers);
-                       sig.paramCount = 0;
-                       sig.AddArguments(parameterTypes, requiredParameterTypeCustomModifiers, optionalParameterTypeCustomModifiers);
-                       return sig;
-               }
-
-               public static SignatureHelper GetMethodSigHelper(CallingConvention unmanagedCallingConvention, Type returnType)
-               {
-                       return GetMethodSigHelper(null, unmanagedCallingConvention, returnType);
-               }
-
-               public static SignatureHelper GetMethodSigHelper(CallingConventions callingConvention, Type returnType)
-               {
-                       return GetMethodSigHelper(null, callingConvention, returnType);
-               }
-
-               public static SignatureHelper GetMethodSigHelper(Module mod, CallingConvention unmanagedCallConv, Type returnType)
-               {
-                       byte type;
-                       switch (unmanagedCallConv)
-                       {
-                               case CallingConvention.Cdecl:
-                                       type = 0x01;    // C
-                                       break;
-                               case CallingConvention.StdCall:
-                               case CallingConvention.Winapi:
-                                       type = 0x02;    // STDCALL
-                                       break;
-                               case CallingConvention.ThisCall:
-                                       type = 0x03;    // THISCALL
-                                       break;
-                               case CallingConvention.FastCall:
-                                       type = 0x04;    // FASTCALL
-                                       break;
-                               default:
-                                       throw new ArgumentOutOfRangeException("unmanagedCallConv");
-                       }
-                       SignatureHelper sig = Create(mod, type, returnType);
-                       sig.AddArgument(returnType);
-                       sig.paramCount = 0;
-                       return sig;
-               }
-
-               public static SignatureHelper GetMethodSigHelper(Module mod, CallingConventions callingConvention, Type returnType)
-               {
-                       byte type = 0;
-                       if ((callingConvention & CallingConventions.HasThis) != 0)
-                       {
-                               type |= Signature.HASTHIS;
-                       }
-                       if ((callingConvention & CallingConventions.ExplicitThis) != 0)
-                       {
-                               type |= Signature.EXPLICITTHIS;
-                       }
-                       if ((callingConvention & CallingConventions.VarArgs) != 0)
-                       {
-                               type |= Signature.VARARG;
-                       }
-                       SignatureHelper sig = Create(mod, type, returnType);
-                       sig.AddArgument(returnType);
-                       sig.paramCount = 0;
-                       return sig;
-               }
-
-               public static SignatureHelper GetMethodSigHelper(Module mod, Type returnType, Type[] parameterTypes)
-               {
-                       SignatureHelper sig = Create(mod, 0, returnType);
-                       sig.AddArgument(returnType);
-                       sig.paramCount = 0;
-                       sig.AddArguments(parameterTypes, null, null);
-                       return sig;
-               }
-
-               public abstract byte[] GetSignature();
-
-               internal abstract ByteBuffer GetSignature(ModuleBuilder module);
-
-               public abstract void AddSentinel();
-
-               public void AddArgument(Type clsArgument)
-               {
-                       AddArgument(clsArgument, false);
-               }
-
-               public void AddArgument(Type argument, bool pinned)
-               {
-                       __AddArgument(argument, pinned, new CustomModifiers());
-               }
-
-               public void AddArgument(Type argument, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       __AddArgument(argument, false, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public abstract void __AddArgument(Type argument, bool pinned, CustomModifiers customModifiers);
-
-               public void AddArguments(Type[] arguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
-               {
-                       if (arguments != null)
-                       {
-                               for (int i = 0; i < arguments.Length; i++)
-                               {
-                                       __AddArgument(arguments[i], false, CustomModifiers.FromReqOpt(Util.NullSafeElementAt(requiredCustomModifiers, i), Util.NullSafeElementAt(optionalCustomModifiers, i)));
-                               }
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/Tokens.cs b/mcs/class/IKVM.Reflection/Emit/Tokens.cs
deleted file mode 100644 (file)
index 9b39f29..0000000
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-
-namespace IKVM.Reflection.Emit
-{
-       public struct EventToken
-       {
-               public static readonly EventToken Empty;
-               private readonly int token;
-
-               internal EventToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as EventToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(EventToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(EventToken et1, EventToken et2)
-               {
-                       return et1.token == et2.token;
-               }
-
-               public static bool operator !=(EventToken et1, EventToken et2)
-               {
-                       return et1.token != et2.token;
-               }
-       }
-
-       public struct FieldToken
-       {
-               public static readonly FieldToken Empty;
-               private readonly int token;
-
-               internal FieldToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as FieldToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(FieldToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(FieldToken ft1, FieldToken ft2)
-               {
-                       return ft1.token == ft2.token;
-               }
-
-               public static bool operator !=(FieldToken ft1, FieldToken ft2)
-               {
-                       return ft1.token != ft2.token;
-               }
-       }
-
-       public struct MethodToken
-       {
-               public static readonly MethodToken Empty;
-               private readonly int token;
-
-               internal MethodToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as MethodToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(MethodToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(MethodToken mt1, MethodToken mt2)
-               {
-                       return mt1.token == mt2.token;
-               }
-
-               public static bool operator !=(MethodToken mt1, MethodToken mt2)
-               {
-                       return mt1.token != mt2.token;
-               }
-       }
-
-       public struct SignatureToken
-       {
-               public static readonly SignatureToken Empty;
-               private readonly int token;
-
-               internal SignatureToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as SignatureToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(SignatureToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(SignatureToken st1, SignatureToken st2)
-               {
-                       return st1.token == st2.token;
-               }
-
-               public static bool operator !=(SignatureToken st1, SignatureToken st2)
-               {
-                       return st1.token != st2.token;
-               }
-       }
-
-       public struct StringToken
-       {
-               private readonly int token;
-
-               internal StringToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as StringToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(StringToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(StringToken st1, StringToken st2)
-               {
-                       return st1.token == st2.token;
-               }
-
-               public static bool operator !=(StringToken st1, StringToken st2)
-               {
-                       return st1.token != st2.token;
-               }
-       }
-
-       public struct TypeToken
-       {
-               public static readonly TypeToken Empty;
-               private readonly int token;
-
-               internal TypeToken(int token)
-               {
-                       this.token = token;
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return obj as TypeToken? == this;
-               }
-
-               public override int GetHashCode()
-               {
-                       return token;
-               }
-
-               public bool Equals(TypeToken other)
-               {
-                       return this == other;
-               }
-
-               public static bool operator ==(TypeToken tt1, TypeToken tt2)
-               {
-                       return tt1.token == tt2.token;
-               }
-
-               public static bool operator !=(TypeToken tt1, TypeToken tt2)
-               {
-                       return tt1.token != tt2.token;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Emit/TypeBuilder.cs b/mcs/class/IKVM.Reflection/Emit/TypeBuilder.cs
deleted file mode 100644 (file)
index aa6d264..0000000
+++ /dev/null
@@ -1,1252 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Runtime.InteropServices;
-using IKVM.Reflection.Impl;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Writer;
-
-namespace IKVM.Reflection.Emit
-{
-       public sealed class GenericTypeParameterBuilder : TypeInfo
-       {
-               private readonly string name;
-               private readonly TypeBuilder type;
-               private readonly MethodBuilder method;
-               private readonly int paramPseudoIndex;
-               private readonly int position;
-               private int typeToken;
-               private Type baseType;
-               private GenericParameterAttributes attr;
-
-               internal GenericTypeParameterBuilder(string name, TypeBuilder type, MethodBuilder method, int position)
-               {
-                       this.name = name;
-                       this.type = type;
-                       this.method = method;
-                       this.position = position;
-                       GenericParamTable.Record rec = new GenericParamTable.Record();
-                       rec.Number = (short)position;
-                       rec.Flags = 0;
-                       rec.Owner = type != null ? type.MetadataToken : method.MetadataToken;
-                       rec.Name = this.ModuleBuilder.Strings.Add(name);
-                       this.paramPseudoIndex = this.ModuleBuilder.GenericParam.AddRecord(rec);
-               }
-
-               public override string AssemblyQualifiedName
-               {
-                       get { return null; }
-               }
-
-               public override bool IsValueType
-               {
-                       get { return (this.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0; }
-               }
-
-               public override Type BaseType
-               {
-                       get { return baseType; }
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return TypeAttributes.Public; }
-               }
-
-               public override string Namespace
-               {
-                       get { return DeclaringType.Namespace; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override string FullName
-               {
-                       get { return null; }
-               }
-
-               public override string ToString()
-               {
-                       return this.Name;
-               }
-
-               private ModuleBuilder ModuleBuilder
-               {
-                       get { return type != null ? type.ModuleBuilder : method.ModuleBuilder; }
-               }
-
-               public override Module Module
-               {
-                       get { return ModuleBuilder; }
-               }
-
-               public override bool IsGenericParameter
-               {
-                       get { return true; }
-               }
-
-               public override int GenericParameterPosition
-               {
-                       get { return position; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return type; }
-               }
-
-               public override MethodBase DeclaringMethod
-               {
-                       get { return method; }
-               }
-
-               public override Type[] GetGenericParameterConstraints()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public override GenericParameterAttributes GenericParameterAttributes
-               {
-                       get
-                       {
-                               CheckBaked();
-                               return attr;
-                       }
-               }
-
-               internal override void CheckBaked()
-               {
-                       if (type != null)
-                       {
-                               type.CheckBaked();
-                       }
-                       else
-                       {
-                               method.CheckBaked();
-                       }
-               }
-
-               private void AddConstraint(Type type)
-               {
-                       GenericParamConstraintTable.Record rec = new GenericParamConstraintTable.Record();
-                       rec.Owner = paramPseudoIndex;
-                       rec.Constraint = this.ModuleBuilder.GetTypeTokenForMemberRef(type);
-                       this.ModuleBuilder.GenericParamConstraint.AddRecord(rec);
-               }
-
-               public void SetBaseTypeConstraint(Type baseTypeConstraint)
-               {
-                       this.baseType = baseTypeConstraint;
-                       AddConstraint(baseTypeConstraint);
-               }
-
-               public void SetInterfaceConstraints(params Type[] interfaceConstraints)
-               {
-                       foreach (Type type in interfaceConstraints)
-                       {
-                               AddConstraint(type);
-                       }
-               }
-
-               public void SetGenericParameterAttributes(GenericParameterAttributes genericParameterAttributes)
-               {
-                       this.attr = genericParameterAttributes;
-                       // for now we'll back patch the table
-                       this.ModuleBuilder.GenericParam.PatchAttribute(paramPseudoIndex, genericParameterAttributes);
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       this.ModuleBuilder.SetCustomAttribute((GenericParamTable.Index << 24) | paramPseudoIndex, customBuilder);
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public override int MetadataToken
-               {
-                       get
-                       {
-                               CheckBaked();
-                               return (GenericParamTable.Index << 24) | paramPseudoIndex;
-                       }
-               }
-
-               internal override int GetModuleBuilderToken()
-               {
-                       if (typeToken == 0)
-                       {
-                               ByteBuffer spec = new ByteBuffer(5);
-                               Signature.WriteTypeSpec(this.ModuleBuilder, spec, this);
-                               typeToken = 0x1B000000 | this.ModuleBuilder.TypeSpec.AddRecord(this.ModuleBuilder.Blobs.Add(spec));
-                       }
-                       return typeToken;
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       if (type != null)
-                       {
-                               return binder.BindTypeParameter(this);
-                       }
-                       else
-                       {
-                               return binder.BindMethodParameter(this);
-                       }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       if (this.ModuleBuilder.IsSaved)
-                       {
-                               return (GenericParamTable.Index << 24) | this.Module.GenericParam.GetIndexFixup()[paramPseudoIndex - 1] + 1;
-                       }
-                       else
-                       {
-                               return (GenericParamTable.Index << 24) | paramPseudoIndex;
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return ((MemberInfo)type ?? method).IsBaked; }
-               }
-       }
-
-       public sealed class TypeBuilder : TypeInfo, ITypeOwner
-       {
-               public const int UnspecifiedTypeSize = 0;
-               private readonly ITypeOwner owner;
-               private readonly int token;
-               private int extends;
-               private Type lazyBaseType;              // (lazyBaseType == null && attribs & TypeAttributes.Interface) == 0) => BaseType == System.Object
-               private readonly int typeName;
-               private readonly int typeNameSpace;
-               private readonly string ns;
-               private readonly string name;
-               private readonly List<MethodBuilder> methods = new List<MethodBuilder>();
-               private readonly List<FieldBuilder> fields = new List<FieldBuilder>();
-               private List<PropertyBuilder> properties;
-               private List<EventBuilder> events;
-               private TypeAttributes attribs;
-               private GenericTypeParameterBuilder[] gtpb;
-               private List<CustomAttributeBuilder> declarativeSecurity;
-               private List<Type> interfaces;
-               private int size;
-               private short pack;
-               private bool hasLayout;
-
-               internal TypeBuilder(ITypeOwner owner, string ns, string name)
-               {
-                       this.owner = owner;
-                       this.token = this.ModuleBuilder.TypeDef.AllocToken();
-                       this.ns = ns;
-                       this.name = name;
-                       this.typeNameSpace = ns == null ? 0 : this.ModuleBuilder.Strings.Add(ns);
-                       this.typeName = this.ModuleBuilder.Strings.Add(name);
-                       MarkEnumOrValueType(ns, name);
-               }
-
-               public ConstructorBuilder DefineDefaultConstructor(MethodAttributes attributes)
-               {
-                       ConstructorBuilder cb = DefineConstructor(attributes, CallingConventions.Standard, Type.EmptyTypes);
-                       ILGenerator ilgen = cb.GetILGenerator();
-                       ilgen.Emit(OpCodes.Ldarg_0);
-                       ilgen.Emit(OpCodes.Call, BaseType.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null));
-                       ilgen.Emit(OpCodes.Ret);
-                       return cb;
-               }
-
-               public ConstructorBuilder DefineConstructor(MethodAttributes attribs, CallingConventions callConv, Type[] parameterTypes)
-               {
-                       return DefineConstructor(attribs, callConv, parameterTypes, null, null);
-               }
-
-               public ConstructorBuilder DefineConstructor(MethodAttributes attribs, CallingConventions callingConvention, Type[] parameterTypes, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
-               {
-                       attribs |= MethodAttributes.RTSpecialName | MethodAttributes.SpecialName;
-                       string name = (attribs & MethodAttributes.Static) == 0 ? ConstructorInfo.ConstructorName : ConstructorInfo.TypeConstructorName;
-                       MethodBuilder mb = DefineMethod(name, attribs, callingConvention, null, null, null, parameterTypes, requiredCustomModifiers, optionalCustomModifiers);
-                       return new ConstructorBuilder(mb);
-               }
-
-               public ConstructorBuilder DefineTypeInitializer()
-               {
-                       MethodBuilder mb = DefineMethod(ConstructorInfo.TypeConstructorName, MethodAttributes.Private | MethodAttributes.Static | MethodAttributes.RTSpecialName | MethodAttributes.SpecialName, null, Type.EmptyTypes);
-                       return new ConstructorBuilder(mb);
-               }
-
-               private MethodBuilder CreateMethodBuilder(string name, MethodAttributes attributes, CallingConventions callingConvention)
-               {
-                       this.ModuleBuilder.MethodDef.AddVirtualRecord();
-                       MethodBuilder mb = new MethodBuilder(this, name, attributes, callingConvention);
-                       methods.Add(mb);
-                       return mb;
-               }
-
-               public MethodBuilder DefineMethod(string name, MethodAttributes attribs)
-               {
-                       return DefineMethod(name, attribs, CallingConventions.Standard);
-               }
-
-               public MethodBuilder DefineMethod(string name, MethodAttributes attribs, CallingConventions callingConvention)
-               {
-                       return CreateMethodBuilder(name, attribs, callingConvention);
-               }
-
-               public MethodBuilder DefineMethod(string name, MethodAttributes attribs, Type returnType, Type[] parameterTypes)
-               {
-                       return DefineMethod(name, attribs, CallingConventions.Standard, returnType, null, null, parameterTypes, null, null);
-               }
-
-               public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       return DefineMethod(name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
-               }
-
-               public MethodBuilder DefineMethod(string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       MethodBuilder mb = CreateMethodBuilder(name, attributes, callingConvention);
-                       mb.SetSignature(returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers, parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
-                       return mb;
-               }
-
-               public MethodBuilder DefinePInvokeMethod(string name, string dllName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
-               {
-                       return DefinePInvokeMethod(name, dllName, null, attributes, callingConvention, returnType, null, null, parameterTypes, null, null, nativeCallConv, nativeCharSet);
-               }
-
-               public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, CallingConvention nativeCallConv, CharSet nativeCharSet)
-               {
-                       return DefinePInvokeMethod(name, dllName, entryName, attributes, callingConvention, returnType, null, null, parameterTypes, null, null, nativeCallConv, nativeCharSet);
-               }
-
-               public MethodBuilder DefinePInvokeMethod(string name, string dllName, string entryName, MethodAttributes attributes, CallingConventions callingConvention,
-                       Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
-                       Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers,
-                       CallingConvention nativeCallConv, CharSet nativeCharSet)
-               {
-                       MethodBuilder mb = DefineMethod(name, attributes | MethodAttributes.PinvokeImpl, callingConvention,
-                               returnType, returnTypeRequiredCustomModifiers, returnTypeOptionalCustomModifiers,
-                               parameterTypes, parameterTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers);
-                       mb.SetDllImportPseudoCustomAttribute(dllName, entryName, nativeCallConv, nativeCharSet, null, null, null, null, null);
-                       return mb;
-               }
-
-               public void DefineMethodOverride(MethodInfo methodInfoBody, MethodInfo methodInfoDeclaration)
-               {
-                       MethodImplTable.Record rec = new MethodImplTable.Record();
-                       rec.Class = token;
-                       rec.MethodBody = this.ModuleBuilder.GetMethodToken(methodInfoBody).Token;
-                       rec.MethodDeclaration = this.ModuleBuilder.GetMethodTokenWinRT(methodInfoDeclaration);
-                       this.ModuleBuilder.MethodImpl.AddRecord(rec);
-               }
-
-               public FieldBuilder DefineField(string name, Type fieldType, FieldAttributes attribs)
-               {
-                       return DefineField(name, fieldType, null, null, attribs);
-               }
-
-               public FieldBuilder DefineField(string fieldName, Type type, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers, FieldAttributes attributes)
-               {
-                       return __DefineField(fieldName, type, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers), attributes);
-               }
-
-               public FieldBuilder __DefineField(string fieldName, Type type, CustomModifiers customModifiers, FieldAttributes attributes)
-               {
-                       FieldBuilder fb = new FieldBuilder(this, fieldName, type, customModifiers, attributes);
-                       fields.Add(fb);
-                       return fb;
-               }
-
-               public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] parameterTypes)
-               {
-                       return DefineProperty(name, attributes, returnType, null, null, parameterTypes, null, null);
-               }
-
-               public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-               {
-                       return DefineProperty(name, attributes, callingConvention, returnType, null, null, parameterTypes, null, null);
-               }
-
-               public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
-                       Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       return DefinePropertyImpl(name, attributes, CallingConventions.Standard, true, returnType, parameterTypes,
-                               PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               public PropertyBuilder DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention,
-                       Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers,
-                       Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes,
-                               PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               public PropertyBuilder __DefineProperty(string name, PropertyAttributes attributes, CallingConventions callingConvention,
-                       Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       return DefinePropertyImpl(name, attributes, callingConvention, false, returnType, parameterTypes,
-                               PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               private PropertyBuilder DefinePropertyImpl(string name, PropertyAttributes attributes, CallingConventions callingConvention, bool patchCallingConvention,
-                       Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       if (properties == null)
-                       {
-                               properties = new List<PropertyBuilder>();
-                       }
-                       PropertySignature sig = PropertySignature.Create(callingConvention, returnType, parameterTypes, customModifiers);
-                       PropertyBuilder pb = new PropertyBuilder(this, name, attributes, sig, patchCallingConvention);
-                       properties.Add(pb);
-                       return pb;
-               }
-
-               public EventBuilder DefineEvent(string name, EventAttributes attributes, Type eventtype)
-               {
-                       if (events == null)
-                       {
-                               events = new List<EventBuilder>();
-                       }
-                       EventBuilder eb = new EventBuilder(this, name, attributes, eventtype);
-                       events.Add(eb);
-                       return eb;
-               }
-
-               public TypeBuilder DefineNestedType(string name)
-               {
-                       return DefineNestedType(name, TypeAttributes.Class | TypeAttributes.NestedPrivate);
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attribs)
-               {
-                       return DefineNestedType(name, attribs, null);
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, Type[] interfaces)
-               {
-                       TypeBuilder tb = DefineNestedType(name, attr, parent);
-                       if (interfaces != null)
-                       {
-                               foreach (Type iface in interfaces)
-                               {
-                                       tb.AddInterfaceImplementation(iface);
-                               }
-                       }
-                       return tb;
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent)
-               {
-                       return DefineNestedType(name, attr, parent, 0);
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, int typeSize)
-               {
-                       return DefineNestedType(name, attr, parent, PackingSize.Unspecified, typeSize);
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize)
-               {
-                       return DefineNestedType(name, attr, parent, packSize, 0);
-               }
-
-               public TypeBuilder DefineNestedType(string name, TypeAttributes attr, Type parent, PackingSize packSize, int typeSize)
-               {
-                       string ns = null;
-                       int lastdot = name.LastIndexOf('.');
-                       if (lastdot > 0)
-                       {
-                               ns = name.Substring(0, lastdot);
-                               name = name.Substring(lastdot + 1);
-                       }
-                       TypeBuilder typeBuilder = __DefineNestedType(ns, name);
-                       typeBuilder.__SetAttributes(attr);
-                       typeBuilder.SetParent(parent);
-                       if (packSize != PackingSize.Unspecified || typeSize != 0)
-                       {
-                               typeBuilder.__SetLayout((int)packSize, typeSize);
-                       }
-                       return typeBuilder;
-               }
-
-               public TypeBuilder __DefineNestedType(string ns, string name)
-               {
-                       this.typeFlags |= TypeFlags.HasNestedTypes;
-                       TypeBuilder typeBuilder = this.ModuleBuilder.DefineType(this, ns, name);
-                       NestedClassTable.Record rec = new NestedClassTable.Record();
-                       rec.NestedClass = typeBuilder.MetadataToken;
-                       rec.EnclosingClass = this.MetadataToken;
-                       this.ModuleBuilder.NestedClass.AddRecord(rec);
-                       return typeBuilder;
-               }
-
-               public void SetParent(Type parent)
-               {
-                       lazyBaseType = parent;
-               }
-
-               public void AddInterfaceImplementation(Type interfaceType)
-               {
-                       if (interfaces == null)
-                       {
-                               interfaces = new List<Type>();
-                       }
-                       interfaces.Add(interfaceType);
-               }
-
-               public void __SetInterfaceImplementationCustomAttribute(Type interfaceType, CustomAttributeBuilder cab)
-               {
-                       this.ModuleBuilder.SetInterfaceImplementationCustomAttribute(this, interfaceType, cab);
-               }
-
-               public int Size
-               {
-                       get { return size; }
-               }
-
-               public PackingSize PackingSize
-               {
-                       get { return (PackingSize)pack; }
-               }
-
-               public override bool __GetLayout(out int packingSize, out int typeSize)
-               {
-                       packingSize = this.pack;
-                       typeSize = this.size;
-                       return hasLayout;
-               }
-
-               public void __SetLayout(int packingSize, int typesize)
-               {
-                       this.pack = (short)packingSize;
-                       this.size = typesize;
-                       this.hasLayout = true;
-               }
-
-               private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       object val = customBuilder.GetConstructorArgument(0);
-                       LayoutKind layout;
-                       if (val is short)
-                       {
-                               layout = (LayoutKind)(short)val;
-                       }
-                       else
-                       {
-                               layout = (LayoutKind)val;
-                       }
-                       StructLayoutAttribute attr = new StructLayoutAttribute(layout);
-                       attr.Pack = (int?)customBuilder.GetFieldValue("Pack") ?? 0;
-                       attr.Size = (int?)customBuilder.GetFieldValue("Size") ?? 0;
-                       attr.CharSet = customBuilder.GetFieldValue<CharSet>("CharSet") ?? CharSet.None;
-                       attribs &= ~TypeAttributes.LayoutMask;
-                       switch (attr.Value)
-                       {
-                               case LayoutKind.Auto:
-                                       attribs |= TypeAttributes.AutoLayout;
-                                       break;
-                               case LayoutKind.Explicit:
-                                       attribs |= TypeAttributes.ExplicitLayout;
-                                       break;
-                               case LayoutKind.Sequential:
-                                       attribs |= TypeAttributes.SequentialLayout;
-                                       break;
-                       }
-                       attribs &= ~TypeAttributes.StringFormatMask;
-                       switch (attr.CharSet)
-                       {
-                               case CharSet.None:
-                               case CharSet.Ansi:
-                                       attribs |= TypeAttributes.AnsiClass;
-                                       break;
-                               case CharSet.Auto:
-                                       attribs |= TypeAttributes.AutoClass;
-                                       break;
-                               case CharSet.Unicode:
-                                       attribs |= TypeAttributes.UnicodeClass;
-                                       break;
-                       }
-                       pack = (short)attr.Pack;
-                       size = attr.Size;
-                       hasLayout = pack != 0 || size != 0;
-               }
-
-               public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
-               {
-                       SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute));
-               }
-
-               public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
-               {
-                       Universe u = this.ModuleBuilder.universe;
-                       Type type = customBuilder.Constructor.DeclaringType;
-                       if (type == u.System_Runtime_InteropServices_StructLayoutAttribute)
-                       {
-                               SetStructLayoutPseudoCustomAttribute(customBuilder.DecodeBlob(this.Assembly));
-                       }
-                       else if (type == u.System_SerializableAttribute)
-                       {
-                               attribs |= TypeAttributes.Serializable;
-                       }
-                       else if (type == u.System_Runtime_InteropServices_ComImportAttribute)
-                       {
-                               attribs |= TypeAttributes.Import;
-                       }
-                       else if (type == u.System_Runtime_CompilerServices_SpecialNameAttribute)
-                       {
-                               attribs |= TypeAttributes.SpecialName;
-                       }
-                       else
-                       {
-                               if (type == u.System_Security_SuppressUnmanagedCodeSecurityAttribute)
-                               {
-                                       attribs |= TypeAttributes.HasSecurity;
-                               }
-                               this.ModuleBuilder.SetCustomAttribute(token, customBuilder);
-                       }
-               }
-
-               public void __AddDeclarativeSecurity(CustomAttributeBuilder customBuilder)
-               {
-                       attribs |= TypeAttributes.HasSecurity;
-                       if (declarativeSecurity == null)
-                       {
-                               declarativeSecurity = new List<CustomAttributeBuilder>();
-                       }
-                       declarativeSecurity.Add(customBuilder);
-               }
-
-               public void AddDeclarativeSecurity(System.Security.Permissions.SecurityAction securityAction, System.Security.PermissionSet permissionSet)
-               {
-                       this.ModuleBuilder.AddDeclarativeSecurity(token, securityAction, permissionSet);
-                       this.attribs |= TypeAttributes.HasSecurity;
-               }
-
-               public GenericTypeParameterBuilder[] DefineGenericParameters(params string[] names)
-               {
-                       typeFlags |= TypeFlags.IsGenericTypeDefinition;
-                       gtpb = new GenericTypeParameterBuilder[names.Length];
-                       for (int i = 0; i < names.Length; i++)
-                       {
-                               gtpb[i] = new GenericTypeParameterBuilder(names[i], this, null, i);
-                       }
-                       return (GenericTypeParameterBuilder[])gtpb.Clone();
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       return Util.Copy(gtpb);
-               }
-
-               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       return gtpb == null ? Empty<CustomModifiers>.Array : new CustomModifiers[gtpb.Length];
-               }
-
-               internal override Type GetGenericTypeArgument(int index)
-               {
-                       return gtpb[index];
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get { return gtpb != null; }
-               }
-
-               public override Type GetGenericTypeDefinition()
-               {
-                       return this;
-               }
-
-               public TypeInfo CreateTypeInfo()
-               {
-                       if ((typeFlags & TypeFlags.Baked) != 0)
-                       {
-                               // .NET allows multiple invocations (subsequent invocations return the same baked type)
-                               throw new NotImplementedException();
-                       }
-                       typeFlags |= TypeFlags.Baked;
-                       if (hasLayout)
-                       {
-                               ClassLayoutTable.Record rec = new ClassLayoutTable.Record();
-                               rec.PackingSize = pack;
-                               rec.ClassSize = size;
-                               rec.Parent = token;
-                               this.ModuleBuilder.ClassLayout.AddRecord(rec);
-                       }
-                       bool hasConstructor = false;
-                       foreach (MethodBuilder mb in methods)
-                       {
-                               hasConstructor |= mb.IsSpecialName && mb.Name == ConstructorInfo.ConstructorName;
-                               mb.Bake();
-                       }
-                       if (!hasConstructor && !IsModulePseudoType && !IsInterface && !IsValueType && !(IsAbstract && IsSealed) && Universe.AutomaticallyProvideDefaultConstructor)
-                       {
-                               ((MethodBuilder)DefineDefaultConstructor(MethodAttributes.Public).GetMethodInfo()).Bake();
-                       }
-                       if (declarativeSecurity != null)
-                       {
-                               this.ModuleBuilder.AddDeclarativeSecurity(token, declarativeSecurity);
-                       }
-                       if (!IsModulePseudoType)
-                       {
-                               Type baseType = this.BaseType;
-                               if (baseType != null)
-                               {
-                                       extends = this.ModuleBuilder.GetTypeToken(baseType).Token;
-                               }
-                       }
-                       if (interfaces != null)
-                       {
-                               foreach (Type interfaceType in interfaces)
-                               {
-                                       InterfaceImplTable.Record rec = new InterfaceImplTable.Record();
-                                       rec.Class = token;
-                                       rec.Interface = this.ModuleBuilder.GetTypeToken(interfaceType).Token;
-                                       this.ModuleBuilder.InterfaceImpl.AddRecord(rec);
-                               }
-                       }
-                       return new BakedType(this);
-               }
-
-               public Type CreateType()
-               {
-                       return CreateTypeInfo();
-               }
-
-               internal void PopulatePropertyAndEventTables()
-               {
-                       if (properties != null)
-                       {
-                               PropertyMapTable.Record rec = new PropertyMapTable.Record();
-                               rec.Parent = token;
-                               rec.PropertyList = this.ModuleBuilder.Property.RowCount + 1;
-                               this.ModuleBuilder.PropertyMap.AddRecord(rec);
-                               foreach (PropertyBuilder pb in properties)
-                               {
-                                       pb.Bake();
-                               }
-                       }
-                       if (events != null)
-                       {
-                               EventMapTable.Record rec = new EventMapTable.Record();
-                               rec.Parent = token;
-                               rec.EventList = this.ModuleBuilder.Event.RowCount + 1;
-                               this.ModuleBuilder.EventMap.AddRecord(rec);
-                               foreach (EventBuilder eb in events)
-                               {
-                                       eb.Bake();
-                               }
-                       }
-               }
-
-               public override Type BaseType
-               {
-                       get
-                       {
-                               if (lazyBaseType == null && !IsInterface)
-                               {
-                                       Type obj = Module.universe.System_Object;
-                                       if (this != obj)
-                                       {
-                                               lazyBaseType = obj;
-                                       }
-                               }
-                               return lazyBaseType;
-                       }
-               }
-
-               public override string FullName
-               {
-                       get
-                       {
-                               if (this.IsNested)
-                               {
-                                       return this.DeclaringType.FullName + "+" + TypeNameParser.Escape(name);
-                               }
-                               if (ns == null)
-                               {
-                                       return TypeNameParser.Escape(name);
-                               }
-                               else
-                               {
-                                       return TypeNameParser.Escape(ns) + "." + TypeNameParser.Escape(name);
-                               }
-                       }
-               }
-
-               public override string __Name
-               {
-                       get { return name; }
-               }
-
-               public override string __Namespace
-               {
-                       get { return ns; }
-               }
-
-               public override string Name
-               {
-                       // FXBUG for a TypeBuilder the name is not escaped
-                       get { return name; }
-               }
-
-               public override string Namespace
-               {
-                       get
-                       {
-                               // for some reason, TypeBuilder doesn't return null (and mcs depends on this)
-                               // note also that we don't return the declaring type namespace for nested types
-                               return ns ?? "";
-                       }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return attribs; }
-               }
-
-               public void __SetAttributes(TypeAttributes attributes)
-               {
-                       this.attribs = attributes;
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       return Util.ToArray(interfaces, Type.EmptyTypes);
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       MethodBase[] methods = new MethodBase[this.methods.Count];
-                       for (int i = 0; i < methods.Length; i++)
-                       {
-                               MethodBuilder mb = this.methods[i];
-                               if (mb.IsConstructor)
-                               {
-                                       methods[i] = new ConstructorInfoImpl(mb);
-                               }
-                               else
-                               {
-                                       methods[i] = mb;
-                               }
-                       }
-                       return methods;
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute
-               {
-                       get
-                       {
-                               LayoutKind layout;
-                               switch (attribs & TypeAttributes.LayoutMask)
-                               {
-                                       case TypeAttributes.ExplicitLayout:
-                                               layout = LayoutKind.Explicit;
-                                               break;
-                                       case TypeAttributes.SequentialLayout:
-                                               layout = LayoutKind.Sequential;
-                                               break;
-                                       default:
-                                               layout = LayoutKind.Auto;
-                                               break;
-                               }
-                               StructLayoutAttribute attr = new StructLayoutAttribute(layout);
-                               attr.Pack = (ushort)pack;
-                               attr.Size = size;
-                               switch (attribs & TypeAttributes.StringFormatMask)
-                               {
-                                       case TypeAttributes.AutoClass:
-                                               attr.CharSet = CharSet.Auto;
-                                               break;
-                                       case TypeAttributes.UnicodeClass:
-                                               attr.CharSet = CharSet.Unicode;
-                                               break;
-                                       case TypeAttributes.AnsiClass:
-                                               attr.CharSet = CharSet.Ansi;
-                                               break;
-                                       default:
-                                               attr.CharSet = CharSet.None;
-                                               break;
-                               }
-                               return attr;
-                       }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return owner as TypeBuilder; }
-               }
-
-               public override bool IsGenericType
-               {
-                       get { return IsGenericTypeDefinition; }
-               }
-
-               public override bool IsGenericTypeDefinition
-               {
-                       get { return (typeFlags & TypeFlags.IsGenericTypeDefinition) != 0; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return token; }
-               }
-
-               public FieldBuilder DefineUninitializedData(string name, int size, FieldAttributes attributes)
-               {
-                       return DefineInitializedData(name, new byte[size], attributes);
-               }
-
-               public FieldBuilder DefineInitializedData(string name, byte[] data, FieldAttributes attributes)
-               {
-                       Type fieldType = this.ModuleBuilder.GetType("$ArrayType$" + data.Length);
-                       if (fieldType == null)
-                       {
-                               TypeBuilder tb = this.ModuleBuilder.DefineType("$ArrayType$" + data.Length, TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.ExplicitLayout, this.Module.universe.System_ValueType, PackingSize.Size1, data.Length);
-                               tb.CreateType();
-                               fieldType = tb;
-                       }
-                       FieldBuilder fb = DefineField(name, fieldType, attributes | FieldAttributes.Static);
-                       fb.__SetDataAndRVA(data);
-                       return fb;
-               }
-
-               public static MethodInfo GetMethod(Type type, MethodInfo method)
-               {
-                       return new GenericMethodInstance(type, method, null);
-               }
-
-               public static ConstructorInfo GetConstructor(Type type, ConstructorInfo constructor)
-               {
-                       return new ConstructorInfoImpl(GetMethod(type, constructor.GetMethodInfo()));
-               }
-
-               public static FieldInfo GetField(Type type, FieldInfo field)
-               {
-                       return new GenericFieldInstance(type, field);
-               }
-
-               public override Module Module
-               {
-                       get { return owner.ModuleBuilder; }
-               }
-
-               public TypeToken TypeToken
-               {
-                       get { return new TypeToken(token); }
-               }
-
-               internal void WriteTypeDefRecord(MetadataWriter mw, ref int fieldList, ref int methodList)
-               {
-                       mw.Write((int)attribs);
-                       mw.WriteStringIndex(typeName);
-                       mw.WriteStringIndex(typeNameSpace);
-                       mw.WriteTypeDefOrRef(extends);
-                       mw.WriteField(fieldList);
-                       mw.WriteMethodDef(methodList);
-                       methodList += methods.Count;
-                       fieldList += fields.Count;
-               }
-
-               internal void WriteMethodDefRecords(int baseRVA, MetadataWriter mw, ref int paramList)
-               {
-                       foreach (MethodBuilder mb in methods)
-                       {
-                               mb.WriteMethodDefRecord(baseRVA, mw, ref paramList);
-                       }
-               }
-
-               internal void ResolveMethodAndFieldTokens(ref int methodToken, ref int fieldToken, ref int parameterToken)
-               {
-                       foreach (MethodBuilder method in methods)
-                       {
-                               method.FixupToken(methodToken++, ref parameterToken);
-                       }
-                       foreach (FieldBuilder field in fields)
-                       {
-                               field.FixupToken(fieldToken++);
-                       }
-               }
-
-               internal void WriteParamRecords(MetadataWriter mw)
-               {
-                       foreach (MethodBuilder mb in methods)
-                       {
-                               mb.WriteParamRecords(mw);
-                       }
-               }
-
-               internal void WriteFieldRecords(MetadataWriter mw)
-               {
-                       foreach (FieldBuilder fb in fields)
-                       {
-                               fb.WriteFieldRecords(mw);
-                       }
-               }
-
-               internal ModuleBuilder ModuleBuilder
-               {
-                       get { return owner.ModuleBuilder; }
-               }
-
-               ModuleBuilder ITypeOwner.ModuleBuilder
-               {
-                       get { return owner.ModuleBuilder; }
-               }
-
-               internal override int GetModuleBuilderToken()
-               {
-                       return token;
-               }
-
-               internal bool HasNestedTypes
-               {
-                       get { return (typeFlags & TypeFlags.HasNestedTypes) != 0; }
-               }
-
-               // helper for ModuleBuilder.ResolveMethod()
-               internal MethodBase LookupMethod(int token)
-               {
-                       foreach (MethodBuilder method in methods)
-                       {
-                               if (method.MetadataToken == token)
-                               {
-                                       return method;
-                               }
-                       }
-                       return null;
-               }
-
-               public bool IsCreated()
-               {
-                       return (typeFlags & TypeFlags.Baked) != 0;
-               }
-
-               internal override void CheckBaked()
-               {
-                       if ((typeFlags & TypeFlags.Baked) == 0)
-                       {
-                               throw new NotSupportedException();
-                       }
-               }
-
-               public override Type[] __GetDeclaredTypes()
-               {
-                       if (this.HasNestedTypes)
-                       {
-                               List<Type> types = new List<Type>();
-                               List<int> classes = this.ModuleBuilder.NestedClass.GetNestedClasses(token);
-                               foreach (int nestedClass in classes)
-                               {
-                                       types.Add(this.ModuleBuilder.ResolveType(nestedClass));
-                               }
-                               return types.ToArray();
-                       }
-                       else
-                       {
-                               return Type.EmptyTypes;
-                       }
-               }
-
-               public override FieldInfo[] __GetDeclaredFields()
-               {
-                       return Util.ToArray(fields, Empty<FieldInfo>.Array);
-               }
-
-               public override EventInfo[] __GetDeclaredEvents()
-               {
-                       return Util.ToArray(events, Empty<EventInfo>.Array);
-               }
-
-               public override PropertyInfo[] __GetDeclaredProperties()
-               {
-                       return Util.ToArray(properties, Empty<PropertyInfo>.Array);
-               }
-
-               internal override bool IsModulePseudoType
-               {
-                       get { return token == 0x02000001; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return IsCreated(); }
-               }
-       }
-
-       sealed class BakedType : TypeInfo
-       {
-               internal BakedType(TypeBuilder typeBuilder)
-                       : base(typeBuilder)
-               {
-               }
-
-               public override string AssemblyQualifiedName
-               {
-                       get { return underlyingType.AssemblyQualifiedName; }
-               }
-
-               public override Type BaseType
-               {
-                       get { return underlyingType.BaseType; }
-               }
-
-               public override string __Name
-               {
-                       get { return underlyingType.__Name; }
-               }
-
-               public override string __Namespace
-               {
-                       get { return underlyingType.__Namespace; }
-               }
-
-               public override string Name
-               {
-                       // we need to escape here, because TypeBuilder.Name does not escape
-                       get { return TypeNameParser.Escape(underlyingType.__Name); }
-               }
-
-               public override string FullName
-               {
-                       get { return GetFullName(); }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return underlyingType.Attributes; }
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       return underlyingType.__GetDeclaredInterfaces();
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       return underlyingType.__GetDeclaredMethods();
-               }
-
-               public override __MethodImplMap __GetMethodImplMap()
-               {
-                       return underlyingType.__GetMethodImplMap();
-               }
-
-               public override FieldInfo[] __GetDeclaredFields()
-               {
-                       return underlyingType.__GetDeclaredFields();
-               }
-
-               public override EventInfo[] __GetDeclaredEvents()
-               {
-                       return underlyingType.__GetDeclaredEvents();
-               }
-
-               public override PropertyInfo[] __GetDeclaredProperties()
-               {
-                       return underlyingType.__GetDeclaredProperties();
-               }
-
-               public override Type[] __GetDeclaredTypes()
-               {
-                       return underlyingType.__GetDeclaredTypes();
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return underlyingType.DeclaringType; }
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute
-               {
-                       get { return underlyingType.StructLayoutAttribute; }
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       return underlyingType.GetGenericArguments();
-               }
-
-               internal override Type GetGenericTypeArgument(int index)
-               {
-                       return underlyingType.GetGenericTypeArgument(index);
-               }
-
-               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       return underlyingType.__GetGenericArgumentsCustomModifiers();
-               }
-
-               public override bool IsGenericType
-               {
-                       get { return underlyingType.IsGenericType; }
-               }
-
-               public override bool IsGenericTypeDefinition
-               {
-                       get { return underlyingType.IsGenericTypeDefinition; }
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get { return underlyingType.ContainsGenericParameters; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return underlyingType.MetadataToken; }
-               }
-
-               public override Module Module
-               {
-                       get { return underlyingType.Module; }
-               }
-
-               internal override int GetModuleBuilderToken()
-               {
-                       return underlyingType.GetModuleBuilderToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Enums.cs b/mcs/class/IKVM.Reflection/Enums.cs
deleted file mode 100644 (file)
index 9fcbb6d..0000000
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-
-namespace IKVM.Reflection
-{
-       [Flags]
-       public enum AssemblyNameFlags
-       {
-               None = 0,
-               PublicKey = 1,
-               Retargetable = 256,
-               EnableJITcompileOptimizer = 16384,
-               EnableJITcompileTracking = 32768,
-       }
-
-       public enum AssemblyContentType
-       {
-               Default = 0,
-               WindowsRuntime = 1,
-       }
-
-       [Flags]
-       public enum BindingFlags
-       {
-               Default = 0,
-               IgnoreCase = 1,
-               DeclaredOnly = 2,
-               Instance = 4,
-               Static = 8,
-               Public = 16,
-               NonPublic = 32,
-               FlattenHierarchy = 64,
-       }
-
-       [Flags]
-       public enum CallingConventions
-       {
-               Standard = 1,
-               VarArgs = 2,
-               Any = 3,
-               HasThis = 32,
-               ExplicitThis = 64,
-       }
-
-       [Flags]
-       public enum EventAttributes
-       {
-               None = 0,
-               SpecialName = 512,
-               RTSpecialName = 1024,
-               ReservedMask = 1024,
-       }
-
-       [Flags]
-       public enum FieldAttributes
-       {
-               PrivateScope = 0,
-               Private = 1,
-               FamANDAssem = 2,
-               Assembly = 3,
-               Family = 4,
-               FamORAssem = 5,
-               Public = 6,
-               FieldAccessMask = 7,
-               Static = 16,
-               InitOnly = 32,
-               Literal = 64,
-               NotSerialized = 128,
-               HasFieldRVA = 256,
-               SpecialName = 512,
-               RTSpecialName = 1024,
-               HasFieldMarshal = 4096,
-               PinvokeImpl = 8192,
-               HasDefault = 32768,
-               ReservedMask = 38144,
-       }
-
-       [Flags]
-       public enum GenericParameterAttributes
-       {
-               None = 0,
-               Covariant = 1,
-               Contravariant = 2,
-               VarianceMask = 3,
-               ReferenceTypeConstraint = 4,
-               NotNullableValueTypeConstraint = 8,
-               DefaultConstructorConstraint = 16,
-               SpecialConstraintMask = 28,
-       }
-
-       public enum ImageFileMachine
-       {
-               I386 = 332,
-               ARM = 452,
-               IA64 = 512,
-               AMD64 = 34404,
-       }
-
-       [FlagsAttribute]
-       public enum MemberTypes
-       {
-               Constructor = 0x01,
-               Event = 0x02,
-               Field = 0x04,
-               Method = 0x08,
-               Property = 0x10,
-               TypeInfo = 0x20,
-               Custom = 0x40,
-               NestedType = 0x80,
-               All = Constructor | Event | Field | Method | Property | TypeInfo | NestedType
-       }
-
-       [Flags]
-       public enum MethodAttributes
-       {
-               MemberAccessMask                = 0x0007,
-               PrivateScope                    = 0x0000,
-               Private                                 = 0x0001,
-               FamANDAssem                             = 0x0002,
-               Assembly                                = 0x0003,
-               Family                                  = 0x0004,
-               FamORAssem                              = 0x0005,
-               Public                                  = 0x0006,
-               Static                                  = 0x0010,
-               Final                                   = 0x0020,
-               Virtual                                 = 0x0040,
-               HideBySig                               = 0x0080,
-               VtableLayoutMask                = 0x0100,
-               ReuseSlot                               = 0x0000,
-               NewSlot                                 = 0x0100,
-               CheckAccessOnOverride   = 0x0200,
-               Abstract                                = 0x0400,
-               SpecialName                             = 0x0800,
-
-               PinvokeImpl                             = 0x2000,
-               UnmanagedExport                 = 0x0008,
-
-               RTSpecialName                   = 0x1000,
-               HasSecurity                             = 0x4000,
-               RequireSecObject                = 0x8000,
-
-               ReservedMask                    = 0xd000,
-       }
-
-       [Flags]
-       public enum MethodImplAttributes
-       {
-               CodeTypeMask            = 0x0003,
-               IL                                      = 0x0000,
-               Native                          = 0x0001,
-               OPTIL                           = 0x0002,
-               Runtime                         = 0x0003,
-               ManagedMask                     = 0x0004,
-               Unmanaged                       = 0x0004,
-               Managed                         = 0x0000,
-
-               ForwardRef                      = 0x0010,
-               PreserveSig                     = 0x0080,
-               InternalCall            = 0x1000,
-               Synchronized            = 0x0020,
-               NoInlining                      = 0x0008,
-               NoOptimization          = 0x0040,
-               AggressiveInlining  = 0x0100,
-
-               MaxMethodImplVal        = 0xffff,
-       }
-
-       [Flags]
-       public enum ParameterAttributes
-       {
-               None = 0,
-               In = 1,
-               Out = 2,
-               Lcid = 4,
-               Retval = 8,
-               Optional = 16,
-               HasDefault = 4096,
-               HasFieldMarshal = 8192,
-               Reserved3 = 16384,
-               Reserved4 = 32768,
-               ReservedMask = 61440,
-       }
-
-       [Flags]
-       public enum PortableExecutableKinds
-       {
-               NotAPortableExecutableImage = 0,
-               ILOnly = 1,
-               Required32Bit = 2,
-               PE32Plus = 4,
-               Unmanaged32Bit = 8,
-               Preferred32Bit = 16,
-       }
-
-       public enum ProcessorArchitecture
-       {
-               None = 0,
-               MSIL = 1,
-               X86 = 2,
-               IA64 = 3,
-               Amd64 = 4,
-               Arm = 5,
-               // if an item is added here, make sure to update AssemblyName.ProcessorArchitecture,
-               // AssemblyReader.GetNameImpl() and Fusion.ParseAssemblyName as well
-       }
-
-       [Flags]
-       public enum PropertyAttributes
-       {
-               None = 0,
-               SpecialName = 512,
-               RTSpecialName = 1024,
-               HasDefault = 4096,
-       }
-
-       [Flags]
-       public enum ResourceAttributes
-       {
-               Public = 1,
-               Private = 2,
-       }
-
-       [Flags]
-       public enum ResourceLocation
-       {
-               Embedded = 1,
-               ContainedInAnotherAssembly = 2,
-               ContainedInManifestFile = 4,
-       }
-
-       [Flags]
-       public enum TypeAttributes
-       {
-               AnsiClass = 0,
-               Class = 0,
-               AutoLayout = 0,
-               NotPublic = 0,
-               Public = 1,
-               NestedPublic = 2,
-               NestedPrivate = 3,
-               NestedFamily = 4,
-               NestedAssembly = 5,
-               NestedFamANDAssem = 6,
-               VisibilityMask = 7,
-               NestedFamORAssem = 7,
-               SequentialLayout = 8,
-               ExplicitLayout = 16,
-               LayoutMask = 24,
-               ClassSemanticsMask = 32,
-               Interface = 32,
-               Abstract = 128,
-               Sealed = 256,
-               SpecialName = 1024,
-               RTSpecialName = 2048,
-               Import = 4096,
-               Serializable = 8192,
-               WindowsRuntime = 16384,
-               UnicodeClass = 65536,
-               AutoClass = 131072,
-               CustomFormatClass = 196608,
-               StringFormatMask = 196608,
-               HasSecurity = 262144,
-               ReservedMask = 264192,
-               BeforeFieldInit = 1048576,
-               CustomFormatMask = 12582912,
-       }
-
-       // IKVM.Reflection specific type
-       [Flags]
-       public enum DllCharacteristics
-       {
-               HighEntropyVA = 0x0020,                 // IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA
-               DynamicBase = 0x0040,                   // IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
-               NoSEH = 0x0400,                                 // IMAGE_DLLCHARACTERISTICS_NO_SEH
-               NXCompat = 0x0100,                              // IMAGE_DLLCHARACTERISTICS_NX_COMPAT
-               AppContainer = 0x1000,                  // IMAGE_DLLCHARACTERISTICS_APPCONTAINER
-               TerminalServerAware = 0x8000,   // IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE
-       }
-
-       // IKVM.Reflection specific type
-       [Flags]
-       public enum ImplMapFlags
-       {
-               NoMangle = 0x0001,
-               CharSetMask = 0x0006,
-               CharSetNotSpec = 0x0000,
-               CharSetAnsi = 0x0002,
-               CharSetUnicode = 0x0004,
-               CharSetAuto = 0x0006,
-               SupportsLastError = 0x0040,
-               CallConvMask = 0x0700,
-               CallConvWinapi = 0x0100,
-               CallConvCdecl = 0x0200,
-               CallConvStdcall = 0x0300,
-               CallConvThiscall = 0x0400,
-               CallConvFastcall = 0x0500,
-               // non-standard flags (i.e. CLR specific)
-               BestFitOn = 0x0010,
-               BestFitOff = 0x0020,
-               CharMapErrorOn = 0x1000,
-               CharMapErrorOff = 0x2000,
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/EventInfo.cs b/mcs/class/IKVM.Reflection/EventInfo.cs
deleted file mode 100644 (file)
index d8f3c03..0000000
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace IKVM.Reflection
-{
-       public abstract class EventInfo : MemberInfo
-       {
-               // prevent external subclasses
-               internal EventInfo()
-               {
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return MemberTypes.Event; }
-               }
-
-               public abstract EventAttributes Attributes { get; }
-               public abstract MethodInfo GetAddMethod(bool nonPublic);
-               public abstract MethodInfo GetRaiseMethod(bool nonPublic);
-               public abstract MethodInfo GetRemoveMethod(bool nonPublic);
-               public abstract MethodInfo[] GetOtherMethods(bool nonPublic);
-               public abstract MethodInfo[] __GetMethods();
-               public abstract Type EventHandlerType { get; }
-               internal abstract bool IsPublic { get; }
-               internal abstract bool IsNonPrivate { get; }
-               internal abstract bool IsStatic { get; }
-
-               public bool IsSpecialName
-               {
-                       get { return (Attributes & EventAttributes.SpecialName) != 0; }
-               }
-
-               public MethodInfo GetAddMethod()
-               {
-                       return GetAddMethod(false);
-               }
-
-               public MethodInfo GetRaiseMethod()
-               {
-                       return GetRaiseMethod(false);
-               }
-
-               public MethodInfo GetRemoveMethod()
-               {
-                       return GetRemoveMethod(false);
-               }
-
-               public MethodInfo[] GetOtherMethods()
-               {
-                       return GetOtherMethods(false);
-               }
-
-               public MethodInfo AddMethod
-               {
-                       get { return GetAddMethod(true); }
-               }
-
-               public MethodInfo RaiseMethod
-               {
-                       get { return GetRaiseMethod(true); }
-               }
-
-               public MethodInfo RemoveMethod
-               {
-                       get { return GetRemoveMethod(true); }
-               }
-
-               internal virtual EventInfo BindTypeParameters(Type type)
-               {
-                       return new GenericEventInfo(this.DeclaringType.BindTypeParameters(type), this);
-               }
-
-               public override string ToString()
-               {
-                       return this.DeclaringType.ToString() + " " + Name;
-               }
-
-               internal sealed override bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
-               }
-
-               internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
-               {
-                       return IsNonPrivate
-                               && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       return new EventInfoWithReflectedType(type, this);
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       // events don't have pseudo custom attributes
-                       return null;
-               }
-       }
-
-       sealed class EventInfoWithReflectedType : EventInfo
-       {
-               private readonly Type reflectedType;
-               private readonly EventInfo eventInfo;
-
-               internal EventInfoWithReflectedType(Type reflectedType, EventInfo eventInfo)
-               {
-                       Debug.Assert(reflectedType != eventInfo.DeclaringType);
-                       this.reflectedType = reflectedType;
-                       this.eventInfo = eventInfo;
-               }
-
-               public override EventAttributes Attributes
-               {
-                       get { return eventInfo.Attributes; }
-               }
-
-               public override MethodInfo GetAddMethod(bool nonPublic)
-               {
-                       return SetReflectedType(eventInfo.GetAddMethod(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo GetRaiseMethod(bool nonPublic)
-               {
-                       return SetReflectedType(eventInfo.GetRaiseMethod(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo GetRemoveMethod(bool nonPublic)
-               {
-                       return SetReflectedType(eventInfo.GetRemoveMethod(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo[] GetOtherMethods(bool nonPublic)
-               {
-                       return SetReflectedType(eventInfo.GetOtherMethods(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo[] __GetMethods()
-               {
-                       return SetReflectedType(eventInfo.__GetMethods(), reflectedType);
-               }
-
-               public override Type EventHandlerType
-               {
-                       get { return eventInfo.EventHandlerType; }
-               }
-
-               internal override bool IsPublic
-               {
-                       get { return eventInfo.IsPublic; }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get { return eventInfo.IsNonPrivate; }
-               }
-
-               internal override bool IsStatic
-               {
-                       get { return eventInfo.IsStatic; }
-               }
-
-               internal override EventInfo BindTypeParameters(Type type)
-               {
-                       return eventInfo.BindTypeParameters(type);
-               }
-
-               public override string ToString()
-               {
-                       return eventInfo.ToString();
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return eventInfo.__IsMissing; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return eventInfo.DeclaringType; }
-               }
-
-               public override Type ReflectedType
-               {
-                       get { return reflectedType; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       EventInfoWithReflectedType other = obj as EventInfoWithReflectedType;
-                       return other != null
-                               && other.reflectedType == reflectedType
-                               && other.eventInfo == eventInfo;
-               }
-
-               public override int GetHashCode()
-               {
-                       return reflectedType.GetHashCode() ^ eventInfo.GetHashCode();
-               }
-
-               public override int MetadataToken
-               {
-                       get { return eventInfo.MetadataToken; }
-               }
-
-               public override Module Module
-               {
-                       get { return eventInfo.Module; }
-               }
-
-               public override string Name
-               {
-                       get { return eventInfo.Name; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return eventInfo.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return eventInfo.GetCurrentToken();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/ExceptionHandlingClause.cs b/mcs/class/IKVM.Reflection/ExceptionHandlingClause.cs
deleted file mode 100644 (file)
index 3553f90..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       [Flags]
-       public enum ExceptionHandlingClauseOptions
-       {
-               Clause  = 0x0000,
-               Filter  = 0x0001,
-               Finally = 0x0002,
-               Fault   = 0x0004,
-       }
-
-       public sealed class ExceptionHandlingClause
-       {
-               private readonly int flags;
-               private readonly int tryOffset;
-               private readonly int tryLength;
-               private readonly int handlerOffset;
-               private readonly int handlerLength;
-               private readonly Type catchType;
-               private readonly int filterOffset;
-
-               internal ExceptionHandlingClause(ModuleReader module, int flags, int tryOffset, int tryLength, int handlerOffset, int handlerLength, int classTokenOrfilterOffset, IGenericContext context)
-               {
-                       this.flags = flags;
-                       this.tryOffset = tryOffset;
-                       this.tryLength = tryLength;
-                       this.handlerOffset = handlerOffset;
-                       this.handlerLength = handlerLength;
-                       this.catchType = flags == (int)ExceptionHandlingClauseOptions.Clause && classTokenOrfilterOffset != 0 ? module.ResolveType(classTokenOrfilterOffset, context) : null;
-                       this.filterOffset = flags == (int)ExceptionHandlingClauseOptions.Filter ? classTokenOrfilterOffset : 0;
-               }
-
-               public Type CatchType
-               {
-                       get { return catchType; }
-               }
-
-               public int FilterOffset
-               {
-                       get { return filterOffset; }
-               }
-
-               public ExceptionHandlingClauseOptions Flags
-               {
-                       get { return (ExceptionHandlingClauseOptions)flags; }
-               }
-
-               public int HandlerLength
-               {
-                       get { return handlerLength; }
-               }
-
-               public int HandlerOffset
-               {
-                       get { return handlerOffset; }
-               }
-
-               public int TryLength
-               {
-                       get { return tryLength; }
-               }
-
-               public int TryOffset
-               {
-                       get { return tryOffset; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/FieldInfo.cs b/mcs/class/IKVM.Reflection/FieldInfo.cs
deleted file mode 100644 (file)
index 92f8909..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace IKVM.Reflection
-{
-       public abstract class FieldInfo : MemberInfo
-       {
-               // prevent external subclasses
-               internal FieldInfo()
-               {
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return MemberTypes.Field; }
-               }
-
-               public abstract FieldAttributes Attributes { get; }
-               public abstract void __GetDataFromRVA(byte[] data, int offset, int length);
-               public abstract int __FieldRVA { get; }
-               public abstract Object GetRawConstantValue();
-               internal abstract FieldSignature FieldSignature { get; }
-
-               public Type FieldType
-               {
-                       get { return this.FieldSignature.FieldType; }
-               }
-
-               public CustomModifiers __GetCustomModifiers()
-               {
-                       return this.FieldSignature.GetCustomModifiers();
-               }
-
-               public Type[] GetOptionalCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetOptional();
-               }
-
-               public Type[] GetRequiredCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetRequired();
-               }
-
-               public bool IsStatic
-               {
-                       get { return (Attributes & FieldAttributes.Static) != 0; }
-               }
-
-               public bool IsLiteral
-               {
-                       get { return (Attributes & FieldAttributes.Literal) != 0; }
-               }
-
-               public bool IsInitOnly
-               {
-                       get { return (Attributes & FieldAttributes.InitOnly) != 0; }
-               }
-
-               public bool IsNotSerialized
-               {
-                       get { return (Attributes & FieldAttributes.NotSerialized) != 0; }
-               }
-
-               public bool IsSpecialName
-               {
-                       get { return (Attributes & FieldAttributes.SpecialName) != 0; }
-               }
-
-               public bool IsPublic
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public; }
-               }
-
-               public bool IsPrivate
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private; }
-               }
-
-               public bool IsFamily
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Family; }
-               }
-
-               public bool IsFamilyOrAssembly
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamORAssem; }
-               }
-
-               public bool IsAssembly
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Assembly; }
-               }
-
-               public bool IsFamilyAndAssembly
-               {
-                       get { return (Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.FamANDAssem; }
-               }
-
-               public bool IsPinvokeImpl
-               {
-                       get { return (Attributes & FieldAttributes.PinvokeImpl) != 0; }
-               }
-
-               public virtual FieldInfo __GetFieldOnTypeDefinition()
-               {
-                       return this;
-               }
-
-               public abstract bool __TryGetFieldOffset(out int offset);
-
-               public bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-               {
-                       return FieldMarshal.ReadFieldMarshal(this.Module, GetCurrentToken(), out fieldMarshal);
-               }
-
-               internal abstract int ImportTo(Emit.ModuleBuilder module);
-
-               internal virtual FieldInfo BindTypeParameters(Type type)
-               {
-                       return new GenericFieldInstance(this.DeclaringType.BindTypeParameters(type), this);
-               }
-
-               internal sealed override bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
-               }
-
-               internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
-               {
-                       return (Attributes & FieldAttributes.FieldAccessMask) > FieldAttributes.Private
-                               && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       return new FieldInfoWithReflectedType(type, this);
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       Module module = this.Module;
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       if (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_MarshalAsAttribute))
-                       {
-                               FieldMarshal spec;
-                               if (__TryGetFieldMarshal(out spec))
-                               {
-                                       list.Add(CustomAttributeData.CreateMarshalAsPseudoCustomAttribute(module, spec));
-                               }
-                       }
-                       if (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_FieldOffsetAttribute))
-                       {
-                               int offset;
-                               if (__TryGetFieldOffset(out offset))
-                               {
-                                       list.Add(CustomAttributeData.CreateFieldOffsetPseudoCustomAttribute(module, offset));
-                               }
-                       }
-                       return list;
-               }
-       }
-
-       sealed class FieldInfoWithReflectedType : FieldInfo
-       {
-               private readonly Type reflectedType;
-               private readonly FieldInfo field;
-
-               internal FieldInfoWithReflectedType(Type reflectedType, FieldInfo field)
-               {
-                       Debug.Assert(reflectedType != field.DeclaringType);
-                       this.reflectedType = reflectedType;
-                       this.field = field;
-               }
-
-               public override FieldAttributes Attributes
-               {
-                       get { return field.Attributes; }
-               }
-
-               public override void __GetDataFromRVA(byte[] data, int offset, int length)
-               {
-                       field.__GetDataFromRVA(data, offset, length);
-               }
-
-               public override int __FieldRVA
-               {
-                       get { return field.__FieldRVA; }
-               }
-
-               public override bool __TryGetFieldOffset(out int offset)
-               {
-                       return field.__TryGetFieldOffset(out offset);
-               }
-
-               public override Object GetRawConstantValue()
-               {
-                       return field.GetRawConstantValue();
-               }
-
-               internal override FieldSignature FieldSignature
-               {
-                       get { return field.FieldSignature; }
-               }
-
-               public override FieldInfo __GetFieldOnTypeDefinition()
-               {
-                       return field.__GetFieldOnTypeDefinition();
-               }
-
-               internal override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       return field.ImportTo(module);
-               }
-
-               internal override FieldInfo BindTypeParameters(Type type)
-               {
-                       return field.BindTypeParameters(type);
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return field.__IsMissing; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return field.DeclaringType; }
-               }
-
-               public override Type ReflectedType
-               {
-                       get { return reflectedType; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       FieldInfoWithReflectedType other = obj as FieldInfoWithReflectedType;
-                       return other != null
-                               && other.reflectedType == reflectedType
-                               && other.field == field;
-               }
-
-               public override int GetHashCode()
-               {
-                       return reflectedType.GetHashCode() ^ field.GetHashCode();
-               }
-
-               public override int MetadataToken
-               {
-                       get { return field.MetadataToken; }
-               }
-
-               public override Module Module
-               {
-                       get { return field.Module; }
-               }
-
-               public override string Name
-               {
-                       get { return field.Name; }
-               }
-
-               public override string ToString()
-               {
-                       return field.ToString();
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return field.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return field.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/FieldSignature.cs b/mcs/class/IKVM.Reflection/FieldSignature.cs
deleted file mode 100644 (file)
index 481fc61..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       sealed class FieldSignature : Signature
-       {
-               private readonly Type fieldType;
-               private readonly CustomModifiers mods;
-
-               internal static FieldSignature Create(Type fieldType, CustomModifiers customModifiers)
-               {
-                       return new FieldSignature(fieldType, customModifiers);
-               }
-
-               private FieldSignature(Type fieldType, CustomModifiers mods)
-               {
-                       this.fieldType = fieldType;
-                       this.mods = mods;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       FieldSignature other = obj as FieldSignature;
-                       return other != null
-                               && other.fieldType.Equals(fieldType)
-                               && other.mods.Equals(mods);
-               }
-
-               public override int GetHashCode()
-               {
-                       return fieldType.GetHashCode() ^ mods.GetHashCode();
-               }
-
-               internal Type FieldType
-               {
-                       get { return fieldType; }
-               }
-
-               internal CustomModifiers GetCustomModifiers()
-               {
-                       return mods;
-               }
-
-               internal FieldSignature ExpandTypeParameters(Type declaringType)
-               {
-                       return new FieldSignature(
-                               fieldType.BindTypeParameters(declaringType),
-                               mods.Bind(declaringType));
-               }
-
-               internal static FieldSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       if (br.ReadByte() != FIELD)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       CustomModifiers mods = CustomModifiers.Read(module, br, context);
-                       Type fieldType = ReadType(module, br, context);
-                       return new FieldSignature(fieldType, mods);
-               }
-
-               internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
-               {
-                       bb.Write(FIELD);
-                       WriteCustomModifiers(module, bb, mods);
-                       WriteType(module, bb, fieldType);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Fusion.cs b/mcs/class/IKVM.Reflection/Fusion.cs
deleted file mode 100644 (file)
index 0d0f8ec..0000000
+++ /dev/null
@@ -1,527 +0,0 @@
-/*
-  Copyright (C) 2010-2012 Jeroen Frijters
-  Copyright (C) 2011 Marek Safar
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       struct ParsedAssemblyName
-       {
-               internal string Name;
-               internal Version Version;
-               internal string Culture;
-               internal string PublicKeyToken;
-               internal bool? Retargetable;
-               internal ProcessorArchitecture ProcessorArchitecture;
-               internal bool HasPublicKey;
-               internal bool WindowsRuntime;
-       }
-
-       enum ParseAssemblyResult
-       {
-               OK,
-               GenericError,
-               DuplicateKey,
-       }
-
-       static class Fusion
-       {
-               internal static bool CompareAssemblyIdentityNative(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
-               {
-                       bool equivalent;
-                       Marshal.ThrowExceptionForHR(CompareAssemblyIdentity(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out equivalent, out result));
-                       return equivalent;
-               }
-
-               [DllImport("fusion", CharSet = CharSet.Unicode)]
-               private static extern int CompareAssemblyIdentity(string pwzAssemblyIdentity1, bool fUnified1, string pwzAssemblyIdentity2, bool fUnified2, out bool pfEquivalent, out AssemblyComparisonResult pResult);
-
-               // internal for use by mcs
-               internal static bool CompareAssemblyIdentityPure(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
-               {
-                       ParsedAssemblyName name1;
-                       ParsedAssemblyName name2;
-
-                       ParseAssemblyResult r = ParseAssemblyName(assemblyIdentity1, out name1);
-                       if (r != ParseAssemblyResult.OK || (r = ParseAssemblyName(assemblyIdentity2, out name2)) != ParseAssemblyResult.OK)
-                       {
-                               result = AssemblyComparisonResult.NonEquivalent;
-                               switch (r)
-                               {
-                                       case ParseAssemblyResult.DuplicateKey:
-                                               throw new System.IO.FileLoadException();
-                                       case ParseAssemblyResult.GenericError:
-                                       default:
-                                               throw new ArgumentException();
-                               }
-                       }
-
-                       bool partial = IsPartial(name1);
-
-                       if ((partial && unified1) || IsPartial(name2))
-                       {
-                               result = AssemblyComparisonResult.NonEquivalent;
-                               throw new ArgumentException();
-                       }
-                       if (!name1.Name.Equals(name2.Name, StringComparison.InvariantCultureIgnoreCase))
-                       {
-                               result = AssemblyComparisonResult.NonEquivalent;
-                               return false;
-                       }
-                       if (name1.Name.Equals("mscorlib", StringComparison.InvariantCultureIgnoreCase))
-                       {
-                               result = AssemblyComparisonResult.EquivalentFullMatch;
-                               return true;
-                       }
-                       if (partial && name1.Culture == null)
-                       {
-                       }
-                       else if (!name1.Culture.Equals(name2.Culture, StringComparison.InvariantCultureIgnoreCase))
-                       {
-                               result = AssemblyComparisonResult.NonEquivalent;
-                               return false;
-                       }
-                       if (IsStrongNamed(name2))
-                       {
-                               if (partial && name1.PublicKeyToken == null)
-                               {
-                               }
-                               else if (name1.PublicKeyToken != name2.PublicKeyToken)
-                               {
-                                       result = AssemblyComparisonResult.NonEquivalent;
-                                       return false;
-                               }
-                               if (partial && name1.Version == null)
-                               {
-                                       result = AssemblyComparisonResult.EquivalentPartialMatch;
-                                       return true;
-                               }
-                               else if (IsFrameworkAssembly(name2))
-                               {
-                                       result = partial ? AssemblyComparisonResult.EquivalentPartialFXUnified : AssemblyComparisonResult.EquivalentFXUnified;
-                                       return true;
-                               }
-                               else if (name1.Version.Revision == -1 || name2.Version.Revision == -1)
-                               {
-                                       result = AssemblyComparisonResult.NonEquivalent;
-                                       throw new ArgumentException();
-                               }
-                               else if (name1.Version < name2.Version)
-                               {
-                                       if (unified2)
-                                       {
-                                               result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
-                                               return true;
-                                       }
-                                       else
-                                       {
-                                               result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
-                                               return false;
-                                       }
-                               }
-                               else if (name1.Version > name2.Version)
-                               {
-                                       if (unified1)
-                                       {
-                                               result = partial ? AssemblyComparisonResult.EquivalentPartialUnified : AssemblyComparisonResult.EquivalentUnified;
-                                               return true;
-                                       }
-                                       else
-                                       {
-                                               result = partial ? AssemblyComparisonResult.NonEquivalentPartialVersion : AssemblyComparisonResult.NonEquivalentVersion;
-                                               return false;
-                                       }
-                               }
-                               else
-                               {
-                                       result = partial ? AssemblyComparisonResult.EquivalentPartialMatch : AssemblyComparisonResult.EquivalentFullMatch;
-                                       return true;
-                               }
-                       }
-                       else if (IsStrongNamed(name1))
-                       {
-                               result = AssemblyComparisonResult.NonEquivalent;
-                               return false;
-                       }
-                       else
-                       {
-                               result = partial ? AssemblyComparisonResult.EquivalentPartialWeakNamed : AssemblyComparisonResult.EquivalentWeakNamed;
-                               return true;
-                       }
-               }
-
-               static bool IsFrameworkAssembly(ParsedAssemblyName name)
-               {
-                       // A list of FX assemblies which require some form of remapping
-                       // When 4.0 + 1 version  is release, assemblies introduced in v4.0
-                       // will have to be added
-                       switch (name.Name)
-                       {
-                               case "System":
-                               case "System.Core":
-                               case "System.Data":
-                               case "System.Data.DataSetExtensions":
-                               case "System.Data.Linq":
-                               case "System.Data.OracleClient":
-                               case "System.Data.Services":
-                               case "System.Data.Services.Client":
-                               case "System.IdentityModel":
-                               case "System.IdentityModel.Selectors":
-                               case "System.Runtime.Remoting":
-                               case "System.Runtime.Serialization":
-                               case "System.ServiceModel":
-                               case "System.Transactions":
-                               case "System.Windows.Forms":
-                               case "System.Xml":
-                               case "System.Xml.Linq":
-                                       return name.PublicKeyToken == "b77a5c561934e089";
-
-                               case "System.Configuration":
-                               case "System.Configuration.Install":
-                               case "System.Design":
-                               case "System.DirectoryServices":
-                               case "System.Drawing":
-                               case "System.Drawing.Design":
-                               case "System.EnterpriseServices":
-                               case "System.Management":
-                               case "System.Messaging":
-                               case "System.Runtime.Serialization.Formatters.Soap":
-                               case "System.Security":
-                               case "System.ServiceProcess":
-                               case "System.Web":
-                               case "System.Web.Mobile":
-                               case "System.Web.Services":
-                                       return name.PublicKeyToken == "b03f5f7f11d50a3a";
-
-                               case "System.ComponentModel.DataAnnotations":
-                               case "System.ServiceModel.Web":
-                               case "System.Web.Abstractions":
-                               case "System.Web.Extensions":
-                               case "System.Web.Extensions.Design":
-                               case "System.Web.DynamicData":
-                               case "System.Web.Routing":
-                                       return name.PublicKeyToken == "31bf3856ad364e35";
-                       }
-
-                       return false;
-               }
-
-               internal static ParseAssemblyResult ParseAssemblySimpleName(string fullName, out int pos, out string simpleName)
-               {
-                       StringBuilder sb = new StringBuilder();
-                       pos = 0;
-                       simpleName = null;
-                       while (pos < fullName.Length && char.IsWhiteSpace(fullName[pos]))
-                       {
-                               pos++;
-                       }
-                       char quoteOrComma = ',';
-                       if (pos < fullName.Length && (fullName[pos] == '\"' || fullName[pos] == '\''))
-                       {
-                               quoteOrComma = fullName[pos++];
-                       }
-                       while (pos < fullName.Length)
-                       {
-                               char ch = fullName[pos++];
-                               if (ch == '\\')
-                               {
-                                       if (pos == fullName.Length)
-                                       {
-                                               return ParseAssemblyResult.GenericError;
-                                       }
-                                       ch = fullName[pos++];
-                                       if (ch == '\\')
-                                       {
-                                               return ParseAssemblyResult.GenericError;
-                                       }
-                               }
-                               else if (ch == quoteOrComma)
-                               {
-                                       if (ch != ',')
-                                       {
-                                               while (pos != fullName.Length)
-                                               {
-                                                       ch = fullName[pos++];
-                                                       if (ch == ',')
-                                                       {
-                                                               break;
-                                                       }
-                                                       if (!char.IsWhiteSpace(ch))
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                               }
-                                       }
-                                       break;
-                               }
-                               else if (ch == '=' || (quoteOrComma == ',' && (ch == '\'' || ch == '"')))
-                               {
-                                       return ParseAssemblyResult.GenericError;
-                               }
-                               sb.Append(ch);
-                       }
-                       simpleName = sb.ToString().Trim();
-                       if (simpleName.Length == 0)
-                       {
-                               return ParseAssemblyResult.GenericError;
-                       }
-                       if (pos == fullName.Length && fullName[fullName.Length - 1] == ',')
-                       {
-                               return ParseAssemblyResult.GenericError;
-                       }
-                       return ParseAssemblyResult.OK;
-               }
-
-               internal static ParseAssemblyResult ParseAssemblyName(string fullName, out ParsedAssemblyName parsedName)
-               {
-                       parsedName = new ParsedAssemblyName();
-                       int pos;
-                       ParseAssemblyResult res = ParseAssemblySimpleName(fullName, out pos, out parsedName.Name);
-                       if (res != ParseAssemblyResult.OK || pos == fullName.Length)
-                       {
-                               return res;
-                       }
-                       else
-                       {
-                               System.Collections.Generic.Dictionary<string, string> unknownAttributes = null;
-                               bool hasProcessorArchitecture = false;
-                               bool hasContentType = false;
-                               string[] parts = fullName.Substring(pos).Split(',');
-                               for (int i = 0; i < parts.Length; i++)
-                               {
-                                       string[] kv = parts[i].Split('=');
-                                       if (kv.Length != 2)
-                                       {
-                                               return ParseAssemblyResult.GenericError;
-                                       }
-                                       switch (kv[0].Trim().ToLowerInvariant())
-                                       {
-                                               case "version":
-                                                       if (parsedName.Version != null)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       if (!ParseVersion(kv[1].Trim(), out parsedName.Version))
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       break;
-                                               case "culture":
-                                                       if (parsedName.Culture != null)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       if (!ParseCulture(kv[1].Trim(), out parsedName.Culture))
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       break;
-                                               case "publickeytoken":
-                                                       if (parsedName.PublicKeyToken != null)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       if (!ParsePublicKeyToken(kv[1].Trim(), out parsedName.PublicKeyToken))
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       break;
-                                               case "publickey":
-                                                       if (parsedName.PublicKeyToken != null)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       if (!ParsePublicKey(kv[1].Trim(), out parsedName.PublicKeyToken))
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       parsedName.HasPublicKey = true;
-                                                       break;
-                                               case "retargetable":
-                                                       if (parsedName.Retargetable.HasValue)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       switch (kv[1].Trim().ToLowerInvariant())
-                                                       {
-                                                               case "yes":
-                                                                       parsedName.Retargetable = true;
-                                                                       break;
-                                                               case "no":
-                                                                       parsedName.Retargetable = false;
-                                                                       break;
-                                                               default:
-                                                                       return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       break;
-                                               case "processorarchitecture":
-                                                       if (hasProcessorArchitecture)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       hasProcessorArchitecture = true;
-                                                       switch (kv[1].Trim().ToLowerInvariant())
-                                                       {
-                                                               case "none":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.None;
-                                                                       break;
-                                                               case "msil":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.MSIL;
-                                                                       break;
-                                                               case "x86":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.X86;
-                                                                       break;
-                                                               case "ia64":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.IA64;
-                                                                       break;
-                                                               case "amd64":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.Amd64;
-                                                                       break;
-                                                               case "arm":
-                                                                       parsedName.ProcessorArchitecture = ProcessorArchitecture.Arm;
-                                                                       break;
-                                                               default:
-                                                                       return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       break;
-                                               case "contenttype":
-                                                       if (hasContentType)
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       hasContentType = true;
-                                                       if (kv[1].Trim().ToLowerInvariant() != "windowsruntime")
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       parsedName.WindowsRuntime = true;
-                                                       break;
-                                               default:
-                                                       if (kv[1].Trim() == "")
-                                                       {
-                                                               return ParseAssemblyResult.GenericError;
-                                                       }
-                                                       if (unknownAttributes == null)
-                                                       {
-                                                               unknownAttributes = new System.Collections.Generic.Dictionary<string, string>();
-                                                       }
-                                                       if (unknownAttributes.ContainsKey(kv[0].Trim().ToLowerInvariant()))
-                                                       {
-                                                               return ParseAssemblyResult.DuplicateKey;
-                                                       }
-                                                       unknownAttributes.Add(kv[0].Trim().ToLowerInvariant(), null);
-                                                       break;
-                                       }
-                               }
-                       }
-                       return ParseAssemblyResult.OK;
-               }
-
-               private static bool ParseVersion(string str, out Version version)
-               {
-                       string[] parts = str.Split('.');
-                       if (parts.Length < 2 || parts.Length > 4)
-                       {
-                               version = null;
-                               ushort dummy;
-                               // if the version consists of a single integer, it is invalid, but not invalid enough to fail the parse of the whole assembly name
-                               return parts.Length == 1 && ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out dummy);
-                       }
-                       if (parts[0] == "" || parts[1] == "")
-                       {
-                               // this is a strange scenario, the version is invalid, but not invalid enough to fail the parse of the whole assembly name
-                               version = null;
-                               return true;
-                       }
-                       ushort major, minor, build = 65535, revision = 65535;
-                       if (ushort.TryParse(parts[0], System.Globalization.NumberStyles.Integer, null, out major)
-                               && ushort.TryParse(parts[1], System.Globalization.NumberStyles.Integer, null, out minor)
-                               && (parts.Length <= 2 || parts[2] == "" || ushort.TryParse(parts[2], System.Globalization.NumberStyles.Integer, null, out build))
-                               && (parts.Length <= 3 || parts[3] == "" || (parts[2] != "" && ushort.TryParse(parts[3], System.Globalization.NumberStyles.Integer, null, out revision))))
-                       {
-                               if (parts.Length == 4 && parts[3] != "" && parts[2] != "")
-                               {
-                                       version = new Version(major, minor, build, revision);
-                               }
-                               else if (parts.Length == 3 && parts[2] != "")
-                               {
-                                       version = new Version(major, minor, build);
-                               }
-                               else
-                               {
-                                       version = new Version(major, minor);
-                               }
-                               return true;
-                       }
-                       version = null;
-                       return false;
-               }
-
-               private static bool ParseCulture(string str, out string culture)
-               {
-                       if (str == null)
-                       {
-                               culture = null;
-                               return false;
-                       }
-                       culture = str;
-                       return true;
-               }
-
-               private static bool ParsePublicKeyToken(string str, out string publicKeyToken)
-               {
-                       if (str == null)
-                       {
-                               publicKeyToken = null;
-                               return false;
-                       }
-                       publicKeyToken = str.ToLowerInvariant();
-                       return true;
-               }
-
-               private static bool ParsePublicKey(string str, out string publicKeyToken)
-               {
-                       if (str == null)
-                       {
-                               publicKeyToken = null;
-                               return false;
-                       }
-                       publicKeyToken = AssemblyName.ComputePublicKeyToken(str);
-                       return true;
-               }
-
-               private static bool IsPartial(ParsedAssemblyName name)
-               {
-                       return name.Version == null || name.Culture == null || name.PublicKeyToken == null;
-               }
-
-               private static bool IsStrongNamed(ParsedAssemblyName name)
-               {
-                       return name.PublicKeyToken != null && name.PublicKeyToken != "null";
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/GenericWrappers.cs b/mcs/class/IKVM.Reflection/GenericWrappers.cs
deleted file mode 100644 (file)
index 1122ff2..0000000
+++ /dev/null
@@ -1,694 +0,0 @@
-/*
-  Copyright (C) 2009, 2010 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       // this represents both generic method instantiations and non-generic methods on generic type instantations
-       // (this means that it can be a generic method declaration as well as a generic method instance)
-       sealed class GenericMethodInstance : MethodInfo
-       {
-               private readonly Type declaringType;
-               private readonly MethodInfo method;
-               private readonly Type[] methodArgs;
-               private MethodSignature lazyMethodSignature;
-
-               internal GenericMethodInstance(Type declaringType, MethodInfo method, Type[] methodArgs)
-               {
-                       System.Diagnostics.Debug.Assert(!(method is GenericMethodInstance));
-                       this.declaringType = declaringType;
-                       this.method = method;
-                       this.methodArgs = methodArgs;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       GenericMethodInstance other = obj as GenericMethodInstance;
-                       return other != null
-                               && other.method.Equals(method)
-                               && other.declaringType.Equals(declaringType)
-                               && Util.ArrayEquals(other.methodArgs, methodArgs);
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() * 33 ^ method.GetHashCode() ^ Util.GetHashCode(methodArgs);
-               }
-
-               public override Type ReturnType
-               {
-                       get { return method.ReturnType.BindTypeParameters(this); }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get { return new GenericParameterInfoImpl(this, method.ReturnParameter); }
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameters = method.GetParameters();
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new GenericParameterInfoImpl(this, parameters[i]);
-                       }
-                       return parameters;
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return method.ParameterCount; }
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return method.CallingConvention; }
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return method.Attributes; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return method.GetMethodImplementationFlags();
-               }
-
-               public override string Name
-               {
-                       get { return method.Name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType.IsModulePseudoType ? null : declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return method.Module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return method.MetadataToken; }
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       IKVM.Reflection.Reader.MethodDefImpl md = method as IKVM.Reflection.Reader.MethodDefImpl;
-                       if (md != null)
-                       {
-                               return md.GetMethodBody(this);
-                       }
-                       throw new NotSupportedException();
-               }
-
-               public override int __MethodRVA
-               {
-                       get { return method.__MethodRVA; }
-               }
-
-               public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       return new GenericMethodInstance(declaringType, method, typeArguments);
-               }
-
-               public override bool IsGenericMethod
-               {
-                       get { return method.IsGenericMethod; }
-               }
-
-               public override bool IsGenericMethodDefinition
-               {
-                       get { return method.IsGenericMethodDefinition && methodArgs == null; }
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get
-                       {
-                               if (declaringType.ContainsGenericParameters)
-                               {
-                                       return true;
-                               }
-                               if (methodArgs != null)
-                               {
-                                       foreach (Type type in methodArgs)
-                                       {
-                                               if (type.ContainsGenericParameters)
-                                               {
-                                                       return true;
-                                               }
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               public override MethodInfo GetGenericMethodDefinition()
-               {
-                       if (this.IsGenericMethod)
-                       {
-                               if (this.IsGenericMethodDefinition)
-                               {
-                                       return this;
-                               }
-                               else if (declaringType.IsConstructedGenericType)
-                               {
-                                       return new GenericMethodInstance(declaringType, method, null);
-                               }
-                               else
-                               {
-                                       return method;
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               public override MethodBase __GetMethodOnTypeDefinition()
-               {
-                       return method;
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       if (methodArgs == null)
-                       {
-                               return method.GetGenericArguments();
-                       }
-                       else
-                       {
-                               return (Type[])methodArgs.Clone();
-                       }
-               }
-
-               internal override Type GetGenericMethodArgument(int index)
-               {
-                       if (methodArgs == null)
-                       {
-                               return method.GetGenericMethodArgument(index);
-                       }
-                       else
-                       {
-                               return methodArgs[index];
-                       }
-               }
-
-               internal override int GetGenericMethodArgumentCount()
-               {
-                       return method.GetGenericMethodArgumentCount();
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return method.GetMethodOnTypeDefinition();
-               }
-
-               internal override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       if (methodArgs == null)
-                       {
-                               return module.ImportMethodOrField(declaringType, method.Name, method.MethodSignature);
-                       }
-                       else
-                       {
-                               return module.ImportMethodSpec(declaringType, method, methodArgs);
-                       }
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get { return lazyMethodSignature ?? (lazyMethodSignature = method.MethodSignature.Bind(declaringType, methodArgs)); }
-               }
-
-               internal override MethodBase BindTypeParameters(Type type)
-               {
-                       System.Diagnostics.Debug.Assert(methodArgs == null);
-                       return new GenericMethodInstance(declaringType.BindTypeParameters(type), method, null);
-               }
-
-               internal override bool HasThis
-               {
-                       get { return method.HasThis; }
-               }
-
-               public override MethodInfo[] __GetMethodImpls()
-               {
-                       MethodInfo[] methods = method.__GetMethodImpls();
-                       for (int i = 0; i < methods.Length; i++)
-                       {
-                               methods[i] = (MethodInfo)methods[i].BindTypeParameters(declaringType);
-                       }
-                       return methods;
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return method.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return method.IsBaked; }
-               }
-       }
-
-       sealed class GenericFieldInstance : FieldInfo
-       {
-               private readonly Type declaringType;
-               private readonly FieldInfo field;
-
-               internal GenericFieldInstance(Type declaringType, FieldInfo field)
-               {
-                       this.declaringType = declaringType;
-                       this.field = field;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       GenericFieldInstance other = obj as GenericFieldInstance;
-                       return other != null && other.declaringType.Equals(declaringType) && other.field.Equals(field);
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() * 3 ^ field.GetHashCode();
-               }
-
-               public override FieldAttributes Attributes
-               {
-                       get { return field.Attributes; }
-               }
-
-               public override string Name
-               {
-                       get { return field.Name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return declaringType.Module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return field.MetadataToken; }
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return field.GetRawConstantValue();
-               }
-
-               public override void __GetDataFromRVA(byte[] data, int offset, int length)
-               {
-                       field.__GetDataFromRVA(data, offset, length);
-               }
-
-               public override int __FieldRVA
-               {
-                       get { return field.__FieldRVA; }
-               }
-
-               public override bool __TryGetFieldOffset(out int offset)
-               {
-                       return field.__TryGetFieldOffset(out offset);
-               }
-
-               public override FieldInfo __GetFieldOnTypeDefinition()
-               {
-                       return field;
-               }
-
-               internal override FieldSignature FieldSignature
-               {
-                       get { return field.FieldSignature.ExpandTypeParameters(declaringType); }
-               }
-
-               internal override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       return module.ImportMethodOrField(declaringType, field.Name, field.FieldSignature);
-               }
-
-               internal override FieldInfo BindTypeParameters(Type type)
-               {
-                       return new GenericFieldInstance(declaringType.BindTypeParameters(type), field);
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return field.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return field.IsBaked; }
-               }
-       }
-
-       sealed class GenericParameterInfoImpl : ParameterInfo
-       {
-               private readonly GenericMethodInstance method;
-               private readonly ParameterInfo parameterInfo;
-
-               internal GenericParameterInfoImpl(GenericMethodInstance method, ParameterInfo parameterInfo)
-               {
-                       this.method = method;
-                       this.parameterInfo = parameterInfo;
-               }
-
-               public override string Name
-               {
-                       get { return parameterInfo.Name; }
-               }
-
-               public override Type ParameterType
-               {
-                       get { return parameterInfo.ParameterType.BindTypeParameters(method); }
-               }
-
-               public override ParameterAttributes Attributes
-               {
-                       get { return parameterInfo.Attributes; }
-               }
-
-               public override int Position
-               {
-                       get { return parameterInfo.Position; }
-               }
-
-               public override object RawDefaultValue
-               {
-                       get { return parameterInfo.RawDefaultValue; }
-               }
-
-               public override CustomModifiers __GetCustomModifiers()
-               {
-                       return parameterInfo.__GetCustomModifiers().Bind(method);
-               }
-
-               public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-               {
-                       return parameterInfo.__TryGetFieldMarshal(out fieldMarshal);
-               }
-
-               public override MemberInfo Member
-               {
-                       get { return method; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return parameterInfo.MetadataToken; }
-               }
-
-               internal override Module Module
-               {
-                       get { return method.Module; }
-               }
-       }
-
-       sealed class GenericPropertyInfo : PropertyInfo
-       {
-               private readonly Type typeInstance;
-               private readonly PropertyInfo property;
-
-               internal GenericPropertyInfo(Type typeInstance, PropertyInfo property)
-               {
-                       this.typeInstance = typeInstance;
-                       this.property = property;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       GenericPropertyInfo other = obj as GenericPropertyInfo;
-                       return other != null && other.typeInstance == typeInstance && other.property == property;
-               }
-
-               public override int GetHashCode()
-               {
-                       return typeInstance.GetHashCode() * 537 + property.GetHashCode();
-               }
-
-               public override PropertyAttributes Attributes
-               {
-                       get { return property.Attributes; }
-               }
-
-               public override bool CanRead
-               {
-                       get { return property.CanRead; }
-               }
-
-               public override bool CanWrite
-               {
-                       get { return property.CanWrite; }
-               }
-
-               private MethodInfo Wrap(MethodInfo method)
-               {
-                       if (method == null)
-                       {
-                               return null;
-                       }
-                       return new GenericMethodInstance(typeInstance, method, null);
-               }
-
-               public override MethodInfo GetGetMethod(bool nonPublic)
-               {
-                       return Wrap(property.GetGetMethod(nonPublic));
-               }
-
-               public override MethodInfo GetSetMethod(bool nonPublic)
-               {
-                       return Wrap(property.GetSetMethod(nonPublic));
-               }
-
-               public override MethodInfo[] GetAccessors(bool nonPublic)
-               {
-                       MethodInfo[] accessors = property.GetAccessors(nonPublic);
-                       for (int i = 0; i < accessors.Length; i++)
-                       {
-                               accessors[i] = Wrap(accessors[i]);
-                       }
-                       return accessors;
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return property.GetRawConstantValue();
-               }
-
-               internal override bool IsPublic
-               {
-                       get { return property.IsPublic; }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get { return property.IsNonPrivate; }
-               }
-
-               internal override bool IsStatic
-               {
-                       get { return property.IsStatic; }
-               }
-
-               internal override PropertySignature PropertySignature
-               {
-                       get { return property.PropertySignature.ExpandTypeParameters(typeInstance); }
-               }
-
-               public override string Name
-               {
-                       get { return property.Name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeInstance; }
-               }
-
-               public override Module Module
-               {
-                       get { return typeInstance.Module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return property.MetadataToken; }
-               }
-
-               internal override PropertyInfo BindTypeParameters(Type type)
-               {
-                       return new GenericPropertyInfo(typeInstance.BindTypeParameters(type), property);
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return property.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return property.GetCurrentToken();
-               }
-       }
-
-       sealed class GenericEventInfo : EventInfo
-       {
-               private readonly Type typeInstance;
-               private readonly EventInfo eventInfo;
-
-               internal GenericEventInfo(Type typeInstance, EventInfo eventInfo)
-               {
-                       this.typeInstance = typeInstance;
-                       this.eventInfo = eventInfo;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       GenericEventInfo other = obj as GenericEventInfo;
-                       return other != null && other.typeInstance == typeInstance && other.eventInfo == eventInfo;
-               }
-
-               public override int GetHashCode()
-               {
-                       return typeInstance.GetHashCode() * 777 + eventInfo.GetHashCode();
-               }
-
-               public override EventAttributes Attributes
-               {
-                       get { return eventInfo.Attributes; }
-               }
-
-               private MethodInfo Wrap(MethodInfo method)
-               {
-                       if (method == null)
-                       {
-                               return null;
-                       }
-                       return new GenericMethodInstance(typeInstance, method, null);
-               }
-
-               public override MethodInfo GetAddMethod(bool nonPublic)
-               {
-                       return Wrap(eventInfo.GetAddMethod(nonPublic));
-               }
-
-               public override MethodInfo GetRaiseMethod(bool nonPublic)
-               {
-                       return Wrap(eventInfo.GetRaiseMethod(nonPublic));
-               }
-
-               public override MethodInfo GetRemoveMethod(bool nonPublic)
-               {
-                       return Wrap(eventInfo.GetRemoveMethod(nonPublic));
-               }
-
-               public override MethodInfo[] GetOtherMethods(bool nonPublic)
-               {
-                       MethodInfo[] others = eventInfo.GetOtherMethods(nonPublic);
-                       for (int i = 0; i < others.Length; i++)
-                       {
-                               others[i] = Wrap(others[i]);
-                       }
-                       return others;
-               }
-
-               public override MethodInfo[] __GetMethods()
-               {
-                       MethodInfo[] others = eventInfo.__GetMethods();
-                       for (int i = 0; i < others.Length; i++)
-                       {
-                               others[i] = Wrap(others[i]);
-                       }
-                       return others;
-               }
-
-               public override Type EventHandlerType
-               {
-                       get { return eventInfo.EventHandlerType.BindTypeParameters(typeInstance); }
-               }
-
-               public override string Name
-               {
-                       get { return eventInfo.Name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return typeInstance; }
-               }
-
-               public override Module Module
-               {
-                       get { return eventInfo.Module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return eventInfo.MetadataToken; }
-               }
-
-               internal override EventInfo BindTypeParameters(Type type)
-               {
-                       return new GenericEventInfo(typeInstance.BindTypeParameters(type), eventInfo);
-               }
-
-               internal override bool IsPublic
-               {
-                       get { return eventInfo.IsPublic; }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get { return eventInfo.IsNonPrivate; }
-               }
-
-               internal override bool IsStatic
-               {
-                       get { return eventInfo.IsStatic; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return eventInfo.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return eventInfo.GetCurrentToken();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/IKVM.Reflection.csproj b/mcs/class/IKVM.Reflection/IKVM.Reflection.csproj
deleted file mode 100644 (file)
index 540e037..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.30729</ProductVersion>
-    <SchemaVersion>2.0</SchemaVersion>
-    <ProjectGuid>{4CB170EF-DFE6-4A56-9E1B-A85449E827A7}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>IKVM.Reflection</RootNamespace>
-    <AssemblyName>IKVM.Reflection</AssemblyName>
-    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <TargetFrameworkSubset>
-    </TargetFrameworkSubset>
-    <SccProjectName>
-    </SccProjectName>
-    <SccLocalPath>
-    </SccLocalPath>
-    <SccAuxPath>
-    </SccAuxPath>
-    <SccProvider>
-    </SccProvider>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <ItemGroup>
-    <Compile Include="AmbiguousMatchException.cs" />
-    <Compile Include="Assembly.cs" />
-    <Compile Include="AssemblyName.cs" />
-    <Compile Include="BadImageFormatException.cs" />
-    <Compile Include="Binder.cs" />
-    <Compile Include="ConstructorInfo.cs" />
-    <Compile Include="CustomAttributeData.cs" />
-    <Compile Include="CustomAttributeNamedArgument.cs" />
-    <Compile Include="CustomAttributeTypedArgument.cs" />
-    <Compile Include="CustomModifiers.cs" />
-    <Compile Include="Emit\AssemblyBuilder.cs" />
-    <Compile Include="Emit\ConstructorBuilder.cs" />
-    <Compile Include="Emit\CustomAttributeBuilder.cs" />
-    <Compile Include="Emit\CustomModifiersBuilder.cs" />
-    <Compile Include="Emit\EnumBuilder.cs" />
-    <Compile Include="Emit\Enums.cs" />
-    <Compile Include="Emit\EventBuilder.cs" />
-    <Compile Include="Emit\ExceptionHandler.cs" />
-    <Compile Include="Emit\FieldBuilder.cs" />
-    <Compile Include="Emit\ILGenerator.cs" />
-    <Compile Include="Emit\MethodBuilder.cs" />
-    <Compile Include="Emit\ModuleBuilder.cs" />
-    <Compile Include="Emit\OpCode.cs" />
-    <Compile Include="Emit\OpCodes.cs" />
-    <Compile Include="Emit\ParameterBuilder.cs" />
-    <Compile Include="Emit\PropertyBuilder.cs" />
-    <Compile Include="Emit\SignatureHelper.cs" />
-    <Compile Include="Emit\Tokens.cs" />
-    <Compile Include="Emit\TypeBuilder.cs" />
-    <Compile Include="Enums.cs" />
-    <Compile Include="EventInfo.cs" />
-    <Compile Include="ExceptionHandlingClause.cs" />
-    <Compile Include="FieldInfo.cs" />
-    <Compile Include="FieldSignature.cs" />
-    <Compile Include="Fusion.cs" />
-    <Compile Include="GenericWrappers.cs" />
-    <Compile Include="Impl\ITypeOwner.cs" />
-    <Compile Include="Impl\MdbWriter.cs" />
-    <Compile Include="Impl\PdbWriter.cs" />
-    <Compile Include="Impl\SymbolSupport.cs" />
-    <Compile Include="InterfaceMapping.cs" />
-    <Compile Include="LocalVariableInfo.cs" />
-    <Compile Include="ManifestResourceInfo.cs" />
-    <Compile Include="MarshalSpec.cs" />
-    <Compile Include="MemberInfo.cs" />
-    <Compile Include="Metadata\CliHeader.cs" />
-    <Compile Include="Metadata\MetadataRW.cs" />
-    <Compile Include="Metadata\Tables.cs" />
-    <Compile Include="MethodBase.cs" />
-    <Compile Include="MethodBody.cs" />
-    <Compile Include="MethodImplMap.cs" />
-    <Compile Include="MethodInfo.cs" />
-    <Compile Include="MethodSignature.cs" />
-    <Compile Include="Missing.cs" />
-    <Compile Include="Module.cs" />
-    <Compile Include="ParameterInfo.cs" />
-    <Compile Include="ParameterModifier.cs" />
-    <Compile Include="PropertyInfo.cs" />
-    <Compile Include="PropertySignature.cs" />
-    <Compile Include="Reader\AssemblyReader.cs" />
-    <Compile Include="Reader\Authenticode.cs" />
-    <Compile Include="Reader\ByteReader.cs" />
-    <Compile Include="Reader\EventInfoImpl.cs" />
-    <Compile Include="Reader\Field.cs" />
-    <Compile Include="Reader\GenericTypeParameter.cs" />
-    <Compile Include="Reader\MetadataReader.cs" />
-    <Compile Include="Reader\Method.cs" />
-    <Compile Include="Reader\ModuleReader.cs" />
-    <Compile Include="Reader\PEReader.cs" />
-    <Compile Include="Reader\PropertyInfoImpl.cs" />
-    <Compile Include="Reader\ResourceModule.cs" />
-    <Compile Include="Reader\TypeDefImpl.cs" />
-    <Compile Include="Signature.cs" />
-    <Compile Include="StandAloneMethodSig.cs" />
-    <Compile Include="StrongNameKeyPair.cs" />
-    <Compile Include="Type.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="TypeInfo.cs" />
-    <Compile Include="TypeNameParser.cs" />
-    <Compile Include="Universe.cs" />
-    <Compile Include="Util.cs" />
-    <Compile Include="Writer\ByteBuffer.cs" />
-    <Compile Include="Writer\Heaps.cs" />
-    <Compile Include="Writer\MetadataWriter.cs" />
-    <Compile Include="Writer\ModuleWriter.cs" />
-    <Compile Include="Writer\PEWriter.cs" />
-    <Compile Include="Writer\ResourceSection.cs" />
-    <Compile Include="Writer\TextSection.cs" />
-    <Compile Include="Writer\VersionInfo.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Security" />
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>
\ No newline at end of file
diff --git a/mcs/class/IKVM.Reflection/Impl/ITypeOwner.cs b/mcs/class/IKVM.Reflection/Impl/ITypeOwner.cs
deleted file mode 100644 (file)
index 10050f7..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection.Impl
-{
-       interface ITypeOwner
-       {
-               ModuleBuilder ModuleBuilder { get; }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Impl/MdbWriter.cs b/mcs/class/IKVM.Reflection/Impl/MdbWriter.cs
deleted file mode 100644 (file)
index 226137b..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-#if MONO
-using System;
-using System.Collections.Generic;
-using Mono.CompilerServices.SymbolWriter;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection.Impl
-{
-       sealed class Method : IMethodDef
-       {
-               internal int token;
-               internal string name;
-               internal SymbolDocumentWriter document;
-               internal int[] offsets;
-               internal int[] lines;
-               internal int[] columns;
-               internal List<string> variables = new List<string>();
-
-               public string Name
-               {
-                       get { return name; }
-               }
-
-               public int Token
-               {
-                       get { return token; }
-               }
-       }
-
-       sealed class SymbolDocumentWriter : System.Diagnostics.SymbolStore.ISymbolDocumentWriter
-       {
-               internal readonly string url;
-               internal SourceFileEntry source;
-
-               internal SymbolDocumentWriter(string url)
-               {
-                       this.url = url;
-               }
-
-               public void SetCheckSum(Guid algorithmId, byte[] checkSum)
-               {
-               }
-
-               public void SetSource(byte[] source)
-               {
-               }
-       }
-
-       sealed class MdbWriter : ISymbolWriterImpl
-       {
-               private readonly ModuleBuilder moduleBuilder;
-               private readonly Dictionary<int, Method> methods = new Dictionary<int, Method>();
-               private readonly Dictionary<string, SymbolDocumentWriter> documents = new Dictionary<string, SymbolDocumentWriter>();
-               private Method currentMethod;
-
-               internal MdbWriter(ModuleBuilder moduleBuilder)
-               {
-                       this.moduleBuilder = moduleBuilder;
-               }
-
-               public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
-               {
-                       return Empty<byte>.Array;
-               }
-
-               public void RemapToken(int oldToken, int newToken)
-               {
-                       if (methods.ContainsKey(oldToken))
-                       {
-                               methods[oldToken].token = newToken;
-                       }
-               }
-
-               public void Close()
-               {
-                       MonoSymbolWriter writer = new MonoSymbolWriter(moduleBuilder.FullyQualifiedName);
-
-                       foreach (Method method in methods.Values)
-                       {
-                               if (method.document != null)
-                               {
-                                       if (method.document.source == null)
-                                       {
-                                               method.document.source = new SourceFileEntry(writer.SymbolFile, method.document.url);
-                                       }
-                                       ICompileUnit file = new CompileUnitEntry(writer.SymbolFile, method.document.source);
-                                       SourceMethodBuilder smb = writer.OpenMethod(file, 0, method);
-                                       for (int i = 0; i < method.offsets.Length; i++)
-                                       {
-                                               smb.MarkSequencePoint(method.offsets[i], method.document.source, method.lines[i], method.columns[i], false);
-                                       }
-                                       for (int i = 0; i < method.variables.Count; i++)
-                                       {
-                                               writer.DefineLocalVariable(i, method.variables[i]);
-                                       }
-                                       writer.CloseMethod();
-                               }
-                       }
-
-                       writer.WriteSymbolFile(moduleBuilder.ModuleVersionId);
-               }
-
-               public System.Diagnostics.SymbolStore.ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
-               {
-                       SymbolDocumentWriter writer;
-                       if (!documents.TryGetValue(url, out writer))
-                       {
-                               writer = new SymbolDocumentWriter(url);
-                               documents.Add(url, writer);
-                       }
-                       return writer;
-               }
-
-               public void OpenMethod(System.Diagnostics.SymbolStore.SymbolToken method)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void OpenMethod(System.Diagnostics.SymbolStore.SymbolToken token, MethodBase mb)
-               {
-                       Method method = new Method();
-                       method.token = token.GetToken();
-                       method.name = mb.Name;
-                       methods.Add(token.GetToken(), method);
-                       currentMethod = method;
-               }
-
-               public void CloseMethod()
-               {
-                       currentMethod = null;
-               }
-
-               public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
-               {
-               }
-
-               public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
-               {
-                       currentMethod.variables.Add(name);
-               }
-
-               public void DefineSequencePoints(System.Diagnostics.SymbolStore.ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
-               {
-                       currentMethod.document = (SymbolDocumentWriter)document;
-                       currentMethod.offsets = offsets;
-                       currentMethod.lines = lines;
-                       currentMethod.columns = columns;
-               }
-
-               public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-               }
-
-               public void DefineField(System.Diagnostics.SymbolStore.SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-               }
-
-               public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, System.Diagnostics.SymbolStore.SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-               }
-
-               public void OpenNamespace(string name)
-               {
-               }
-
-               public void CloseNamespace()
-               {
-               }
-
-               public void UsingNamespace(string fullName)
-               {
-               }
-
-               public int OpenScope(int startOffset)
-               {
-                       return 0;
-               }
-
-               public void CloseScope(int endOffset)
-               {
-               }
-
-               public void SetMethodSourceRange(System.Diagnostics.SymbolStore.ISymbolDocumentWriter startDoc, int startLine, int startColumn, System.Diagnostics.SymbolStore.ISymbolDocumentWriter endDoc, int endLine, int endColumn)
-               {
-               }
-
-               public void SetScopeRange(int scopeID, int startOffset, int endOffset)
-               {
-               }
-
-               public void SetSymAttribute(System.Diagnostics.SymbolStore.SymbolToken parent, string name, byte[] data)
-               {
-               }
-
-               public void SetUserEntryPoint(System.Diagnostics.SymbolStore.SymbolToken entryMethod)
-               {
-               }
-
-               public void SetUnderlyingWriter(IntPtr underlyingWriter)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
-               {
-                       throw new InvalidOperationException();
-               }
-       }
-}
-#endif // MONO
diff --git a/mcs/class/IKVM.Reflection/Impl/PdbWriter.cs b/mcs/class/IKVM.Reflection/Impl/PdbWriter.cs
deleted file mode 100644 (file)
index b8976bb..0000000
+++ /dev/null
@@ -1,1188 +0,0 @@
-/*
-  Copyright (C) 2008-2010 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection.Impl
-{
-       [Guid("7dac8207-d3ae-4c75-9b67-92801a497d44")]
-       [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
-       [ComImport]
-       interface IMetaDataImport
-       {
-               void PlaceHolder_CloseEnum();
-               void PlaceHolder_CountEnum();
-               void PlaceHolder_ResetEnum();
-               void PlaceHolder_EnumTypeDefs();
-               void PlaceHolder_EnumInterfaceImpls();
-               void PlaceHolder_EnumTypeRefs();
-               void PlaceHolder_FindTypeDefByName();
-               void PlaceHolder_GetScopeProps();
-               void PlaceHolder_GetModuleFromScope();
-
-               void GetTypeDefProps(
-                       int                     td,                     // [IN] TypeDef token for inquiry.
-               IntPtr          szTypeDef,              // [OUT] Put name here.
-                   int                 cchTypeDef,             // [IN] size of name buffer in wide chars.
-                       IntPtr          pchTypeDef,                             // [OUT] put size of name (wide chars) here.
-                       IntPtr          pdwTypeDefFlags,                // [OUT] Put flags here.
-                       IntPtr          ptkExtends);                    // [OUT] Put base class TypeDef/TypeRef here.
-
-               void PlaceHolder_GetInterfaceImplProps();
-               void PlaceHolder_GetTypeRefProps();
-               void PlaceHolder_ResolveTypeRef();
-               void PlaceHolder_EnumMembers();
-               void PlaceHolder_EnumMembersWithName();
-               void PlaceHolder_EnumMethods();
-               void PlaceHolder_EnumMethodsWithName();
-               void PlaceHolder_EnumFields();
-               void PlaceHolder_EnumFieldsWithName();
-               void PlaceHolder_EnumParams();
-               void PlaceHolder_EnumMemberRefs();
-               void PlaceHolder_EnumMethodImpls();
-               void PlaceHolder_EnumPermissionSets();
-               void PlaceHolder_FindMember();
-               void PlaceHolder_FindMethod();
-               void PlaceHolder_FindField();
-               void PlaceHolder_FindMemberRef();
-
-               void GetMethodProps(
-                       int                     mb,                     // The method for which to get props.   
-                       IntPtr          pClass,                                 // Put method's class here. 
-                       IntPtr      szMethod,               // Put method's name here.  
-                       int                     cchMethod,              // Size of szMethod buffer in wide chars.   
-                       IntPtr      pchMethod,                          // Put actual size here 
-                       IntPtr          pdwAttr,                                // Put flags here.  
-                       IntPtr          ppvSigBlob,                             // [OUT] point to the blob value of meta data   
-                       IntPtr          pcbSigBlob,                             // [OUT] actual size of signature blob  
-                       IntPtr          pulCodeRVA,                             // [OUT] codeRVA    
-                       IntPtr          pdwImplFlags);              // [OUT] Impl. Flags    
-
-               void PlaceHolder_GetMemberRefProps();
-               void PlaceHolder_EnumProperties();
-               void PlaceHolder_EnumEvents();
-               void PlaceHolder_GetEventProps();
-               void PlaceHolder_EnumMethodSemantics();
-               void PlaceHolder_GetMethodSemantics();
-               void PlaceHolder_GetClassLayout();
-               void PlaceHolder_GetFieldMarshal();
-               void PlaceHolder_GetRVA();
-               void PlaceHolder_GetPermissionSetProps();
-               void PlaceHolder_GetSigFromToken();
-               void PlaceHolder_GetModuleRefProps();
-               void PlaceHolder_EnumModuleRefs();
-               void PlaceHolder_GetTypeSpecFromToken();
-               void PlaceHolder_GetNameFromToken();
-               void PlaceHolder_EnumUnresolvedMethods();
-               void PlaceHolder_GetUserString();
-               void PlaceHolder_GetPinvokeMap();
-               void PlaceHolder_EnumSignatures();
-               void PlaceHolder_EnumTypeSpecs();
-               void PlaceHolder_EnumUserStrings();
-               void PlaceHolder_GetParamForMethodIndex();
-               void PlaceHolder_EnumCustomAttributes();
-               void PlaceHolder_GetCustomAttributeProps();
-               void PlaceHolder_FindTypeRef();
-               void PlaceHolder_GetMemberProps();
-               void PlaceHolder_GetFieldProps();
-               void PlaceHolder_GetPropertyProps();
-               void PlaceHolder_GetParamProps();
-               void PlaceHolder_GetCustomAttributeByName();
-               void PlaceHolder_IsValidToken();
-
-               void GetNestedClassProps(
-                       int             tdNestedClass,                  // [IN] NestedClass token.
-                       IntPtr  ptdEnclosingClass);             // [OUT] EnclosingClass token.
-
-               void PlaceHolder_GetNativeCallConvFromSig();
-               void PlaceHolder_IsGlobal();
-       }
-
-       [Guid("ba3fee4c-ecb9-4e41-83b7-183fa41cd859")]
-       [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
-       [ComImport]
-       interface IMetaDataEmit
-       {
-               void PlaceHolder_SetModuleProps();
-               void PlaceHolder_Save();
-               void PlaceHolder_SaveToStream();
-               void PlaceHolder_GetSaveSize();
-               void PlaceHolder_DefineTypeDef();
-               void PlaceHolder_DefineNestedType();
-               void PlaceHolder_SetHandler();
-               void PlaceHolder_DefineMethod();
-               void PlaceHolder_DefineMethodImpl();
-               void PlaceHolder_DefineTypeRefByName();
-               void PlaceHolder_DefineImportType();
-               void PlaceHolder_DefineMemberRef();
-               void PlaceHolder_DefineImportMember();
-               void PlaceHolder_DefineEvent();
-               void PlaceHolder_SetClassLayout();
-               void PlaceHolder_DeleteClassLayout();
-               void PlaceHolder_SetFieldMarshal();
-               void PlaceHolder_DeleteFieldMarshal();
-               void PlaceHolder_DefinePermissionSet();
-               void PlaceHolder_SetRVA();
-               void PlaceHolder_GetTokenFromSig();
-               void PlaceHolder_DefineModuleRef();
-               void PlaceHolder_SetParent();
-               void PlaceHolder_GetTokenFromTypeSpec();
-               void PlaceHolder_SaveToMemory();
-               void PlaceHolder_DefineUserString();
-               void PlaceHolder_DeleteToken();
-               void PlaceHolder_SetMethodProps();
-               void PlaceHolder_SetTypeDefProps();
-               void PlaceHolder_SetEventProps();
-               void PlaceHolder_SetPermissionSetProps();
-               void PlaceHolder_DefinePinvokeMap();
-               void PlaceHolder_SetPinvokeMap();
-               void PlaceHolder_DeletePinvokeMap();
-               void PlaceHolder_DefineCustomAttribute();
-               void PlaceHolder_SetCustomAttributeValue();
-               void PlaceHolder_DefineField();
-               void PlaceHolder_DefineProperty();
-               void PlaceHolder_DefineParam();
-               void PlaceHolder_SetFieldProps();
-               void PlaceHolder_SetPropertyProps();
-               void PlaceHolder_SetParamProps();
-               void PlaceHolder_DefineSecurityAttributeSet();
-               void PlaceHolder_ApplyEditAndContinue();
-               void PlaceHolder_TranslateSigWithScope();
-               void PlaceHolder_SetMethodImplFlags();
-               void PlaceHolder_SetFieldRVA();
-               void PlaceHolder_Merge();
-               void PlaceHolder_MergeEnd();
-       }
-
-       [Guid("B01FAFEB-C450-3A4D-BEEC-B4CEEC01E006")]
-       [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
-       [ComImport]
-       internal interface ISymUnmanagedDocumentWriter { }
-
-       [Guid("0b97726e-9e6d-4f05-9a26-424022093caa")]
-       [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
-       [ComImport]
-       [CoClass(typeof(CorSymWriterClass))]
-       interface ISymUnmanagedWriter2
-       {
-               ISymUnmanagedDocumentWriter DefineDocument(string url, ref Guid language, ref Guid languageVendor, ref Guid documentType);
-               void PlaceHolder_SetUserEntryPoint();
-               void OpenMethod(int method);
-               void CloseMethod();
-               int OpenScope(int startOffset);
-               void CloseScope(int endOffset);
-               void PlaceHolder_SetScopeRange();
-               void DefineLocalVariable(string name, int attributes, int cSig, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] signature, int addrKind, int addr1, int addr2, int startOffset, int endOffset);
-               void PlaceHolder_DefineParameter();
-               void PlaceHolder_DefineField();
-               void PlaceHolder_DefineGlobalVariable();
-               void Close();
-               void PlaceHolder_SetSymAttribute();
-               void PlaceHolder_OpenNamespace();
-               void PlaceHolder_CloseNamespace();
-               void PlaceHolder_UsingNamespace();
-               void PlaceHolder_SetMethodSourceRange();
-               void Initialize([MarshalAs(UnmanagedType.IUnknown)] object emitter, string filename, [MarshalAs(UnmanagedType.IUnknown)] object pIStream, bool fFullBuild);
-
-               void GetDebugInfo(
-                       [In, Out] ref IMAGE_DEBUG_DIRECTORY pIDD,
-                       [In]  uint cData,
-                       [Out] out uint pcData,
-                       [Out, MarshalAs(UnmanagedType.LPArray)] byte[] data);
-
-               void DefineSequencePoints(ISymUnmanagedDocumentWriter document, int spCount,
-                 [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] offsets,
-                 [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] lines,
-                 [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] columns,
-                 [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endLines,
-                 [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] int[] endColumns);
-
-               void RemapToken(
-                       [In] int oldToken,
-                       [In] int newToken);
-
-               void PlaceHolder_Initialize2();
-               void PlaceHolder_DefineConstant();
-               void PlaceHolder_Abort();
-
-               void DefineLocalVariable2(string name, int attributes, int token, int addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
-
-               void PlaceHolder_DefineGlobalVariable2();
-               void PlaceHolder_DefineConstant2();
-       }
-
-       [Guid("108296c1-281e-11d3-bd22-0000f80849bd")]
-       [ComImport]
-       class CorSymWriterClass { }
-
-       sealed class PdbWriter : ISymbolWriterImpl, IMetaDataEmit, IMetaDataImport
-       {
-               private readonly ModuleBuilder moduleBuilder;
-               private ISymUnmanagedWriter2 symUnmanagedWriter;
-               private readonly Dictionary<string, Document> documents = new Dictionary<string, Document>();
-               private readonly List<Method> methods = new List<Method>();
-               private readonly Dictionary<int, int> remap = new Dictionary<int, int>();
-               private readonly Dictionary<int, int> reversemap = new Dictionary<int, int>();
-               private readonly Dictionary<int, MethodBase> methodMap = new Dictionary<int, MethodBase>();
-               private Method currentMethod;
-
-               internal PdbWriter(ModuleBuilder moduleBuilder)
-               {
-                       this.moduleBuilder = moduleBuilder;
-               }
-
-               private sealed class Document : ISymbolDocumentWriter
-               {
-                       internal readonly string url;
-                       private Guid language;
-                       private Guid languageVendor;
-                       private Guid documentType;
-                       private ISymUnmanagedDocumentWriter unmanagedDocument;
-
-                       internal Document(string url, Guid language, Guid languageVendor, Guid documentType)
-                       {
-                               this.url = url;
-                               this.language = language;
-                               this.languageVendor = languageVendor;
-                               this.documentType = documentType;
-                       }
-
-                       public void SetCheckSum(Guid algorithmId, byte[] checkSum)
-                       {
-                               throw new NotImplementedException();
-                       }
-
-                       public void SetSource(byte[] source)
-                       {
-                               throw new NotImplementedException();
-                       }
-
-                       internal ISymUnmanagedDocumentWriter GetUnmanagedDocument(ISymUnmanagedWriter2 symUnmanagedWriter)
-                       {
-                               if (unmanagedDocument == null)
-                               {
-                                       unmanagedDocument = symUnmanagedWriter.DefineDocument(url, ref language, ref languageVendor, ref documentType);
-                               }
-                               return unmanagedDocument;
-                       }
-
-                       internal void Release()
-                       {
-                               if (unmanagedDocument != null)
-                               {
-                                       Marshal.ReleaseComObject(unmanagedDocument);
-                                       unmanagedDocument = null;
-                               }
-                       }
-               }
-
-               private sealed class LocalVar
-               {
-                       internal readonly FieldAttributes attributes;
-                       internal readonly int signature;
-                       internal readonly SymAddressKind addrKind;
-                       internal readonly int addr1;
-                       internal readonly int addr2;
-                       internal readonly int addr3;
-                       internal readonly int startOffset;
-                       internal readonly int endOffset;
-
-                       internal LocalVar(FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
-                       {
-                               this.attributes = attributes;
-                               this.signature = signature;
-                               this.addrKind = addrKind;
-                               this.addr1 = addr1;
-                               this.addr2 = addr2;
-                               this.addr3 = addr3;
-                               this.startOffset = startOffset;
-                               this.endOffset = endOffset;
-                       }
-               }
-
-               private sealed class Scope
-               {
-                       internal readonly int startOffset;
-                       internal int endOffset;
-                       internal readonly List<Scope> scopes = new List<Scope>();
-                       internal readonly Dictionary<string, LocalVar> locals = new Dictionary<string, LocalVar>();
-
-                       internal Scope(int startOffset)
-                       {
-                               this.startOffset = startOffset;
-                       }
-
-                       internal void Do(ISymUnmanagedWriter2 symUnmanagedWriter)
-                       {
-                               symUnmanagedWriter.OpenScope(startOffset);
-                               foreach (KeyValuePair<string, LocalVar> kv in locals)
-                               {
-                                       symUnmanagedWriter.DefineLocalVariable2(kv.Key, (int)kv.Value.attributes, kv.Value.signature, (int)kv.Value.addrKind, kv.Value.addr1, kv.Value.addr2, kv.Value.addr3, kv.Value.startOffset, kv.Value.endOffset);
-                               }
-                               foreach (Scope scope in scopes)
-                               {
-                                       scope.Do(symUnmanagedWriter);
-                               }
-                               symUnmanagedWriter.CloseScope(endOffset);
-                       }
-               }
-
-               private sealed class Method
-               {
-                       internal readonly int token;
-                       internal Document document;
-                       internal int[] offsets;
-                       internal int[] lines;
-                       internal int[] columns;
-                       internal int[] endLines;
-                       internal int[] endColumns;
-                       internal readonly List<Scope> scopes = new List<Scope>();
-                       internal readonly Stack<Scope> scopeStack = new Stack<Scope>();
-
-                       internal Method(int token)
-                       {
-                               this.token = token;
-                       }
-               }
-
-               public ISymbolDocumentWriter DefineDocument(string url, Guid language, Guid languageVendor, Guid documentType)
-               {
-                       Document doc;
-                       if (!documents.TryGetValue(url, out doc))
-                       {
-                               doc = new Document(url, language, languageVendor, documentType);
-                               documents.Add(url, doc);
-                       }
-                       return doc;
-               }
-
-               public void OpenMethod(SymbolToken method)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void OpenMethod(SymbolToken method, MethodBase mb)
-               {
-                       int token = method.GetToken();
-                       currentMethod = new Method(token);
-                       methodMap.Add(token, mb);
-               }
-
-               public void CloseMethod()
-               {
-                       methods.Add(currentMethod);
-                       currentMethod = null;
-               }
-
-               public void DefineSequencePoints(ISymbolDocumentWriter document, int[] offsets, int[] lines, int[] columns, int[] endLines, int[] endColumns)
-               {
-                       currentMethod.document = (Document)document;
-                       currentMethod.offsets = offsets;
-                       currentMethod.lines = lines;
-                       currentMethod.columns = columns;
-                       currentMethod.endLines = endLines;
-                       currentMethod.endColumns = endColumns;
-               }
-
-               public int OpenScope(int startOffset)
-               {
-                       Scope scope = new Scope(startOffset);
-                       if (currentMethod.scopeStack.Count == 0)
-                       {
-                               currentMethod.scopes.Add(scope);
-                       }
-                       else
-                       {
-                               currentMethod.scopeStack.Peek().scopes.Add(scope);
-                       }
-                       currentMethod.scopeStack.Push(scope);
-                       return 0;
-               }
-
-               public void CloseScope(int endOffset)
-               {
-                       currentMethod.scopeStack.Pop().endOffset = endOffset;
-               }
-
-               public void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
-               {
-                       currentMethod.scopeStack.Peek().locals[name] = new LocalVar(attributes, signature, addrKind, addr1, addr2, addr3, startOffset, endOffset);
-               }
-
-               private void InitWriter()
-               {
-                       if (symUnmanagedWriter == null)
-                       {
-                               string fileName = System.IO.Path.ChangeExtension(moduleBuilder.FullyQualifiedName, ".pdb");
-                               // pro-actively delete the .pdb to get a meaningful IOException, instead of COMInteropException if the file can't be overwritten (or is corrupt, or who knows what)
-                               System.IO.File.Delete(fileName);
-                               symUnmanagedWriter = new ISymUnmanagedWriter2();
-                               symUnmanagedWriter.Initialize(this, fileName, null, true);
-                       }
-               }
-
-               public byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd)
-               {
-                       InitWriter();
-                       uint cData;
-                       symUnmanagedWriter.GetDebugInfo(ref idd, 0, out cData, null);
-                       byte[] buf = new byte[cData];
-                       symUnmanagedWriter.GetDebugInfo(ref idd, (uint)buf.Length, out cData, buf);
-                       return buf;
-               }
-
-               public void RemapToken(int oldToken, int newToken)
-               {
-                       remap.Add(oldToken, newToken);
-                       reversemap.Add(newToken, oldToken);
-               }
-
-               public void Close()
-               {
-                       InitWriter();
-
-                       foreach (Method method in methods)
-                       {
-                               int remappedToken = method.token;
-                               remap.TryGetValue(remappedToken, out remappedToken);
-                               symUnmanagedWriter.OpenMethod(remappedToken);
-                               if (method.document != null)
-                               {
-                                       ISymUnmanagedDocumentWriter doc = method.document.GetUnmanagedDocument(symUnmanagedWriter);
-                                       symUnmanagedWriter.DefineSequencePoints(doc, method.offsets.Length, method.offsets, method.lines, method.columns, method.endLines, method.endColumns);
-                               }
-                               foreach (Scope scope in method.scopes)
-                               {
-                                       scope.Do(symUnmanagedWriter);
-                               }
-                               symUnmanagedWriter.CloseMethod(); 
-                       }
-
-                       foreach (Document doc in documents.Values)
-                       {
-                               doc.Release();
-                       }
-
-                       symUnmanagedWriter.Close();
-                       Marshal.ReleaseComObject(symUnmanagedWriter);
-                       symUnmanagedWriter = null;
-                       documents.Clear();
-                       methods.Clear();
-                       remap.Clear();
-                       reversemap.Clear();
-               }
-
-               public void DefineLocalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void CloseNamespace()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void DefineField(SymbolToken parent, string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void DefineGlobalVariable(string name, System.Reflection.FieldAttributes attributes, byte[] signature, SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void DefineParameter(string name, System.Reflection.ParameterAttributes attributes, int sequence, SymAddressKind addrKind, int addr1, int addr2, int addr3)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void Initialize(IntPtr emitter, string filename, bool fFullBuild)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void OpenNamespace(string name)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void SetMethodSourceRange(ISymbolDocumentWriter startDoc, int startLine, int startColumn, ISymbolDocumentWriter endDoc, int endLine, int endColumn)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void SetScopeRange(int scopeID, int startOffset, int endOffset)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void SetSymAttribute(SymbolToken parent, string name, byte[] data)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void SetUnderlyingWriter(IntPtr underlyingWriter)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void SetUserEntryPoint(SymbolToken entryMethod)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void UsingNamespace(string fullName)
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_CloseEnum()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_CountEnum()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_ResetEnum()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumTypeDefs()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumInterfaceImpls()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumTypeRefs()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindTypeDefByName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetScopeProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetModuleFromScope()
-               {
-                       throw new NotImplementedException();
-               }
-
-               private static void WriteString(IntPtr ptrString, IntPtr ptrLength, string str, int length)
-               {
-                       if (ptrString != IntPtr.Zero)
-                       {
-                               for (int i = 0; i < Math.Min(length, str.Length); i++)
-                               {
-                                       Marshal.WriteInt16(ptrString, i, str[i]);
-                               }
-                       }
-                       if (ptrLength != IntPtr.Zero)
-                       {
-                               Marshal.WriteInt32(ptrLength, str.Length);
-                       }
-               }
-
-               private static void WriteToken(IntPtr ptr, MemberInfo member)
-               {
-                       if (ptr != IntPtr.Zero)
-                       {
-                               Marshal.WriteInt32(ptr, member == null ? 0 : member.MetadataToken);
-                       }
-               }
-
-               private static void WriteInt32(IntPtr ptr, int value)
-               {
-                       if (ptr != IntPtr.Zero)
-                       {
-                               Marshal.WriteInt32(ptr, value);
-                       }
-               }
-
-               public void GetTypeDefProps(
-                       int td,                     // [IN] TypeDef token for inquiry.
-                       IntPtr szTypeDef,                       // [OUT] Put name here.
-                       int cchTypeDef,             // [IN] size of name buffer in wide chars.
-                       IntPtr pchTypeDef,                      // [OUT] put size of name (wide chars) here.
-                       IntPtr pdwTypeDefFlags,         // [OUT] Put flags here.
-                       IntPtr ptkExtends)                      // [OUT] Put base class TypeDef/TypeRef here.
-               {
-                       if (td == 0)
-                       {
-                               // why are we being called with an invalid token?
-                               WriteString(szTypeDef, pchTypeDef, "", cchTypeDef);
-                               WriteInt32(pdwTypeDefFlags, 0);
-                               WriteToken(ptkExtends, null);
-                       }
-                       else
-                       {
-                               Type type = moduleBuilder.ResolveType(td);
-                               WriteString(szTypeDef, pchTypeDef, type.FullName, cchTypeDef);
-                               WriteInt32(pdwTypeDefFlags, (int)type.Attributes);
-                               WriteToken(ptkExtends, type.BaseType);
-                       }
-               }
-
-               public void PlaceHolder_GetInterfaceImplProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetTypeRefProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_ResolveTypeRef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMembers()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMembersWithName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMethods()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMethodsWithName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumFields()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumFieldsWithName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumParams()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMemberRefs()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMethodImpls()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumPermissionSets()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindMember()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindMethod()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindField()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindMemberRef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void GetMethodProps(
-                       int mb,                                         // The method for which to get props.   
-                       IntPtr pClass,                          // [OUT] Put method's class here. 
-                       IntPtr szMethod,            // [OUT] Put method's name here.  
-                       int cchMethod,              // Size of szMethod buffer in wide chars.   
-                       IntPtr pchMethod,                       // [OUT] Put actual size here 
-                       IntPtr pdwAttr,                         // [OUT] Put flags here.  
-                       IntPtr ppvSigBlob,                      // [OUT] point to the blob value of meta data   
-                       IntPtr pcbSigBlob,                      // [OUT] actual size of signature blob  
-                       IntPtr pulCodeRVA,                      // [OUT] codeRVA    
-                       IntPtr pdwImplFlags)            // [OUT] Impl. Flags    
-               {
-                       if (pdwAttr != IntPtr.Zero || ppvSigBlob != IntPtr.Zero || pcbSigBlob != IntPtr.Zero || pulCodeRVA != IntPtr.Zero || pdwImplFlags != IntPtr.Zero)
-                       {
-                               throw new NotImplementedException();
-                       }
-                       MethodBase method = methodMap[reversemap[mb]];
-                       WriteToken(pClass, method.DeclaringType);
-                       WriteString(szMethod, pchMethod, method.Name, cchMethod);
-               }
-
-               public void PlaceHolder_GetMemberRefProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumProperties()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumEvents()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetEventProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumMethodSemantics()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetMethodSemantics()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetClassLayout()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetFieldMarshal()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetRVA()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetPermissionSetProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetSigFromToken()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetModuleRefProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumModuleRefs()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetTypeSpecFromToken()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetNameFromToken()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumUnresolvedMethods()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetUserString()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetPinvokeMap()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumSignatures()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumTypeSpecs()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumUserStrings()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetParamForMethodIndex()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_EnumCustomAttributes()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetCustomAttributeProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_FindTypeRef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetMemberProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetFieldProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetPropertyProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetParamProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetCustomAttributeByName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_IsValidToken()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void GetNestedClassProps(
-                       int tdNestedClass,                              // [IN] NestedClass token.
-                       IntPtr ptdEnclosingClass)               // [OUT] EnclosingClass token.
-               {
-                       Type type = moduleBuilder.ResolveType(tdNestedClass);
-                       WriteToken(ptdEnclosingClass, type.DeclaringType);
-               }
-
-               public void PlaceHolder_GetNativeCallConvFromSig()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_IsGlobal()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetModuleProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_Save()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SaveToStream()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetSaveSize()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineTypeDef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineNestedType()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetHandler()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineMethod()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineMethodImpl()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineTypeRefByName()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineImportType()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineMemberRef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineImportMember()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineEvent()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetClassLayout()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DeleteClassLayout()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetFieldMarshal()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DeleteFieldMarshal()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefinePermissionSet()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetRVA()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetTokenFromSig()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineModuleRef()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetParent()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_GetTokenFromTypeSpec()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SaveToMemory()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineUserString()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DeleteToken()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetMethodProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetTypeDefProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetEventProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetPermissionSetProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefinePinvokeMap()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetPinvokeMap()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DeletePinvokeMap()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineCustomAttribute()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetCustomAttributeValue()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineField()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineProperty()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineParam()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetFieldProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetPropertyProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetParamProps()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_DefineSecurityAttributeSet()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_ApplyEditAndContinue()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_TranslateSigWithScope()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetMethodImplFlags()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_SetFieldRVA()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_Merge()
-               {
-                       throw new NotImplementedException();
-               }
-
-               public void PlaceHolder_MergeEnd()
-               {
-                       throw new NotImplementedException();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Impl/SymbolSupport.cs b/mcs/class/IKVM.Reflection/Impl/SymbolSupport.cs
deleted file mode 100644 (file)
index 64547eb..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
-  Copyright (C) 2008, 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.InteropServices;
-using System.Diagnostics.SymbolStore;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection.Impl
-{
-       [StructLayout(LayoutKind.Sequential)]
-       struct IMAGE_DEBUG_DIRECTORY
-       {
-               public uint Characteristics;
-               public uint TimeDateStamp;
-               public ushort MajorVersion;
-               public ushort MinorVersion;
-               public uint Type;
-               public uint SizeOfData;
-               public uint AddressOfRawData;
-               public uint PointerToRawData;
-       }
-
-       interface ISymbolWriterImpl : ISymbolWriter
-       {
-               byte[] GetDebugInfo(ref IMAGE_DEBUG_DIRECTORY idd);
-               void RemapToken(int oldToken, int newToken);
-               void DefineLocalVariable2(string name, FieldAttributes attributes, int signature, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset);
-               void OpenMethod(SymbolToken symbolToken, MethodBase mb);
-       }
-
-       static class SymbolSupport
-       {
-               internal static ISymbolWriterImpl CreateSymbolWriterFor(ModuleBuilder moduleBuilder)
-               {
-#if NO_SYMBOL_WRITER
-                       throw new NotSupportedException("IKVM.Reflection compiled with NO_SYMBOL_WRITER does not support writing debugging symbols.");
-#else
-                       if (Universe.MonoRuntime)
-                       {
-#if MONO
-                               return new MdbWriter(moduleBuilder);
-#else
-                               throw new NotSupportedException("IKVM.Reflection must be compiled with MONO defined to support writing Mono debugging symbols.");
-#endif
-                       }
-                       else
-                       {
-                               return new PdbWriter(moduleBuilder);
-                       }
-#endif
-               }
-
-               internal static byte[] GetDebugInfo(ISymbolWriterImpl writer, ref IMAGE_DEBUG_DIRECTORY idd)
-               {
-                       return writer.GetDebugInfo(ref idd);
-               }
-
-               internal static void RemapToken(ISymbolWriterImpl writer, int oldToken, int newToken)
-               {
-                       writer.RemapToken(oldToken, newToken);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/InterfaceMapping.cs b/mcs/class/IKVM.Reflection/InterfaceMapping.cs
deleted file mode 100644 (file)
index f589cfe..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-
-namespace IKVM.Reflection
-{
-       public struct InterfaceMapping
-       {
-               public MethodInfo[] InterfaceMethods;
-               public Type InterfaceType;
-               public MethodInfo[] TargetMethods;
-               public Type TargetType;
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/LocalVariableInfo.cs b/mcs/class/IKVM.Reflection/LocalVariableInfo.cs
deleted file mode 100644 (file)
index 9d565aa..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-
-namespace IKVM.Reflection
-{
-       public class LocalVariableInfo
-       {
-               private readonly int index;
-               private readonly Type type;
-               private readonly bool pinned;
-               private readonly CustomModifiers customModifiers;
-
-               internal LocalVariableInfo(int index, Type type, bool pinned)
-               {
-                       this.index = index;
-                       this.type = type;
-                       this.pinned = pinned;
-               }
-
-               internal LocalVariableInfo(int index, Type type, bool pinned, CustomModifiers customModifiers)
-                       : this(index, type, pinned)
-               {
-                       this.customModifiers = customModifiers;
-               }
-
-               public bool IsPinned
-               {
-                       get { return pinned; }
-               }
-
-               public int LocalIndex
-               {
-                       get { return index; }
-               }
-
-               public Type LocalType
-               {
-                       get { return type; }
-               }
-
-               public CustomModifiers __GetCustomModifiers()
-               {
-                       return customModifiers;
-               }
-
-               public override string ToString()
-               {
-                       return String.Format(pinned ? "{0} ({1}) (pinned)" : "{0} ({1})", type, index);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Makefile b/mcs/class/IKVM.Reflection/Makefile
deleted file mode 100644 (file)
index 069df18..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-thisdir = class/IKVM.Reflection
-SUBDIRS = 
-
-include ../../build/rules.make
-
-DISTFILES = \
-       Emit/*.cs \
-       Impl/*.cs \
-       Metadata/*.cs \
-       Properties/*.cs \
-       Reader/*.cs \
-       Writer/*.cs \
-       *.cs  *.csproj \
-       Makefile
-
-all-local install-local clean-local test-local run-test-local run-test-ondotnet-local uninstall-local doc-update-local csproj-local:
-
-dist-local: dist-default
diff --git a/mcs/class/IKVM.Reflection/ManifestResourceInfo.cs b/mcs/class/IKVM.Reflection/ManifestResourceInfo.cs
deleted file mode 100644 (file)
index 04a2a30..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection
-{
-       public sealed class ManifestResourceInfo
-       {
-               private readonly ModuleReader module;
-               private readonly int index;
-
-               internal ManifestResourceInfo(ModuleReader module, int index)
-               {
-                       this.module = module;
-                       this.index = index;
-               }
-
-               public ResourceAttributes __ResourceAttributes
-               {
-                       get { return (ResourceAttributes)module.ManifestResource.records[index].Flags; }
-               }
-
-               public int __Offset
-               {
-                       get { return module.ManifestResource.records[index].Offset; }
-               }
-
-               public ResourceLocation ResourceLocation
-               {
-                       get
-                       {
-                               int implementation = module.ManifestResource.records[index].Implementation;
-                               if ((implementation >> 24) == AssemblyRefTable.Index)
-                               {
-                                       Assembly asm = ReferencedAssembly;
-                                       if (asm == null || asm.__IsMissing)
-                                       {
-                                               return ResourceLocation.ContainedInAnotherAssembly;
-                                       }
-                                       return asm.GetManifestResourceInfo(module.GetString(module.ManifestResource.records[index].Name)).ResourceLocation | ResourceLocation.ContainedInAnotherAssembly;
-                               }
-                               else if ((implementation >> 24) == FileTable.Index)
-                               {
-                                       if ((implementation & 0xFFFFFF) == 0)
-                                       {
-                                               return ResourceLocation.ContainedInManifestFile | ResourceLocation.Embedded;
-                                       }
-                                       return 0;
-                               }
-                               else
-                               {
-                                       throw new BadImageFormatException();
-                               }
-                       }
-               }
-
-               public Assembly ReferencedAssembly
-               {
-                       get
-                       {
-                               int implementation = module.ManifestResource.records[index].Implementation;
-                               if ((implementation >> 24) == AssemblyRefTable.Index)
-                               {
-                                       return module.ResolveAssemblyRef((implementation & 0xFFFFFF) - 1);
-                               }
-                               return null;
-                       }
-               }
-
-               public string FileName
-               {
-                       get
-                       {
-                               int implementation = module.ManifestResource.records[index].Implementation;
-                               if ((implementation >> 24) == FileTable.Index)
-                               {
-                                       if ((implementation & 0xFFFFFF) == 0)
-                                       {
-                                               return null;
-                                       }
-                                       else
-                                       {
-                                               return module.GetString(module.File.records[(implementation & 0xFFFFFF) - 1].Name);
-                                       }
-                               }
-                               return null;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MarshalSpec.cs b/mcs/class/IKVM.Reflection/MarshalSpec.cs
deleted file mode 100644 (file)
index ee5314d..0000000
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
-  Copyright (C) 2008-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection
-{
-       public struct FieldMarshal
-       {
-               private const UnmanagedType NATIVE_TYPE_MAX = (UnmanagedType)0x50;
-               public UnmanagedType UnmanagedType;
-               public UnmanagedType? ArraySubType;
-               public short? SizeParamIndex;
-               public int? SizeConst;
-               public VarEnum? SafeArraySubType;
-               public Type SafeArrayUserDefinedSubType;
-               public int? IidParameterIndex;
-               public string MarshalType;
-               public string MarshalCookie;
-               public Type MarshalTypeRef;
-
-               internal static bool ReadFieldMarshal(Module module, int token, out FieldMarshal fm)
-               {
-                       fm = new FieldMarshal();
-                       foreach (int i in module.FieldMarshal.Filter(token))
-                       {
-                               ByteReader blob = module.GetBlob(module.FieldMarshal.records[i].NativeType);
-                               fm.UnmanagedType = (UnmanagedType)blob.ReadCompressedUInt();
-                               if (fm.UnmanagedType == UnmanagedType.LPArray)
-                               {
-                                       fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
-                                       if (fm.ArraySubType == NATIVE_TYPE_MAX)
-                                       {
-                                               fm.ArraySubType = null;
-                                       }
-                                       if (blob.Length != 0)
-                                       {
-                                               fm.SizeParamIndex = (short)blob.ReadCompressedUInt();
-                                               if (blob.Length != 0)
-                                               {
-                                                       fm.SizeConst = blob.ReadCompressedUInt();
-                                                       if (blob.Length != 0 && blob.ReadCompressedUInt() == 0)
-                                                       {
-                                                               fm.SizeParamIndex = null;
-                                                       }
-                                               }
-                                       }
-                               }
-                               else if (fm.UnmanagedType == UnmanagedType.SafeArray)
-                               {
-                                       if (blob.Length != 0)
-                                       {
-                                               fm.SafeArraySubType = (VarEnum)blob.ReadCompressedUInt();
-                                               if (blob.Length != 0)
-                                               {
-                                                       fm.SafeArrayUserDefinedSubType = ReadType(module, blob);
-                                               }
-                                       }
-                               }
-                               else if (fm.UnmanagedType == UnmanagedType.ByValArray)
-                               {
-                                       fm.SizeConst = blob.ReadCompressedUInt();
-                                       if (blob.Length != 0)
-                                       {
-                                               fm.ArraySubType = (UnmanagedType)blob.ReadCompressedUInt();
-                                       }
-                               }
-                               else if (fm.UnmanagedType == UnmanagedType.ByValTStr)
-                               {
-                                       fm.SizeConst = blob.ReadCompressedUInt();
-                               }
-                               else if (fm.UnmanagedType == UnmanagedType.Interface
-                                       || fm.UnmanagedType == UnmanagedType.IDispatch
-                                       || fm.UnmanagedType == UnmanagedType.IUnknown)
-                               {
-                                       if (blob.Length != 0)
-                                       {
-                                               fm.IidParameterIndex = blob.ReadCompressedUInt();
-                                       }
-                               }
-                               else if (fm.UnmanagedType == UnmanagedType.CustomMarshaler)
-                               {
-                                       blob.ReadCompressedUInt();
-                                       blob.ReadCompressedUInt();
-                                       fm.MarshalType = ReadString(blob);
-                                       fm.MarshalCookie = ReadString(blob);
-
-                                       TypeNameParser parser = TypeNameParser.Parse(fm.MarshalType, false);
-                                       if (!parser.Error)
-                                       {
-                                               fm.MarshalTypeRef = parser.GetType(module.universe, module.Assembly, false, fm.MarshalType, false, false);
-                                       }
-                               }
-                               return true;
-                       }
-                       return false;
-               }
-
-               internal static void SetMarshalAsAttribute(ModuleBuilder module, int token, CustomAttributeBuilder attribute)
-               {
-                       attribute = attribute.DecodeBlob(module.Assembly);
-                       FieldMarshalTable.Record rec = new FieldMarshalTable.Record();
-                       rec.Parent = token;
-                       rec.NativeType = WriteMarshallingDescriptor(module, attribute);
-                       module.FieldMarshal.AddRecord(rec);
-               }
-
-               private static int WriteMarshallingDescriptor(ModuleBuilder module, CustomAttributeBuilder attribute)
-               {
-                       UnmanagedType unmanagedType;
-                       object val = attribute.GetConstructorArgument(0);
-                       if (val is short)
-                       {
-                               unmanagedType = (UnmanagedType)(short)val;
-                       }
-                       else if (val is int)
-                       {
-                               unmanagedType = (UnmanagedType)(int)val;
-                       }
-                       else
-                       {
-                               unmanagedType = (UnmanagedType)val;
-                       }
-
-                       ByteBuffer bb = new ByteBuffer(5);
-                       bb.WriteCompressedUInt((int)unmanagedType);
-
-                       if (unmanagedType == UnmanagedType.LPArray)
-                       {
-                               UnmanagedType arraySubType = attribute.GetFieldValue<UnmanagedType>("ArraySubType") ?? NATIVE_TYPE_MAX;
-                               bb.WriteCompressedUInt((int)arraySubType);
-                               int? sizeParamIndex = attribute.GetFieldValue<short>("SizeParamIndex");
-                               int? sizeConst = attribute.GetFieldValue<int>("SizeConst");
-                               if (sizeParamIndex != null)
-                               {
-                                       bb.WriteCompressedUInt(sizeParamIndex.Value);
-                                       if (sizeConst != null)
-                                       {
-                                               bb.WriteCompressedUInt(sizeConst.Value);
-                                               bb.WriteCompressedUInt(1); // flag that says that SizeParamIndex was specified
-                                       }
-                               }
-                               else if (sizeConst != null)
-                               {
-                                       bb.WriteCompressedUInt(0); // SizeParamIndex
-                                       bb.WriteCompressedUInt(sizeConst.Value);
-                                       bb.WriteCompressedUInt(0); // flag that says that SizeParamIndex was not specified
-                               }
-                       }
-                       else if (unmanagedType == UnmanagedType.SafeArray)
-                       {
-                               VarEnum? safeArraySubType = attribute.GetFieldValue<VarEnum>("SafeArraySubType");
-                               if (safeArraySubType != null)
-                               {
-                                       bb.WriteCompressedUInt((int)safeArraySubType);
-                                       Type safeArrayUserDefinedSubType = (Type)attribute.GetFieldValue("SafeArrayUserDefinedSubType");
-                                       if (safeArrayUserDefinedSubType != null)
-                                       {
-                                               WriteType(module, bb, safeArrayUserDefinedSubType);
-                                       }
-                               }
-                       }
-                       else if (unmanagedType == UnmanagedType.ByValArray)
-                       {
-                               bb.WriteCompressedUInt(attribute.GetFieldValue<int>("SizeConst") ?? 1);
-                               UnmanagedType? arraySubType = attribute.GetFieldValue<UnmanagedType>("ArraySubType");
-                               if (arraySubType != null)
-                               {
-                                       bb.WriteCompressedUInt((int)arraySubType);
-                               }
-                       }
-                       else if (unmanagedType == UnmanagedType.ByValTStr)
-                       {
-                               bb.WriteCompressedUInt(attribute.GetFieldValue<int>("SizeConst").Value);
-                       }
-                       else if (unmanagedType == UnmanagedType.Interface
-                               || unmanagedType == UnmanagedType.IDispatch
-                               || unmanagedType == UnmanagedType.IUnknown)
-                       {
-                               int? iidParameterIndex = attribute.GetFieldValue<int>("IidParameterIndex");
-                               if (iidParameterIndex != null)
-                               {
-                                       bb.WriteCompressedUInt(iidParameterIndex.Value);
-                               }
-                       }
-                       else if (unmanagedType == UnmanagedType.CustomMarshaler)
-                       {
-                               bb.WriteCompressedUInt(0);
-                               bb.WriteCompressedUInt(0);
-                               string marshalType = (string)attribute.GetFieldValue("MarshalType");
-                               if (marshalType != null)
-                               {
-                                       WriteString(bb, marshalType);
-                               }
-                               else
-                               {
-                                       WriteType(module, bb, (Type)attribute.GetFieldValue("MarshalTypeRef"));
-                               }
-                               WriteString(bb, (string)attribute.GetFieldValue("MarshalCookie") ?? "");
-                       }
-
-                       return module.Blobs.Add(bb);
-               }
-
-               private static Type ReadType(Module module, ByteReader br)
-               {
-                       string str = ReadString(br);
-                       if (str == "")
-                       {
-                               return null;
-                       }
-                       return module.Assembly.GetType(str) ?? module.universe.GetType(str, true);
-               }
-
-               private static void WriteType(Module module, ByteBuffer bb, Type type)
-               {
-                       WriteString(bb, type.Assembly == module.Assembly ? type.FullName : type.AssemblyQualifiedName);
-               }
-
-               private static string ReadString(ByteReader br)
-               {
-                       return Encoding.UTF8.GetString(br.ReadBytes(br.ReadCompressedUInt()));
-               }
-
-               private static void WriteString(ByteBuffer bb, string str)
-               {
-                       byte[] buf = Encoding.UTF8.GetBytes(str);
-                       bb.WriteCompressedUInt(buf.Length);
-                       bb.Write(buf);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MemberInfo.cs b/mcs/class/IKVM.Reflection/MemberInfo.cs
deleted file mode 100644 (file)
index 1a8173b..0000000
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-// disable warnings that complain about us having == and != operators without also overriding Equals/GetHashCode,
-// this is intentional because most subtypes use reference equality
-#pragma warning disable 660, 661
-       public abstract class MemberInfo : ICustomAttributeProvider
-       {
-               // prevent external subclasses
-               internal MemberInfo()
-               {
-               }
-
-               public abstract string Name { get; }
-               public abstract Type DeclaringType { get; }
-               public abstract MemberTypes MemberType { get; }
-
-               public virtual Type ReflectedType
-               {
-                       get { return DeclaringType; }
-               }
-
-               internal abstract MemberInfo SetReflectedType(Type type);
-
-               public virtual int MetadataToken
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public abstract Module Module
-               {
-                       get;
-               }
-
-               public virtual bool __IsMissing
-               {
-                       get { return false; }
-               }
-
-               public bool IsDefined(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
-               }
-
-               public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
-               }
-
-               public IList<CustomAttributeData> GetCustomAttributesData()
-               {
-                       return CustomAttributeData.GetCustomAttributes(this);
-               }
-
-               public IEnumerable<CustomAttributeData> CustomAttributes
-               {
-                       get { return GetCustomAttributesData(); }
-               }
-
-               public static bool operator ==(MemberInfo m1, MemberInfo m2)
-               {
-                       return ReferenceEquals(m1, m2) || (!ReferenceEquals(m1, null) && m1.Equals(m2));
-               }
-
-               public static bool operator !=(MemberInfo m1, MemberInfo m2)
-               {
-                       return !(m1 == m2);
-               }
-
-               internal abstract int GetCurrentToken();
-
-               internal abstract List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType);
-
-               internal abstract bool IsBaked { get; }
-
-               internal virtual bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               internal virtual bool BindingFlagsMatchInherited(BindingFlags flags)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               protected static bool BindingFlagsMatch(bool state, BindingFlags flags, BindingFlags trueFlag, BindingFlags falseFlag)
-               {
-                       return (state && (flags & trueFlag) == trueFlag)
-                               || (!state && (flags & falseFlag) == falseFlag);
-               }
-
-               protected static T SetReflectedType<T>(T member, Type type)
-                       where T : MemberInfo
-               {
-                       return member == null ? null : (T)member.SetReflectedType(type);
-               }
-
-               protected static T[] SetReflectedType<T>(T[] members, Type type)
-                       where T : MemberInfo
-               {
-                       for (int i = 0; i < members.Length; i++)
-                       {
-                               members[i] = SetReflectedType(members[i], type);
-                       }
-                       return members;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Metadata/CliHeader.cs b/mcs/class/IKVM.Reflection/Metadata/CliHeader.cs
deleted file mode 100644 (file)
index cb2574b..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System.IO;
-
-namespace IKVM.Reflection.Metadata
-{
-       struct RvaSize
-       {
-               internal uint VirtualAddress;
-               internal uint Size;
-
-               internal void Read(BinaryReader br)
-               {
-                       VirtualAddress = br.ReadUInt32();
-                       Size = br.ReadUInt32();
-               }
-
-               internal void Write(IKVM.Reflection.Writer.MetadataWriter mw)
-               {
-                       mw.Write(VirtualAddress);
-                       mw.Write(Size);
-               }
-       }
-
-       sealed class CliHeader
-       {
-               internal const uint COMIMAGE_FLAGS_ILONLY = 0x00000001;
-               internal const uint COMIMAGE_FLAGS_32BITREQUIRED = 0x00000002;
-               internal const uint COMIMAGE_FLAGS_STRONGNAMESIGNED = 0x00000008;
-               internal const uint COMIMAGE_FLAGS_NATIVE_ENTRYPOINT = 0x00000010;
-               internal const uint COMIMAGE_FLAGS_32BITPREFERRED = 0x00020000;
-
-               internal uint Cb = 0x48;
-               internal ushort MajorRuntimeVersion;
-               internal ushort MinorRuntimeVersion;
-               internal RvaSize MetaData;
-               internal uint Flags;
-               internal uint EntryPointToken;
-               internal RvaSize Resources;
-               internal RvaSize StrongNameSignature;
-               internal RvaSize CodeManagerTable;
-               internal RvaSize VTableFixups;
-               internal RvaSize ExportAddressTableJumps;
-               internal RvaSize ManagedNativeHeader;
-
-               internal void Read(BinaryReader br)
-               {
-                       Cb = br.ReadUInt32();
-                       MajorRuntimeVersion = br.ReadUInt16();
-                       MinorRuntimeVersion = br.ReadUInt16();
-                       MetaData.Read(br);
-                       Flags = br.ReadUInt32();
-                       EntryPointToken = br.ReadUInt32();
-                       Resources.Read(br);
-                       StrongNameSignature.Read(br);
-                       CodeManagerTable.Read(br);
-                       VTableFixups.Read(br);
-                       ExportAddressTableJumps.Read(br);
-                       ManagedNativeHeader.Read(br);
-               }
-
-               internal void Write(IKVM.Reflection.Writer.MetadataWriter mw)
-               {
-                       mw.Write(Cb);
-                       mw.Write(MajorRuntimeVersion);
-                       mw.Write(MinorRuntimeVersion);
-                       MetaData.Write(mw);
-                       mw.Write(Flags);
-                       mw.Write(EntryPointToken);
-                       Resources.Write(mw);
-                       StrongNameSignature.Write(mw);
-                       CodeManagerTable.Write(mw);
-                       VTableFixups.Write(mw);
-                       ExportAddressTableJumps.Write(mw);
-                       ManagedNativeHeader.Write(mw);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Metadata/MetadataRW.cs b/mcs/class/IKVM.Reflection/Metadata/MetadataRW.cs
deleted file mode 100644 (file)
index d03c8d6..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection.Metadata
-{
-       // base class for MetadataReader and MetadataWriter
-       abstract class MetadataRW
-       {
-               internal readonly bool bigStrings;
-               internal readonly bool bigGuids;
-               internal readonly bool bigBlobs;
-               internal readonly bool bigResolutionScope;
-               internal readonly bool bigTypeDefOrRef;
-               internal readonly bool bigMemberRefParent;
-               internal readonly bool bigHasCustomAttribute;
-               internal readonly bool bigCustomAttributeType;
-               internal readonly bool bigMethodDefOrRef;
-               internal readonly bool bigHasConstant;
-               internal readonly bool bigHasSemantics;
-               internal readonly bool bigHasFieldMarshal;
-               internal readonly bool bigHasDeclSecurity;
-               internal readonly bool bigTypeOrMethodDef;
-               internal readonly bool bigMemberForwarded;
-               internal readonly bool bigImplementation;
-               internal readonly bool bigField;
-               internal readonly bool bigMethodDef;
-               internal readonly bool bigParam;
-               internal readonly bool bigTypeDef;
-               internal readonly bool bigProperty;
-               internal readonly bool bigEvent;
-               internal readonly bool bigGenericParam;
-               internal readonly bool bigModuleRef;
-
-               protected MetadataRW(Module module, bool bigStrings, bool bigGuids, bool bigBlobs)
-               {
-                       this.bigStrings = bigStrings;
-                       this.bigGuids = bigGuids;
-                       this.bigBlobs = bigBlobs;
-                       this.bigField = module.Field.IsBig;
-                       this.bigMethodDef = module.MethodDef.IsBig;
-                       this.bigParam = module.Param.IsBig;
-                       this.bigTypeDef = module.TypeDef.IsBig;
-                       this.bigProperty = module.Property.IsBig;
-                       this.bigEvent = module.Event.IsBig;
-                       this.bigGenericParam = module.GenericParam.IsBig;
-                       this.bigModuleRef = module.ModuleRef.IsBig;
-                       this.bigResolutionScope = IsBig(2, module.ModuleTable, module.ModuleRef, module.AssemblyRef, module.TypeRef);
-                       this.bigTypeDefOrRef = IsBig(2, module.TypeDef, module.TypeRef, module.TypeSpec);
-                       this.bigMemberRefParent = IsBig(3, module.TypeDef, module.TypeRef, module.ModuleRef, module.MethodDef, module.TypeSpec);
-                       this.bigMethodDefOrRef = IsBig(1, module.MethodDef, module.MemberRef);
-                       this.bigHasCustomAttribute = IsBig(5, module.MethodDef, module.Field, module.TypeRef, module.TypeDef, module.Param, module.InterfaceImpl, module.MemberRef,
-                               module.ModuleTable, /*module.Permission,*/ module.Property, module.Event, module.StandAloneSig, module.ModuleRef, module.TypeSpec, module.AssemblyTable,
-                               module.AssemblyRef, module.File, module.ExportedType, module.ManifestResource);
-                       this.bigCustomAttributeType = IsBig(3, module.MethodDef, module.MemberRef);
-                       this.bigHasConstant = IsBig(2, module.Field, module.Param, module.Property);
-                       this.bigHasSemantics = IsBig(1, module.Event, module.Property);
-                       this.bigHasFieldMarshal = IsBig(1, module.Field, module.Param);
-                       this.bigHasDeclSecurity = IsBig(2, module.TypeDef, module.MethodDef, module.AssemblyTable);
-                       this.bigTypeOrMethodDef = IsBig(1, module.TypeDef, module.MethodDef);
-                       this.bigMemberForwarded = IsBig(1, module.Field, module.MethodDef);
-                       this.bigImplementation = IsBig(2, module.File, module.AssemblyRef, module.ExportedType);
-               }
-
-               private static bool IsBig(int bitsUsed, params Table[] tables)
-               {
-                       int limit = 1 << (16 - bitsUsed);
-                       foreach (Table table in tables)
-                       {
-                               if (table.RowCount >= limit)
-                               {
-                                       return true;
-                               }
-                       }
-                       return false;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Metadata/Tables.cs b/mcs/class/IKVM.Reflection/Metadata/Tables.cs
deleted file mode 100644 (file)
index b35debf..0000000
+++ /dev/null
@@ -1,2722 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection.Metadata
-{
-       internal abstract class Table
-       {
-               internal bool Sorted;
-
-               internal bool IsBig
-               {
-                       get { return RowCount > 65535; }
-               }
-
-               internal abstract int RowCount { get; set; }
-
-               internal abstract void Write(MetadataWriter mw);
-               internal abstract void Read(MetadataReader mr);
-
-               internal int GetLength(MetadataWriter md)
-               {
-                       return RowCount * GetRowSize(new RowSizeCalc(md));
-               }
-
-               protected abstract int GetRowSize(RowSizeCalc rsc);
-
-               protected sealed class RowSizeCalc
-               {
-                       private readonly MetadataWriter mw;
-                       private int size;
-
-                       internal RowSizeCalc(MetadataWriter mw)
-                       {
-                               this.mw = mw;
-                       }
-
-                       internal RowSizeCalc AddFixed(int size)
-                       {
-                               this.size += size;
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteStringIndex()
-                       {
-                               if (mw.bigStrings)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteGuidIndex()
-                       {
-                               if (mw.bigGuids)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteBlobIndex()
-                       {
-                               if (mw.bigBlobs)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteTypeDefOrRef()
-                       {
-                               if (mw.bigTypeDefOrRef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteField()
-                       {
-                               if (mw.bigField)
-                               {
-                                       size += 4;
-                               }
-                               else
-                               {
-                                       size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteMethodDef()
-                       {
-                               if (mw.bigMethodDef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteParam()
-                       {
-                               if (mw.bigParam)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteResolutionScope()
-                       {
-                               if (mw.bigResolutionScope)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteMemberRefParent()
-                       {
-                               if (mw.bigMemberRefParent)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteHasCustomAttribute()
-                       {
-                               if (mw.bigHasCustomAttribute)
-                               {
-                                       size += 4;
-                               }
-                               else
-                               {
-                                       size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteCustomAttributeType()
-                       {
-                               if (mw.bigCustomAttributeType)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteHasConstant()
-                       {
-                               if (mw.bigHasConstant)
-                               {
-                                       size += 4;
-                               }
-                               else
-                               {
-                                       size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteTypeDef()
-                       {
-                               if (mw.bigTypeDef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteMethodDefOrRef()
-                       {
-                               if (mw.bigMethodDefOrRef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteEvent()
-                       {
-                               if (mw.bigEvent)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteProperty()
-                       {
-                               if (mw.bigProperty)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteHasSemantics()
-                       {
-                               if (mw.bigHasSemantics)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteImplementation()
-                       {
-                               if (mw.bigImplementation)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteTypeOrMethodDef()
-                       {
-                               if (mw.bigTypeOrMethodDef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteGenericParam()
-                       {
-                               if (mw.bigGenericParam)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteHasDeclSecurity()
-                       {
-                               if (mw.bigHasDeclSecurity)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteMemberForwarded()
-                       {
-                               if (mw.bigMemberForwarded)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteModuleRef()
-                       {
-                               if (mw.bigModuleRef)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal RowSizeCalc WriteHasFieldMarshal()
-                       {
-                               if (mw.bigHasFieldMarshal)
-                               {
-                                       this.size += 4;
-                               }
-                               else
-                               {
-                                       this.size += 2;
-                               }
-                               return this;
-                       }
-
-                       internal int Value
-                       {
-                               get { return size; }
-                       }
-               }
-       }
-
-       abstract class Table<T> : Table
-       {
-               internal T[] records = Empty<T>.Array;
-               protected int rowCount;
-
-               internal sealed override int RowCount
-               {
-                       get { return rowCount; }
-                       set { rowCount = value; records = new T[value]; }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               internal int AddRecord(T newRecord)
-               {
-                       if (rowCount == records.Length)
-                       {
-                               Array.Resize(ref records, Math.Max(16, records.Length * 2));
-                       }
-                       records[rowCount++] = newRecord;
-                       return rowCount;
-               }
-
-               internal int AddVirtualRecord()
-               {
-                       return ++rowCount;
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       throw new InvalidOperationException();
-               }
-       }
-
-       abstract class SortedTable<T> : Table<T>
-               where T : SortedTable<T>.IRecord
-       {
-               internal interface IRecord
-               {
-                       int SortKey { get; }
-                       int FilterKey { get; }
-               }
-
-               internal struct Enumerable
-               {
-                       private readonly SortedTable<T> table;
-                       private readonly int token;
-
-                       internal Enumerable(SortedTable<T> table, int token)
-                       {
-                               this.table = table;
-                               this.token = token;
-                       }
-
-                       public Enumerator GetEnumerator()
-                       {
-                               T[] records = table.records;
-                               if (!table.Sorted)
-                               {
-                                       return new Enumerator(records, table.RowCount - 1, -1, token);
-                               }
-                               int index = BinarySearch(records, table.RowCount, token & 0xFFFFFF);
-                               if (index < 0)
-                               {
-                                       return new Enumerator(null, 0, 1, -1);
-                               }
-                               int start = index;
-                               while (start > 0 && (records[start - 1].FilterKey & 0xFFFFFF) == (token & 0xFFFFFF))
-                               {
-                                       start--;
-                               }
-                               int end = index;
-                               int max = table.RowCount - 1;
-                               while (end < max && (records[end + 1].FilterKey & 0xFFFFFF) == (token & 0xFFFFFF))
-                               {
-                                       end++;
-                               }
-                               return new Enumerator(records, end, start - 1, token);
-                       }
-
-                       private static int BinarySearch(T[] records, int length, int maskedToken)
-                       {
-                               int min = 0;
-                               int max = length - 1;
-                               while (min <= max)
-                               {
-                                       int mid = min + ((max - min) / 2);
-                                       int maskedValue = records[mid].FilterKey & 0xFFFFFF;
-                                       if (maskedToken == maskedValue)
-                                       {
-                                               return mid;
-                                       }
-                                       else if (maskedToken < maskedValue)
-                                       {
-                                               max = mid - 1;
-                                       }
-                                       else
-                                       {
-                                               min = mid + 1;
-                                       }
-                               }
-                               return -1;
-                       }
-               }
-
-               internal struct Enumerator
-               {
-                       private readonly T[] records;
-                       private readonly int token;
-                       private readonly int max;
-                       private int index;
-
-                       internal Enumerator(T[] records, int max, int index, int token)
-                       {
-                               this.records = records;
-                               this.token = token;
-                               this.max = max;
-                               this.index = index;
-                       }
-
-                       public int Current
-                       {
-                               get { return index; }
-                       }
-
-                       public bool MoveNext()
-                       {
-                               while (index < max)
-                               {
-                                       index++;
-                                       if (records[index].FilterKey == token)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal Enumerable Filter(int token)
-               {
-                       return new Enumerable(this, token);
-               }
-
-               protected void Sort()
-               {
-                       ulong[] map = new ulong[rowCount];
-                       for (uint i = 0; i < map.Length; i++)
-                       {
-                               map[i] = ((ulong)records[i].SortKey << 32) | i;
-                       }
-                       Array.Sort(map);
-                       T[] newRecords = new T[rowCount];
-                       for (int i = 0; i < map.Length; i++)
-                       {
-                               newRecords[i] = records[(int)map[i]];
-                       }
-                       records = newRecords;
-               }
-       }
-
-       sealed class ModuleTable : Table<ModuleTable.Record>
-       {
-               internal const int Index = 0x00;
-
-               internal struct Record
-               {
-                       internal short Generation;
-                       internal int Name; // -> StringHeap
-                       internal int Mvid; // -> GuidHeap
-                       internal int EncId; // -> GuidHeap
-                       internal int EncBaseId; // -> GuidHeap
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Generation = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Mvid = mr.ReadGuidIndex();
-                               records[i].EncId = mr.ReadGuidIndex();
-                               records[i].EncBaseId = mr.ReadGuidIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Generation);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteGuidIndex(records[i].Mvid);
-                               mw.WriteGuidIndex(records[i].EncId);
-                               mw.WriteGuidIndex(records[i].EncBaseId);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteStringIndex()
-                               .WriteGuidIndex()
-                               .WriteGuidIndex()
-                               .WriteGuidIndex()
-                               .Value;
-               }
-
-               internal void Add(short generation, int name, int mvid, int encid, int encbaseid)
-               {
-                       Record record = new Record();
-                       record.Generation = generation;
-                       record.Name = name;
-                       record.Mvid = mvid;
-                       record.EncId = encid;
-                       record.EncBaseId = encbaseid;
-                       AddRecord(record);
-               }
-       }
-
-       sealed class TypeRefTable : Table<TypeRefTable.Record>
-       {
-               internal const int Index = 0x01;
-
-               internal struct Record
-               {
-                       internal int ResolutionScope;
-                       internal int TypeName;
-                       internal int TypeNameSpace;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].ResolutionScope = mr.ReadResolutionScope();
-                               records[i].TypeName = mr.ReadStringIndex();
-                               records[i].TypeNameSpace = mr.ReadStringIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteResolutionScope(records[i].ResolutionScope);
-                               mw.WriteStringIndex(records[i].TypeName);
-                               mw.WriteStringIndex(records[i].TypeNameSpace);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteResolutionScope()
-                               .WriteStringIndex()
-                               .WriteStringIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].ResolutionScope);
-                       }
-               }
-       }
-
-       sealed class TypeDefTable : Table<TypeDefTable.Record>
-       {
-               internal const int Index = 0x02;
-
-               internal struct Record
-               {
-                       internal int Flags;
-                       internal int TypeName;
-                       internal int TypeNamespace;
-                       internal int Extends;
-                       internal int FieldList;
-                       internal int MethodList;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].TypeName = mr.ReadStringIndex();
-                               records[i].TypeNamespace = mr.ReadStringIndex();
-                               records[i].Extends = mr.ReadTypeDefOrRef();
-                               records[i].FieldList = mr.ReadField();
-                               records[i].MethodList = mr.ReadMethodDef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       mw.ModuleBuilder.WriteTypeDefTable(mw);
-               }
-
-               internal int AllocToken()
-               {
-                       return 0x02000000 + AddVirtualRecord();
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteStringIndex()
-                               .WriteStringIndex()
-                               .WriteTypeDefOrRef()
-                               .WriteField()
-                               .WriteMethodDef()
-                               .Value;
-               }
-       }
-
-       sealed class FieldPtrTable : Table<int>
-       {
-               internal const int Index = 0x03;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadField();
-                       }
-               }
-       }
-
-       sealed class FieldTable : Table<FieldTable.Record>
-       {
-               internal const int Index = 0x04;
-
-               internal struct Record
-               {
-                       internal short Flags;
-                       internal int Name;
-                       internal int Signature;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Signature = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       mw.ModuleBuilder.WriteFieldTable(mw);
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-       }
-
-       sealed class MethodPtrTable : Table<int>
-       {
-               internal const int Index = 0x05;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadMethodDef();
-                       }
-               }
-       }
-
-       sealed class MethodDefTable : Table<MethodDefTable.Record>
-       {
-               internal const int Index = 0x06;
-               private int baseRVA;
-
-               internal struct Record
-               {
-                       internal int RVA;
-                       internal short ImplFlags;
-                       internal short Flags;
-                       internal int Name;
-                       internal int Signature;
-                       internal int ParamList;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].RVA = mr.ReadInt32();
-                               records[i].ImplFlags = mr.ReadInt16();
-                               records[i].Flags = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Signature = mr.ReadBlobIndex();
-                               records[i].ParamList = mr.ReadParam();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       mw.ModuleBuilder.WriteMethodDefTable(baseRVA, mw);
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(8)
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .WriteParam()
-                               .Value;
-               }
-
-               internal void Fixup(TextSection code)
-               {
-                       baseRVA = (int)code.MethodBodiesRVA;
-               }
-       }
-
-       sealed class ParamPtrTable : Table<int>
-       {
-               internal const int Index = 0x07;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadParam();
-                       }
-               }
-       }
-
-       sealed class ParamTable : Table<ParamTable.Record>
-       {
-               internal const int Index = 0x08;
-
-               internal struct Record
-               {
-                       internal short Flags;
-                       internal short Sequence;
-                       internal int Name;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt16();
-                               records[i].Sequence = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       mw.ModuleBuilder.WriteParamTable(mw);
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteStringIndex()
-                               .Value;
-               }
-       }
-
-       sealed class InterfaceImplTable : SortedTable<InterfaceImplTable.Record>
-       {
-               internal const int Index = 0x09;
-
-               internal struct Record : IRecord
-               {
-                       internal int Class;
-                       internal int Interface;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Class; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Class; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Class = mr.ReadTypeDef();
-                               records[i].Interface = mr.ReadTypeDefOrRef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteTypeDef(records[i].Class);
-                               mw.WriteEncodedTypeDefOrRef(records[i].Interface);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteTypeDef()
-                               .WriteTypeDefOrRef()
-                               .Value;
-               }
-
-               internal void Fixup()
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               int token = records[i].Interface;
-                               switch (token >> 24)
-                               {
-                                       case 0:
-                                               break;
-                                       case TypeDefTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 0;
-                                               break;
-                                       case TypeRefTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 1;
-                                               break;
-                                       case TypeSpecTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 2;
-                                               break;
-                                       default:
-                                               throw new InvalidOperationException();
-                               }
-                               records[i].Interface = token;
-                       }
-                       // LAMESPEC the CLI spec says that InterfaceImpl should be sorted by { Class, Interface },
-                       // but it appears to only be necessary to sort by Class (and csc emits InterfaceImpl records in
-                       // source file order, so to be able to support round tripping, we need to retain ordering as well).
-                       Sort();
-               }
-       }
-
-       sealed class MemberRefTable : Table<MemberRefTable.Record>
-       {
-               internal const int Index = 0x0A;
-
-               internal struct Record
-               {
-                       internal int Class;
-                       internal int Name;
-                       internal int Signature;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Class = mr.ReadMemberRefParent();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Signature = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteMemberRefParent(records[i].Class);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteBlobIndex(records[i].Signature);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteMemberRefParent()
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal int FindOrAddRecord(Record record)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i].Class == record.Class
-                                       && records[i].Name == record.Name
-                                       && records[i].Signature == record.Signature)
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(record);
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Class);
-                       }
-               }
-       }
-
-       sealed class ConstantTable : SortedTable<ConstantTable.Record>
-       {
-               internal const int Index = 0x0B;
-
-               internal struct Record : IRecord
-               {
-                       internal short Type;
-                       internal int Parent;
-                       internal int Value;
-
-                       int IRecord.SortKey
-                       {
-                               get { return EncodeHasConstant(Parent); }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Type = mr.ReadInt16();
-                               records[i].Parent = mr.ReadHasConstant();
-                               records[i].Value = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Type);
-                               mw.WriteHasConstant(records[i].Parent);
-                               mw.WriteBlobIndex(records[i].Value);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteHasConstant()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Parent);
-                       }
-                       Sort();
-               }
-
-               internal static int EncodeHasConstant(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case FieldTable.Index:
-                                       return (token & 0xFFFFFF) << 2 | 0;
-                               case ParamTable.Index:
-                                       return (token & 0xFFFFFF) << 2 | 1;
-                               case PropertyTable.Index:
-                                       return (token & 0xFFFFFF) << 2 | 2;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-               }
-
-               internal object GetRawConstantValue(Module module, int parent)
-               {
-                       foreach (int i in Filter(parent))
-                       {
-                               ByteReader br = module.GetBlob(module.Constant.records[i].Value);
-                               switch (module.Constant.records[i].Type)
-                               {
-                                       // see ModuleBuilder.AddConstant for the encodings
-                                       case Signature.ELEMENT_TYPE_BOOLEAN:
-                                               return br.ReadByte() != 0;
-                                       case Signature.ELEMENT_TYPE_I1:
-                                               return br.ReadSByte();
-                                       case Signature.ELEMENT_TYPE_I2:
-                                               return br.ReadInt16();
-                                       case Signature.ELEMENT_TYPE_I4:
-                                               return br.ReadInt32();
-                                       case Signature.ELEMENT_TYPE_I8:
-                                               return br.ReadInt64();
-                                       case Signature.ELEMENT_TYPE_U1:
-                                               return br.ReadByte();
-                                       case Signature.ELEMENT_TYPE_U2:
-                                               return br.ReadUInt16();
-                                       case Signature.ELEMENT_TYPE_U4:
-                                               return br.ReadUInt32();
-                                       case Signature.ELEMENT_TYPE_U8:
-                                               return br.ReadUInt64();
-                                       case Signature.ELEMENT_TYPE_R4:
-                                               return br.ReadSingle();
-                                       case Signature.ELEMENT_TYPE_R8:
-                                               return br.ReadDouble();
-                                       case Signature.ELEMENT_TYPE_CHAR:
-                                               return br.ReadChar();
-                                       case Signature.ELEMENT_TYPE_STRING:
-                                               {
-                                                       char[] chars = new char[br.Length / 2];
-                                                       for (int j = 0; j < chars.Length; j++)
-                                                       {
-                                                               chars[j] = br.ReadChar();
-                                                       }
-                                                       return new String(chars);
-                                               }
-                                       case Signature.ELEMENT_TYPE_CLASS:
-                                               if (br.ReadInt32() != 0)
-                                               {
-                                                       throw new BadImageFormatException();
-                                               }
-                                               return null;
-                                       default:
-                                               throw new BadImageFormatException();
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-       }
-
-       sealed class CustomAttributeTable : SortedTable<CustomAttributeTable.Record>
-       {
-               internal const int Index = 0x0C;
-
-               internal struct Record : IRecord
-               {
-                       internal int Parent;
-                       internal int Type;
-                       internal int Value;
-
-                       int IRecord.SortKey
-                       {
-                               get { return EncodeHasCustomAttribute(Parent); }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Parent = mr.ReadHasCustomAttribute();
-                               records[i].Type = mr.ReadCustomAttributeType();
-                               records[i].Value = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteHasCustomAttribute(records[i].Parent);
-                               mw.WriteCustomAttributeType(records[i].Type);
-                               mw.WriteBlobIndex(records[i].Value);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteHasCustomAttribute()
-                               .WriteCustomAttributeType()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       int[] genericParamFixup = moduleBuilder.GenericParam.GetIndexFixup();
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Type);
-                               moduleBuilder.FixupPseudoToken(ref records[i].Parent);
-                               if (records[i].Parent >> 24 == GenericParamTable.Index)
-                               {
-                                       records[i].Parent = (GenericParamTable.Index << 24) + genericParamFixup[(records[i].Parent & 0xFFFFFF) - 1] + 1;
-                               }
-                       }
-                       Sort();
-               }
-
-               internal static int EncodeHasCustomAttribute(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case MethodDefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 0;
-                               case FieldTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 1;
-                               case TypeRefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 2;
-                               case TypeDefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 3;
-                               case ParamTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 4;
-                               case InterfaceImplTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 5;
-                               case MemberRefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 6;
-                               case ModuleTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 7;
-                               // Permission (8) table doesn't exist in the spec
-                               case PropertyTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 9;
-                               case EventTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 10;
-                               case StandAloneSigTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 11;
-                               case ModuleRefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 12;
-                               case TypeSpecTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 13;
-                               case AssemblyTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 14;
-                               case AssemblyRefTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 15;
-                               case FileTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 16;
-                               case ExportedTypeTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 17;
-                               case ManifestResourceTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 18;
-                               case GenericParamTable.Index:
-                                       return (token & 0xFFFFFF) << 5 | 19;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-               }
-       }
-
-       sealed class FieldMarshalTable : SortedTable<FieldMarshalTable.Record>
-       {
-               internal const int Index = 0x0D;
-
-               internal struct Record : IRecord
-               {
-                       internal int Parent;
-                       internal int NativeType;
-
-                       int IRecord.SortKey
-                       {
-                               get { return EncodeHasFieldMarshal(Parent); }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Parent = mr.ReadHasFieldMarshal();
-                               records[i].NativeType = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteHasFieldMarshal(records[i].Parent);
-                               mw.WriteBlobIndex(records[i].NativeType);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteHasFieldMarshal()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               records[i].Parent = moduleBuilder.ResolvePseudoToken(records[i].Parent);
-                       }
-                       Sort();
-               }
-
-               internal static int EncodeHasFieldMarshal(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case FieldTable.Index:
-                                       return (token & 0xFFFFFF) << 1 | 0;
-                               case ParamTable.Index:
-                                       return (token & 0xFFFFFF) << 1 | 1;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-               }
-       }
-
-       sealed class DeclSecurityTable : SortedTable<DeclSecurityTable.Record>
-       {
-               internal const int Index = 0x0E;
-
-               internal struct Record : IRecord
-               {
-                       internal short Action;
-                       internal int Parent;
-                       internal int PermissionSet;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Parent; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Action = mr.ReadInt16();
-                               records[i].Parent = mr.ReadHasDeclSecurity();
-                               records[i].PermissionSet = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Action);
-                               mw.WriteHasDeclSecurity(records[i].Parent);
-                               mw.WriteBlobIndex(records[i].PermissionSet);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteHasDeclSecurity()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               int token = records[i].Parent;
-                               moduleBuilder.FixupPseudoToken(ref token);
-                               // do the HasDeclSecurity encoding, so that we can sort the table
-                               switch (token >> 24)
-                               {
-                                       case TypeDefTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 0;
-                                               break;
-                                       case MethodDefTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 1;
-                                               break;
-                                       case AssemblyTable.Index:
-                                               token = (token & 0xFFFFFF) << 2 | 2;
-                                               break;
-                                       default:
-                                               throw new InvalidOperationException();
-                               }
-                               records[i].Parent = token;
-                       }
-                       Sort();
-               }
-       }
-
-       sealed class ClassLayoutTable : SortedTable<ClassLayoutTable.Record>
-       {
-               internal const int Index = 0x0f;
-
-               internal struct Record : IRecord
-               {
-                       internal short PackingSize;
-                       internal int ClassSize;
-                       internal int Parent;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Parent; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].PackingSize = mr.ReadInt16();
-                               records[i].ClassSize = mr.ReadInt32();
-                               records[i].Parent = mr.ReadTypeDef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       Sort();
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].PackingSize);
-                               mw.Write(records[i].ClassSize);
-                               mw.WriteTypeDef(records[i].Parent);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(6)
-                               .WriteTypeDef()
-                               .Value;
-               }
-       }
-
-       sealed class FieldLayoutTable : SortedTable<FieldLayoutTable.Record>
-       {
-               internal const int Index = 0x10;
-
-               internal struct Record : IRecord
-               {
-                       internal int Offset;
-                       internal int Field;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Field; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Field; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Offset = mr.ReadInt32();
-                               records[i].Field = mr.ReadField();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Offset);
-                               mw.WriteField(records[i].Field);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteField()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               records[i].Field = moduleBuilder.ResolvePseudoToken(records[i].Field) & 0xFFFFFF;
-                       }
-                       Sort();
-               }
-       }
-
-       sealed class StandAloneSigTable : Table<int>
-       {
-               internal const int Index = 0x11;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteBlobIndex(records[i]);
-                       }
-               }
-
-               protected override int GetRowSize(Table.RowSizeCalc rsc)
-               {
-                       return rsc.WriteBlobIndex().Value;
-               }
-
-               internal int FindOrAddRecord(int blob)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i] == blob)
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(blob);
-               }
-       }
-
-       sealed class EventMapTable : SortedTable<EventMapTable.Record>
-       {
-               internal const int Index = 0x12;
-
-               internal struct Record : IRecord
-               {
-                       internal int Parent;
-                       internal int EventList;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Parent; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Parent = mr.ReadTypeDef();
-                               records[i].EventList = mr.ReadEvent();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteTypeDef(records[i].Parent);
-                               mw.WriteEvent(records[i].EventList);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteTypeDef()
-                               .WriteEvent()
-                               .Value;
-               }
-       }
-
-       sealed class EventPtrTable : Table<int>
-       {
-               internal const int Index = 0x13;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadEvent();
-                       }
-               }
-       }
-
-       sealed class EventTable : Table<EventTable.Record>
-       {
-               internal const int Index = 0x14;
-
-               internal struct Record
-               {
-                       internal short EventFlags;
-                       internal int Name;
-                       internal int EventType;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].EventFlags = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].EventType = mr.ReadTypeDefOrRef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].EventFlags);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteTypeDefOrRef(records[i].EventType);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteStringIndex()
-                               .WriteTypeDefOrRef()
-                               .Value;
-               }
-       }
-
-       sealed class PropertyMapTable : SortedTable<PropertyMapTable.Record>
-       {
-               internal const int Index = 0x15;
-
-               internal struct Record : IRecord
-               {
-                       internal int Parent;
-                       internal int PropertyList;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Parent; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Parent; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Parent = mr.ReadTypeDef();
-                               records[i].PropertyList = mr.ReadProperty();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteTypeDef(records[i].Parent);
-                               mw.WriteProperty(records[i].PropertyList);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteTypeDef()
-                               .WriteProperty()
-                               .Value;
-               }
-       }
-
-       sealed class PropertyPtrTable : Table<int>
-       {
-               internal const int Index = 0x16;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadProperty();
-                       }
-               }
-       }
-
-       sealed class PropertyTable : Table<PropertyTable.Record>
-       {
-               internal const int Index = 0x17;
-
-               internal struct Record
-               {
-                       internal short Flags;
-                       internal int Name;
-                       internal int Type;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt16();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Type = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Flags);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteBlobIndex(records[i].Type);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-       }
-
-       sealed class MethodSemanticsTable : SortedTable<MethodSemanticsTable.Record>
-       {
-               internal const int Index = 0x18;
-
-               // semantics
-               internal const short Setter = 0x0001;
-               internal const short Getter = 0x0002;
-               internal const short Other = 0x0004;
-               internal const short AddOn = 0x0008;
-               internal const short RemoveOn = 0x0010;
-               internal const short Fire = 0x0020;
-
-               internal struct Record : IRecord
-               {
-                       internal short Semantics;
-                       internal int Method;
-                       internal int Association;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Association; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Association; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Semantics = mr.ReadInt16();
-                               records[i].Method = mr.ReadMethodDef();
-                               records[i].Association = mr.ReadHasSemantics();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Semantics);
-                               mw.WriteMethodDef(records[i].Method);
-                               mw.WriteHasSemantics(records[i].Association);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteMethodDef()
-                               .WriteHasSemantics()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Method);
-                               int token = records[i].Association;
-                               // do the HasSemantics encoding, so that we can sort the table
-                               switch (token >> 24)
-                               {
-                                       case EventTable.Index:
-                                               token = (token & 0xFFFFFF) << 1 | 0;
-                                               break;
-                                       case PropertyTable.Index:
-                                               token = (token & 0xFFFFFF) << 1 | 1;
-                                               break;
-                                       default:
-                                               throw new InvalidOperationException();
-                               }
-                               records[i].Association = token;
-                       }
-                       Sort();
-               }
-
-               internal MethodInfo GetMethod(Module module, int token, bool nonPublic, short semantics)
-               {
-                       foreach (int i in Filter(token))
-                       {
-                               if ((records[i].Semantics & semantics) != 0)
-                               {
-                                       MethodBase method = module.ResolveMethod((MethodDefTable.Index << 24) + records[i].Method);
-                                       if (nonPublic || method.IsPublic)
-                                       {
-                                               return (MethodInfo)method;
-                                       }
-                               }
-                       }
-                       return null;
-               }
-
-               internal MethodInfo[] GetMethods(Module module, int token, bool nonPublic, short semantics)
-               {
-                       List<MethodInfo> methods = new List<MethodInfo>();
-                       foreach (int i in Filter(token))
-                       {
-                               if ((records[i].Semantics & semantics) != 0)
-                               {
-                                       MethodInfo method = (MethodInfo)module.ResolveMethod((MethodDefTable.Index << 24) + records[i].Method);
-                                       if (nonPublic || method.IsPublic)
-                                       {
-                                               methods.Add(method);
-                                       }
-                               }
-                       }
-                       return methods.ToArray();
-               }
-
-               internal void ComputeFlags(Module module, int token, out bool isPublic, out bool isNonPrivate, out bool isStatic)
-               {
-                       isPublic = false;
-                       isNonPrivate = false;
-                       isStatic = false;
-                       foreach (int i in Filter(token))
-                       {
-                               MethodBase method = module.ResolveMethod((MethodDefTable.Index << 24) + records[i].Method);
-                               isPublic |= method.IsPublic;
-                               isNonPrivate |= (method.Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private;
-                               isStatic |= method.IsStatic;
-                       }
-               }
-       }
-
-       sealed class MethodImplTable : SortedTable<MethodImplTable.Record>
-       {
-               internal const int Index = 0x19;
-
-               internal struct Record : IRecord
-               {
-                       internal int Class;
-                       internal int MethodBody;
-                       internal int MethodDeclaration;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Class; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Class; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Class = mr.ReadTypeDef();
-                               records[i].MethodBody = mr.ReadMethodDefOrRef();
-                               records[i].MethodDeclaration = mr.ReadMethodDefOrRef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteTypeDef(records[i].Class);
-                               mw.WriteMethodDefOrRef(records[i].MethodBody);
-                               mw.WriteMethodDefOrRef(records[i].MethodDeclaration);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteTypeDef()
-                               .WriteMethodDefOrRef()
-                               .WriteMethodDefOrRef()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].MethodBody);
-                               moduleBuilder.FixupPseudoToken(ref records[i].MethodDeclaration);
-                       }
-                       Sort();
-               }
-       }
-
-       sealed class ModuleRefTable : Table<int>
-       {
-               internal const int Index = 0x1A;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadStringIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteStringIndex(records[i]);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteStringIndex()
-                               .Value;
-               }
-
-               internal int FindOrAddRecord(int str)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i] == str)
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(str);
-               }
-       }
-
-       sealed class TypeSpecTable : Table<int>
-       {
-               internal const int Index = 0x1B;
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i] = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteBlobIndex(records[i]);
-                       }
-               }
-
-               protected override int GetRowSize(Table.RowSizeCalc rsc)
-               {
-                       return rsc.WriteBlobIndex().Value;
-               }
-       }
-
-       sealed class ImplMapTable : SortedTable<ImplMapTable.Record>
-       {
-               internal const int Index = 0x1C;
-
-               internal struct Record : IRecord
-               {
-                       internal short MappingFlags;
-                       internal int MemberForwarded;
-                       internal int ImportName;
-                       internal int ImportScope;
-
-                       int IRecord.SortKey
-                       {
-                               get { return MemberForwarded; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return MemberForwarded; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].MappingFlags = mr.ReadInt16();
-                               records[i].MemberForwarded = mr.ReadMemberForwarded();
-                               records[i].ImportName = mr.ReadStringIndex();
-                               records[i].ImportScope = mr.ReadModuleRef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].MappingFlags);
-                               mw.WriteMemberForwarded(records[i].MemberForwarded);
-                               mw.WriteStringIndex(records[i].ImportName);
-                               mw.WriteModuleRef(records[i].ImportScope);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(2)
-                               .WriteMemberForwarded()
-                               .WriteStringIndex()
-                               .WriteModuleRef()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].MemberForwarded);
-                       }
-                       Sort();
-               }
-       }
-
-       sealed class FieldRVATable : SortedTable<FieldRVATable.Record>
-       {
-               internal const int Index = 0x1D;
-
-               internal struct Record : IRecord
-               {
-                       internal int RVA;               // we set the high bit to signify that the RVA is in the CIL stream (instead of .sdata)
-                       internal int Field;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Field; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Field; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].RVA = mr.ReadInt32();
-                               records[i].Field = mr.ReadField();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].RVA);
-                               mw.WriteField(records[i].Field);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteField()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder, int sdataRVA, int cilRVA)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i].RVA < 0)
-                               {
-                                       records[i].RVA = (records[i].RVA & 0x7fffffff) + cilRVA;
-                               }
-                               else
-                               {
-                                       records[i].RVA += sdataRVA;
-                               }
-                               moduleBuilder.FixupPseudoToken(ref records[i].Field);
-                       }
-                       Sort();
-               }
-       }
-
-       sealed class AssemblyTable : Table<AssemblyTable.Record>
-       {
-               internal const int Index = 0x20;
-
-               internal struct Record
-               {
-                       internal int HashAlgId;
-                       internal ushort MajorVersion;
-                       internal ushort MinorVersion;
-                       internal ushort BuildNumber;
-                       internal ushort RevisionNumber;
-                       internal int Flags;
-                       internal int PublicKey;
-                       internal int Name;
-                       internal int Culture;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].HashAlgId = mr.ReadInt32();
-                               records[i].MajorVersion = mr.ReadUInt16();
-                               records[i].MinorVersion = mr.ReadUInt16();
-                               records[i].BuildNumber = mr.ReadUInt16();
-                               records[i].RevisionNumber = mr.ReadUInt16();
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].PublicKey = mr.ReadBlobIndex();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Culture = mr.ReadStringIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].HashAlgId);
-                               mw.Write(records[i].MajorVersion);
-                               mw.Write(records[i].MinorVersion);
-                               mw.Write(records[i].BuildNumber);
-                               mw.Write(records[i].RevisionNumber);
-                               mw.Write(records[i].Flags);
-                               mw.WriteBlobIndex(records[i].PublicKey);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteStringIndex(records[i].Culture);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(16)
-                               .WriteBlobIndex()
-                               .WriteStringIndex()
-                               .WriteStringIndex()
-                               .Value;
-               }
-       }
-
-       sealed class AssemblyRefTable : Table<AssemblyRefTable.Record>
-       {
-               internal const int Index = 0x23;
-
-               internal struct Record
-               {
-                       internal ushort MajorVersion;
-                       internal ushort MinorVersion;
-                       internal ushort BuildNumber;
-                       internal ushort RevisionNumber;
-                       internal int Flags;
-                       internal int PublicKeyOrToken;
-                       internal int Name;
-                       internal int Culture;
-                       internal int HashValue;
-               }
-
-               internal int FindOrAddRecord(Record rec)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               // note that we ignore HashValue here!
-                               if (records[i].Name == rec.Name
-                                       && records[i].MajorVersion == rec.MajorVersion
-                                       && records[i].MinorVersion == rec.MinorVersion
-                                       && records[i].BuildNumber == rec.BuildNumber
-                                       && records[i].RevisionNumber == rec.RevisionNumber
-                                       && records[i].Flags == rec.Flags
-                                       && records[i].PublicKeyOrToken == rec.PublicKeyOrToken
-                                       && records[i].Culture == rec.Culture
-                                       )
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(rec);
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].MajorVersion = mr.ReadUInt16();
-                               records[i].MinorVersion = mr.ReadUInt16();
-                               records[i].BuildNumber = mr.ReadUInt16();
-                               records[i].RevisionNumber = mr.ReadUInt16();
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].PublicKeyOrToken = mr.ReadBlobIndex();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Culture = mr.ReadStringIndex();
-                               records[i].HashValue = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].MajorVersion);
-                               mw.Write(records[i].MinorVersion);
-                               mw.Write(records[i].BuildNumber);
-                               mw.Write(records[i].RevisionNumber);
-                               mw.Write(records[i].Flags);
-                               mw.WriteBlobIndex(records[i].PublicKeyOrToken);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteStringIndex(records[i].Culture);
-                               mw.WriteBlobIndex(records[i].HashValue);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(12)
-                               .WriteBlobIndex()
-                               .WriteStringIndex()
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-       }
-
-       sealed class FileTable : Table<FileTable.Record>
-       {
-               internal const int Index = 0x26;
-
-               internal struct Record
-               {
-                       internal int Flags;
-                       internal int Name;
-                       internal int HashValue;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].HashValue = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Flags);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteBlobIndex(records[i].HashValue);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteStringIndex()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-       }
-
-       sealed class ExportedTypeTable : Table<ExportedTypeTable.Record>
-       {
-               internal const int Index = 0x27;
-
-               internal struct Record
-               {
-                       internal int Flags;
-                       internal int TypeDefId;
-                       internal int TypeName;
-                       internal int TypeNamespace;
-                       internal int Implementation;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].TypeDefId = mr.ReadInt32();
-                               records[i].TypeName = mr.ReadStringIndex();
-                               records[i].TypeNamespace = mr.ReadStringIndex();
-                               records[i].Implementation = mr.ReadImplementation();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Flags);
-                               mw.Write(records[i].TypeDefId);
-                               mw.WriteStringIndex(records[i].TypeName);
-                               mw.WriteStringIndex(records[i].TypeNamespace);
-                               mw.WriteImplementation(records[i].Implementation);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(8)
-                               .WriteStringIndex()
-                               .WriteStringIndex()
-                               .WriteImplementation()
-                               .Value;
-               }
-
-               internal int FindOrAddRecord(Record rec)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i].Implementation == rec.Implementation
-                                       && records[i].TypeName == rec.TypeName
-                                       && records[i].TypeNamespace == rec.TypeNamespace)
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(rec);
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Implementation);
-                       }
-               }
-       }
-
-       sealed class ManifestResourceTable : Table<ManifestResourceTable.Record>
-       {
-               internal const int Index = 0x28;
-
-               internal struct Record
-               {
-                       internal int Offset;
-                       internal int Flags;
-                       internal int Name;
-                       internal int Implementation;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Offset = mr.ReadInt32();
-                               records[i].Flags = mr.ReadInt32();
-                               records[i].Name = mr.ReadStringIndex();
-                               records[i].Implementation = mr.ReadImplementation();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Offset);
-                               mw.Write(records[i].Flags);
-                               mw.WriteStringIndex(records[i].Name);
-                               mw.WriteImplementation(records[i].Implementation);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(8)
-                               .WriteStringIndex()
-                               .WriteImplementation()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Implementation);
-                       }
-               }
-       }
-
-       sealed class NestedClassTable : SortedTable<NestedClassTable.Record>
-       {
-               internal const int Index = 0x29;
-
-               internal struct Record : IRecord
-               {
-                       internal int NestedClass;
-                       internal int EnclosingClass;
-
-                       int IRecord.SortKey
-                       {
-                               get { return NestedClass; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return NestedClass; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].NestedClass = mr.ReadTypeDef();
-                               records[i].EnclosingClass = mr.ReadTypeDef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteTypeDef(records[i].NestedClass);
-                               mw.WriteTypeDef(records[i].EnclosingClass);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteTypeDef()
-                               .WriteTypeDef()
-                               .Value;
-               }
-
-               internal List<int> GetNestedClasses(int enclosingClass)
-               {
-                       List<int> nestedClasses = new List<int>();
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i].EnclosingClass == enclosingClass)
-                               {
-                                       nestedClasses.Add(records[i].NestedClass);
-                               }
-                       }
-                       return nestedClasses;
-               }
-       }
-
-       sealed class GenericParamTable : SortedTable<GenericParamTable.Record>, IComparer<GenericParamTable.Record>
-       {
-               internal const int Index = 0x2A;
-
-               internal struct Record : IRecord
-               {
-                       internal short Number;
-                       internal short Flags;
-                       internal int Owner;
-                       internal int Name;
-                       // not part of the table, we use it to be able to fixup the GenericParamConstraint table
-                       internal int unsortedIndex;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Owner; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Owner; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Number = mr.ReadInt16();
-                               records[i].Flags = mr.ReadInt16();
-                               records[i].Owner = mr.ReadTypeOrMethodDef();
-                               records[i].Name = mr.ReadStringIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.Write(records[i].Number);
-                               mw.Write(records[i].Flags);
-                               mw.WriteTypeOrMethodDef(records[i].Owner);
-                               mw.WriteStringIndex(records[i].Name);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .AddFixed(4)
-                               .WriteTypeOrMethodDef()
-                               .WriteStringIndex()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               int token = records[i].Owner;
-                               moduleBuilder.FixupPseudoToken(ref token);
-                               // do the TypeOrMethodDef encoding, so that we can sort the table
-                               switch (token >> 24)
-                               {
-                                       case TypeDefTable.Index:
-                                               records[i].Owner = (token & 0xFFFFFF) << 1 | 0;
-                                               break;
-                                       case MethodDefTable.Index:
-                                               records[i].Owner = (token & 0xFFFFFF) << 1 | 1;
-                                               break;
-                                       default:
-                                               throw new InvalidOperationException();
-                               }
-                               records[i].unsortedIndex = i;
-                       }
-                       // FXBUG the unnecessary (IComparer<Record>) cast is a workaround for a .NET 2.0 C# compiler bug
-                       Array.Sort(records, 0, rowCount, (IComparer<Record>)this);
-               }
-
-               int IComparer<Record>.Compare(Record x, Record y)
-               {
-                       if (x.Owner == y.Owner)
-                       {
-                               return x.Number == y.Number ? 0 : (x.Number > y.Number ? 1 : -1);
-                       }
-                       return x.Owner > y.Owner ? 1 : -1;
-               }
-
-               internal void PatchAttribute(int token, GenericParameterAttributes genericParameterAttributes)
-               {
-                       records[(token & 0xFFFFFF) - 1].Flags = (short)genericParameterAttributes;
-               }
-
-               internal int[] GetIndexFixup()
-               {
-                       int[] array = new int[rowCount];
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               array[records[i].unsortedIndex] = i;
-                       }
-                       return array;
-               }
-
-               internal int FindFirstByOwner(int token)
-               {
-                       foreach (int i in Filter(token))
-                       {
-                               return i;
-                       }
-                       return -1;
-               }
-       }
-
-       sealed class MethodSpecTable : Table<MethodSpecTable.Record>
-       {
-               internal const int Index = 0x2B;
-
-               internal struct Record
-               {
-                       internal int Method;
-                       internal int Instantiation;
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Method = mr.ReadMethodDefOrRef();
-                               records[i].Instantiation = mr.ReadBlobIndex();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteMethodDefOrRef(records[i].Method);
-                               mw.WriteBlobIndex(records[i].Instantiation);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteMethodDefOrRef()
-                               .WriteBlobIndex()
-                               .Value;
-               }
-
-               internal int FindOrAddRecord(Record record)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               if (records[i].Method == record.Method
-                                       && records[i].Instantiation == record.Instantiation)
-                               {
-                                       return i + 1;
-                               }
-                       }
-                       return AddRecord(record);
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               moduleBuilder.FixupPseudoToken(ref records[i].Method);
-                       }
-               }
-       }
-
-       sealed class GenericParamConstraintTable : SortedTable<GenericParamConstraintTable.Record>
-       {
-               internal const int Index = 0x2C;
-
-               internal struct Record : IRecord
-               {
-                       internal int Owner;
-                       internal int Constraint;
-
-                       int IRecord.SortKey
-                       {
-                               get { return Owner; }
-                       }
-
-                       int IRecord.FilterKey
-                       {
-                               get { return Owner; }
-                       }
-               }
-
-               internal override void Read(MetadataReader mr)
-               {
-                       for (int i = 0; i < records.Length; i++)
-                       {
-                               records[i].Owner = mr.ReadGenericParam();
-                               records[i].Constraint = mr.ReadTypeDefOrRef();
-                       }
-               }
-
-               internal override void Write(MetadataWriter mw)
-               {
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               mw.WriteGenericParam(records[i].Owner);
-                               mw.WriteTypeDefOrRef(records[i].Constraint);
-                       }
-               }
-
-               protected override int GetRowSize(RowSizeCalc rsc)
-               {
-                       return rsc
-                               .WriteGenericParam()
-                               .WriteTypeDefOrRef()
-                               .Value;
-               }
-
-               internal void Fixup(ModuleBuilder moduleBuilder)
-               {
-                       int[] fixups = moduleBuilder.GenericParam.GetIndexFixup();
-                       for (int i = 0; i < rowCount; i++)
-                       {
-                               records[i].Owner = fixups[records[i].Owner - 1] + 1;
-                       }
-                       Sort();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MethodBase.cs b/mcs/class/IKVM.Reflection/MethodBase.cs
deleted file mode 100644 (file)
index f3810ec..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-
-namespace IKVM.Reflection
-{
-       public abstract class MethodBase : MemberInfo
-       {
-               // prevent external subclasses
-               internal MethodBase()
-               {
-               }
-
-               internal abstract MethodSignature MethodSignature { get; }
-               internal abstract int ParameterCount { get; }
-               public abstract ParameterInfo[] GetParameters();
-               public abstract MethodAttributes Attributes { get; }
-               public abstract MethodImplAttributes GetMethodImplementationFlags();
-               public abstract MethodBody GetMethodBody();
-               public abstract CallingConventions CallingConvention { get; }
-               public abstract int __MethodRVA { get; }
-
-               public bool IsConstructor
-               {
-                       get
-                       {
-                               if ((this.Attributes & MethodAttributes.RTSpecialName) != 0)
-                               {
-                                       string name = this.Name;
-                                       return name == ConstructorInfo.ConstructorName || name == ConstructorInfo.TypeConstructorName;
-                               }
-                               return false;
-                       }
-               }
-
-               public bool IsStatic
-               {
-                       get { return (Attributes & MethodAttributes.Static) != 0; }
-               }
-
-               public bool IsVirtual
-               {
-                       get { return (Attributes & MethodAttributes.Virtual) != 0; }
-               }
-
-               public bool IsAbstract
-               {
-                       get { return (Attributes & MethodAttributes.Abstract) != 0; }
-               }
-
-               public bool IsFinal
-               {
-                       get { return (Attributes & MethodAttributes.Final) != 0; }
-               }
-
-               public bool IsPublic
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public; }
-               }
-
-               public bool IsFamily
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family; }
-               }
-
-               public bool IsFamilyOrAssembly
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem; }
-               }
-
-               public bool IsAssembly
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly; }
-               }
-
-               public bool IsFamilyAndAssembly
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem; }
-               }
-
-               public bool IsPrivate
-               {
-                       get { return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private; }
-               }
-
-               public bool IsSpecialName
-               {
-                       get { return (Attributes & MethodAttributes.SpecialName) != 0; }
-               }
-
-               public bool IsHideBySig
-               {
-                       get { return (Attributes & MethodAttributes.HideBySig) != 0; }
-               }
-
-               public MethodImplAttributes MethodImplementationFlags
-               {
-                       get { return GetMethodImplementationFlags(); }
-               }
-
-               public virtual Type[] GetGenericArguments()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public virtual bool IsGenericMethod
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsGenericMethodDefinition
-               {
-                       get { return false; }
-               }
-
-               public virtual bool ContainsGenericParameters
-               {
-                       get { return IsGenericMethodDefinition; }
-               }
-
-               public virtual MethodBase __GetMethodOnTypeDefinition()
-               {
-                       return this;
-               }
-
-               // This goes to the (uninstantiated) MethodInfo on the (uninstantiated) Type. For constructors
-               // it also has the effect of removing the ConstructorInfo wrapper and returning the underlying MethodInfo.
-               internal abstract MethodInfo GetMethodOnTypeDefinition();
-
-               internal abstract int ImportTo(Emit.ModuleBuilder module);
-
-               internal abstract MethodBase BindTypeParameters(Type type);
-
-               internal sealed override bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
-               }
-
-               internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
-               {
-                       return (Attributes & MethodAttributes.MemberAccessMask) > MethodAttributes.Private
-                               && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MethodBody.cs b/mcs/class/IKVM.Reflection/MethodBody.cs
deleted file mode 100644 (file)
index fc26f6f..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using IKVM.Reflection.Reader;
-using System.IO;
-
-namespace IKVM.Reflection
-{
-       public sealed class MethodBody
-       {
-               private readonly IList<ExceptionHandlingClause> exceptionClauses;
-               private readonly IList<LocalVariableInfo> locals;
-               private readonly bool initLocals;
-               private readonly int maxStack;
-               private readonly int localVarSigTok;
-               private byte[] body;
-
-               internal MethodBody(ModuleReader module, int rva, IGenericContext context)
-               {
-                       const byte CorILMethod_TinyFormat = 0x02;
-                       const byte CorILMethod_FatFormat = 0x03;
-                       const byte CorILMethod_MoreSects = 0x08;
-                       const byte CorILMethod_InitLocals = 0x10;
-                       const byte CorILMethod_Sect_EHTable = 0x01;
-                       const byte CorILMethod_Sect_FatFormat = 0x40;
-                       const byte CorILMethod_Sect_MoreSects = 0x80;
-
-                       List<ExceptionHandlingClause> exceptionClauses = new List<ExceptionHandlingClause>();
-                       List<LocalVariableInfo> locals = new List<LocalVariableInfo>();
-                       module.SeekRVA(rva);
-                       BinaryReader br = new BinaryReader(module.stream);
-                       byte b = br.ReadByte();
-                       if ((b & 3) == CorILMethod_TinyFormat)
-                       {
-                               initLocals = true;
-                               body = br.ReadBytes(b >> 2);
-                               maxStack = 8;
-                       }
-                       else if ((b & 3) == CorILMethod_FatFormat)
-                       {
-                               initLocals = (b & CorILMethod_InitLocals) != 0;
-                               short flagsAndSize = (short)(b | (br.ReadByte() << 8));
-                               if ((flagsAndSize >> 12) != 3)
-                               {
-                                       throw new BadImageFormatException("Fat format method header size should be 3");
-                               }
-                               maxStack = br.ReadUInt16();
-                               int codeLength = br.ReadInt32();
-                               localVarSigTok = br.ReadInt32();
-                               body = br.ReadBytes(codeLength);
-                               if ((b & CorILMethod_MoreSects) != 0)
-                               {
-                                       module.stream.Position = (module.stream.Position + 3) & ~3;
-                                       int hdr = br.ReadInt32();
-                                       if ((hdr & CorILMethod_Sect_MoreSects) != 0 || (hdr & CorILMethod_Sect_EHTable) == 0)
-                                       {
-                                               throw new NotImplementedException();
-                                       }
-                                       else if ((hdr & CorILMethod_Sect_FatFormat) != 0)
-                                       {
-                                               int count = ComputeExceptionCount((hdr >> 8) & 0xFFFFFF, 24);
-                                               for (int i = 0; i < count; i++)
-                                               {
-                                                       int flags = br.ReadInt32();
-                                                       int tryOffset = br.ReadInt32();
-                                                       int tryLength = br.ReadInt32();
-                                                       int handlerOffset = br.ReadInt32();
-                                                       int handlerLength = br.ReadInt32();
-                                                       int classTokenOrFilterOffset = br.ReadInt32();
-                                                       exceptionClauses.Add(new ExceptionHandlingClause(module, flags, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset, context));
-                                               }
-                                       }
-                                       else
-                                       {
-                                               int count = ComputeExceptionCount((hdr >> 8) & 0xFF, 12);
-                                               for (int i = 0; i < count; i++)
-                                               {
-                                                       int flags = br.ReadUInt16();
-                                                       int tryOffset = br.ReadUInt16();
-                                                       int tryLength = br.ReadByte();
-                                                       int handlerOffset = br.ReadUInt16();
-                                                       int handlerLength = br.ReadByte();
-                                                       int classTokenOrFilterOffset = br.ReadInt32();
-                                                       exceptionClauses.Add(new ExceptionHandlingClause(module, flags, tryOffset, tryLength, handlerOffset, handlerLength, classTokenOrFilterOffset, context));
-                                               }
-                                       }
-                               }
-                               if (localVarSigTok != 0)
-                               {
-                                       ByteReader sig = module.GetStandAloneSig((localVarSigTok & 0xFFFFFF) - 1);
-                                       Signature.ReadLocalVarSig(module, sig, context, locals);
-                               }
-                       }
-                       else
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       this.exceptionClauses = exceptionClauses.AsReadOnly();
-                       this.locals = locals.AsReadOnly();
-               }
-
-               private static int ComputeExceptionCount(int size, int itemLength)
-               {
-                       // LAMESPEC according to the spec, the count should be calculated as "(size - 4) / itemLength",
-                       // FXBUG but to workaround a VB compiler bug that specifies the size incorrectly,
-                       // we do a truncating division instead.
-                       return size / itemLength;
-               }
-
-               public IList<ExceptionHandlingClause> ExceptionHandlingClauses
-               {
-                       get { return exceptionClauses; }
-               }
-
-               public bool InitLocals
-               {
-                       get { return initLocals; }
-               }
-
-               public IList<LocalVariableInfo> LocalVariables
-               {
-                       get { return locals; }
-               }
-
-               public byte[] GetILAsByteArray()
-               {
-                       return body;
-               }
-
-               public int LocalSignatureMetadataToken
-               {
-                       get { return localVarSigTok; }
-               }
-
-               public int MaxStackSize
-               {
-                       get { return maxStack; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MethodImplMap.cs b/mcs/class/IKVM.Reflection/MethodImplMap.cs
deleted file mode 100644 (file)
index bab829f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       public struct __MethodImplMap
-       {
-               public Type TargetType;
-               public MethodInfo[] MethodBodies;
-               public MethodInfo[][] MethodDeclarations;
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MethodInfo.cs b/mcs/class/IKVM.Reflection/MethodInfo.cs
deleted file mode 100644 (file)
index 40ca321..0000000
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       public abstract class MethodInfo : MethodBase, IGenericContext, IGenericBinder
-       {
-               // prevent external subclasses
-               internal MethodInfo()
-               {
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return MemberTypes.Method; }
-               }
-
-               public abstract Type ReturnType { get; }
-               public abstract ParameterInfo ReturnParameter { get; }
-
-               public virtual MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       throw new NotSupportedException(this.GetType().FullName);
-               }
-
-               public virtual MethodInfo GetGenericMethodDefinition()
-               {
-                       throw new NotSupportedException(this.GetType().FullName);
-               }
-
-               public override string ToString()
-               {
-                       StringBuilder sb = new StringBuilder();
-                       sb.Append(this.ReturnType.Name).Append(' ').Append(this.Name);
-                       string sep;
-                       if (this.IsGenericMethod)
-                       {
-                               sb.Append('[');
-                               sep = "";
-                               foreach (Type arg in GetGenericArguments())
-                               {
-                                       sb.Append(sep).Append(arg);
-                                       sep = ", ";
-                               }
-                               sb.Append(']');
-                       }
-                       sb.Append('(');
-                       sep = "";
-                       foreach (ParameterInfo arg in GetParameters())
-                       {
-                               sb.Append(sep).Append(arg.ParameterType);
-                               sep = ", ";
-                       }
-                       sb.Append(')');
-                       return sb.ToString();
-               }
-
-               internal bool IsNewSlot
-               {
-                       get { return (this.Attributes & MethodAttributes.NewSlot) != 0; }
-               }
-
-               public MethodInfo GetBaseDefinition()
-               {
-                       MethodInfo match = this;
-                       if (match.IsVirtual)
-                       {
-                               for (Type type = this.DeclaringType.BaseType; type != null && !match.IsNewSlot; type = type.BaseType)
-                               {
-                                       MethodInfo method = type.FindMethod(this.Name, this.MethodSignature) as MethodInfo;
-                                       if (method != null && method.IsVirtual)
-                                       {
-                                               match = method;
-                                       }
-                               }
-                       }
-                       return match;
-               }
-
-               public virtual MethodInfo[] __GetMethodImpls()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public bool __TryGetImplMap(out ImplMapFlags mappingFlags, out string importName, out string importScope)
-               {
-                       Module module = this.Module;
-                       foreach (int i in module.ImplMap.Filter(GetCurrentToken()))
-                       {
-                               mappingFlags = (ImplMapFlags)(ushort)module.ImplMap.records[i].MappingFlags;
-                               importName = module.GetString(module.ImplMap.records[i].ImportName);
-                               importScope = module.GetString(module.ModuleRef.records[(module.ImplMap.records[i].ImportScope & 0xFFFFFF) - 1]);
-                               return true;
-                       }
-                       mappingFlags = 0;
-                       importName = null;
-                       importScope = null;
-                       return false;
-               }
-
-               public ConstructorInfo __AsConstructorInfo()
-               {
-                       return new ConstructorInfoImpl(this);
-               }
-
-               Type IGenericContext.GetGenericTypeArgument(int index)
-               {
-                       return this.DeclaringType.GetGenericTypeArgument(index);
-               }
-
-               Type IGenericContext.GetGenericMethodArgument(int index)
-               {
-                       return GetGenericMethodArgument(index);
-               }
-
-               internal virtual Type GetGenericMethodArgument(int index)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               internal virtual int GetGenericMethodArgumentCount()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return this;
-               }
-
-               Type IGenericBinder.BindTypeParameter(Type type)
-               {
-                       return this.DeclaringType.GetGenericTypeArgument(type.GenericParameterPosition);
-               }
-
-               Type IGenericBinder.BindMethodParameter(Type type)
-               {
-                       return GetGenericMethodArgument(type.GenericParameterPosition);
-               }
-
-               internal override MethodBase BindTypeParameters(Type type)
-               {
-                       return new GenericMethodInstance(this.DeclaringType.BindTypeParameters(type), this, null);
-               }
-
-               // This method is used by ILGenerator and exists to allow ArrayMethod to override it,
-               // because ArrayMethod doesn't have a working MethodAttributes property, so it needs
-               // to base the result of this on the CallingConvention.
-               internal virtual bool HasThis
-               {
-                       get { return !IsStatic; }
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       return new MethodInfoWithReflectedType(type, this);
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       Module module = this.Module;
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       if ((this.Attributes & MethodAttributes.PinvokeImpl) != 0
-                               && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_DllImportAttribute)))
-                       {
-                               ImplMapFlags flags;
-                               string importName;
-                               string importScope;
-                               if (__TryGetImplMap(out flags, out importName, out importScope))
-                               {
-                                       list.Add(CustomAttributeData.CreateDllImportPseudoCustomAttribute(module, flags, importName, importScope, GetMethodImplementationFlags()));
-                               }
-                       }
-                       if ((GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0
-                               && (attributeType == null || attributeType.IsAssignableFrom(module.universe.System_Runtime_InteropServices_PreserveSigAttribute)))
-                       {
-                               list.Add(CustomAttributeData.CreatePreserveSigPseudoCustomAttribute(module));
-                       }
-                       return list;
-               }
-       }
-
-       sealed class MethodInfoWithReflectedType : MethodInfo
-       {
-               private readonly Type reflectedType;
-               private readonly MethodInfo method;
-
-               internal MethodInfoWithReflectedType(Type reflectedType, MethodInfo method)
-               {
-                       Debug.Assert(reflectedType != method.DeclaringType);
-                       this.reflectedType = reflectedType;
-                       this.method = method;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       MethodInfoWithReflectedType other = obj as MethodInfoWithReflectedType;
-                       return other != null
-                               && other.reflectedType == reflectedType
-                               && other.method == method;
-               }
-
-               public override int GetHashCode()
-               {
-                       return reflectedType.GetHashCode() ^ method.GetHashCode();
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get { return method.MethodSignature; }
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return method.ParameterCount; }
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameters = method.GetParameters();
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
-                       }
-                       return parameters;
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return method.Attributes; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return method.GetMethodImplementationFlags();
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       return method.GetMethodBody();
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return method.CallingConvention; }
-               }
-
-               public override int __MethodRVA
-               {
-                       get { return method.__MethodRVA; }
-               }
-
-               public override Type ReturnType
-               {
-                       get { return method.ReturnType; }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get { return new ParameterInfoWrapper(this, method.ReturnParameter); }
-               }
-
-               public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       return SetReflectedType(method.MakeGenericMethod(typeArguments), reflectedType);
-               }
-
-               public override MethodInfo GetGenericMethodDefinition()
-               {
-                       return method.GetGenericMethodDefinition();
-               }
-
-               public override string ToString()
-               {
-                       return method.ToString();
-               }
-
-               public override MethodInfo[] __GetMethodImpls()
-               {
-                       return method.__GetMethodImpls();
-               }
-
-               internal override Type GetGenericMethodArgument(int index)
-               {
-                       return method.GetGenericMethodArgument(index);
-               }
-
-               internal override int GetGenericMethodArgumentCount()
-               {
-                       return method.GetGenericMethodArgumentCount();
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return method.GetMethodOnTypeDefinition();
-               }
-
-               internal override bool HasThis
-               {
-                       get { return method.HasThis; }
-               }
-
-               public override Module Module
-               {
-                       get { return method.Module; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return method.DeclaringType; }
-               }
-
-               public override Type ReflectedType
-               {
-                       get { return reflectedType; }
-               }
-
-               public override string Name
-               {
-                       get { return method.Name; }
-               }
-
-               internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
-               {
-                       return method.ImportTo(module);
-               }
-
-               public override MethodBase __GetMethodOnTypeDefinition()
-               {
-                       return method.__GetMethodOnTypeDefinition();
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return method.__IsMissing; }
-               }
-
-               internal override MethodBase BindTypeParameters(Type type)
-               {
-                       return method.BindTypeParameters(type);
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get { return method.ContainsGenericParameters; }
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       return method.GetGenericArguments();
-               }
-
-               public override bool IsGenericMethod
-               {
-                       get { return method.IsGenericMethod; }
-               }
-
-               public override bool IsGenericMethodDefinition
-               {
-                       get { return method.IsGenericMethodDefinition; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return method.MetadataToken; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return method.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return method.IsBaked; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/MethodSignature.cs b/mcs/class/IKVM.Reflection/MethodSignature.cs
deleted file mode 100644 (file)
index 9a3c314..0000000
+++ /dev/null
@@ -1,487 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection
-{
-       sealed class MethodSignature : Signature
-       {
-               private readonly Type returnType;
-               private readonly Type[] parameterTypes;
-               private readonly PackedCustomModifiers modifiers;
-               private readonly CallingConventions callingConvention;
-               private readonly int genericParamCount;
-
-               internal MethodSignature(Type returnType, Type[] parameterTypes, PackedCustomModifiers modifiers, CallingConventions callingConvention, int genericParamCount)
-               {
-                       this.returnType = returnType;
-                       this.parameterTypes = parameterTypes;
-                       this.modifiers = modifiers;
-                       this.callingConvention = callingConvention;
-                       this.genericParamCount = genericParamCount;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       MethodSignature other = obj as MethodSignature;
-                       return other != null
-                               && other.callingConvention == callingConvention
-                               && other.genericParamCount == genericParamCount
-                               && other.returnType.Equals(returnType)
-                               && Util.ArrayEquals(other.parameterTypes, parameterTypes)
-                               && other.modifiers.Equals(modifiers);
-               }
-
-               public override int GetHashCode()
-               {
-                       return genericParamCount ^ 77 * (int)callingConvention
-                               ^ 3 * returnType.GetHashCode()
-                               ^ Util.GetHashCode(parameterTypes) * 5
-                               ^ modifiers.GetHashCode() * 55;
-               }
-
-               private sealed class UnboundGenericMethodContext : IGenericContext
-               {
-                       private readonly IGenericContext original;
-
-                       internal UnboundGenericMethodContext(IGenericContext original)
-                       {
-                               this.original = original;
-                       }
-
-                       public Type GetGenericTypeArgument(int index)
-                       {
-                               return original.GetGenericTypeArgument(index);
-                       }
-
-                       public Type GetGenericMethodArgument(int index)
-                       {
-                               return UnboundGenericMethodParameter.Make(index);
-                       }
-               }
-
-               internal static MethodSignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       CallingConventions callingConvention;
-                       int genericParamCount;
-                       Type returnType;
-                       Type[] parameterTypes;
-                       byte flags = br.ReadByte();
-                       switch (flags & 7)
-                       {
-                               case DEFAULT:
-                                       callingConvention = CallingConventions.Standard;
-                                       break;
-                               case VARARG:
-                                       callingConvention = CallingConventions.VarArgs;
-                                       break;
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-                       if ((flags & HASTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.HasThis;
-                       }
-                       if ((flags & EXPLICITTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.ExplicitThis;
-                       }
-                       genericParamCount = 0;
-                       if ((flags & GENERIC) != 0)
-                       {
-                               genericParamCount = br.ReadCompressedUInt();
-                               context = new UnboundGenericMethodContext(context);
-                       }
-                       int paramCount = br.ReadCompressedUInt();
-                       CustomModifiers[] modifiers = null;
-                       PackedCustomModifiers.Pack(ref modifiers, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
-                       returnType = ReadRetType(module, br, context);
-                       parameterTypes = new Type[paramCount];
-                       for (int i = 0; i < parameterTypes.Length; i++)
-                       {
-                               if ((callingConvention & CallingConventions.VarArgs) != 0 && br.PeekByte() == SENTINEL)
-                               {
-                                       Array.Resize(ref parameterTypes, i);
-                                       if (modifiers != null)
-                                       {
-                                               Array.Resize(ref modifiers, i + 1);
-                                       }
-                                       break;
-                               }
-                               PackedCustomModifiers.Pack(ref modifiers, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
-                               parameterTypes[i] = ReadParam(module, br, context);
-                       }
-                       return new MethodSignature(returnType, parameterTypes, PackedCustomModifiers.Wrap(modifiers), callingConvention, genericParamCount);
-               }
-
-               internal static __StandAloneMethodSig ReadStandAloneMethodSig(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       CallingConventions callingConvention = 0;
-                       System.Runtime.InteropServices.CallingConvention unmanagedCallingConvention = 0;
-                       bool unmanaged;
-                       byte flags = br.ReadByte();
-                       switch (flags & 7)
-                       {
-                               case DEFAULT:
-                                       callingConvention = CallingConventions.Standard;
-                                       unmanaged = false;
-                                       break;
-                               case 0x01:      // C
-                                       unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl;
-                                       unmanaged = true;
-                                       break;
-                               case 0x02:      // STDCALL
-                                       unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall;
-                                       unmanaged = true;
-                                       break;
-                               case 0x03:      // THISCALL
-                                       unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.ThisCall;
-                                       unmanaged = true;
-                                       break;
-                               case 0x04:      // FASTCALL
-                                       unmanagedCallingConvention = System.Runtime.InteropServices.CallingConvention.FastCall;
-                                       unmanaged = true;
-                                       break;
-                               case VARARG:
-                                       callingConvention = CallingConventions.VarArgs;
-                                       unmanaged = false;
-                                       break;
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-                       if ((flags & HASTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.HasThis;
-                       }
-                       if ((flags & EXPLICITTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.ExplicitThis;
-                       }
-                       if ((flags & GENERIC) != 0)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       int paramCount = br.ReadCompressedUInt();
-                       CustomModifiers[] customModifiers = null;
-                       PackedCustomModifiers.Pack(ref customModifiers, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
-                       Type returnType = ReadRetType(module, br, context);
-                       List<Type> parameterTypes = new List<Type>();
-                       List<Type> optionalParameterTypes = new List<Type>();
-                       List<Type> curr = parameterTypes;
-                       for (int i = 0; i < paramCount; i++)
-                       {
-                               if (br.PeekByte() == SENTINEL)
-                               {
-                                       br.ReadByte();
-                                       curr = optionalParameterTypes;
-                               }
-                               PackedCustomModifiers.Pack(ref customModifiers, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
-                               curr.Add(ReadParam(module, br, context));
-                       }
-                       return new __StandAloneMethodSig(unmanaged, unmanagedCallingConvention, callingConvention, returnType, parameterTypes.ToArray(), optionalParameterTypes.ToArray(), PackedCustomModifiers.Wrap(customModifiers));
-               }
-
-               internal int GetParameterCount()
-               {
-                       return parameterTypes.Length;
-               }
-
-               internal Type GetParameterType(int index)
-               {
-                       return parameterTypes[index];
-               }
-
-               internal Type GetReturnType(IGenericBinder binder)
-               {
-                       return returnType.BindTypeParameters(binder);
-               }
-
-               internal CustomModifiers GetReturnTypeCustomModifiers(IGenericBinder binder)
-               {
-                       return modifiers.GetReturnTypeCustomModifiers().Bind(binder);
-               }
-
-               internal Type GetParameterType(IGenericBinder binder, int index)
-               {
-                       return parameterTypes[index].BindTypeParameters(binder);
-               }
-
-               internal CustomModifiers GetParameterCustomModifiers(IGenericBinder binder, int index)
-               {
-                       return modifiers.GetParameterCustomModifiers(index).Bind(binder);
-               }
-
-               internal CallingConventions CallingConvention
-               {
-                       get { return callingConvention; }
-               }
-
-               internal int GenericParameterCount
-               {
-                       get { return genericParamCount; }
-               }
-
-               private sealed class Binder : IGenericBinder
-               {
-                       private readonly Type declaringType;
-                       private readonly Type[] methodArgs;
-
-                       internal Binder(Type declaringType, Type[] methodArgs)
-                       {
-                               this.declaringType = declaringType;
-                               this.methodArgs = methodArgs;
-                       }
-
-                       public Type BindTypeParameter(Type type)
-                       {
-                               return declaringType.GetGenericTypeArgument(type.GenericParameterPosition);
-                       }
-
-                       public Type BindMethodParameter(Type type)
-                       {
-                               if (methodArgs == null)
-                               {
-                                       return type;
-                               }
-                               return methodArgs[type.GenericParameterPosition];
-                       }
-               }
-
-               internal MethodSignature Bind(Type type, Type[] methodArgs)
-               {
-                       Binder binder = new Binder(type, methodArgs);
-                       return new MethodSignature(returnType.BindTypeParameters(binder),
-                               BindTypeParameters(binder, parameterTypes),
-                               modifiers.Bind(binder),
-                               callingConvention, genericParamCount);
-               }
-
-               private sealed class Unbinder : IGenericBinder
-               {
-                       internal static readonly Unbinder Instance = new Unbinder();
-
-                       private Unbinder()
-                       {
-                       }
-
-                       public Type BindTypeParameter(Type type)
-                       {
-                               return type;
-                       }
-
-                       public Type BindMethodParameter(Type type)
-                       {
-                               return UnboundGenericMethodParameter.Make(type.GenericParameterPosition);
-                       }
-               }
-
-               internal static MethodSignature MakeFromBuilder(Type returnType, Type[] parameterTypes, PackedCustomModifiers modifiers, CallingConventions callingConvention, int genericParamCount)
-               {
-                       if (genericParamCount > 0)
-                       {
-                               returnType = returnType.BindTypeParameters(Unbinder.Instance);
-                               parameterTypes = BindTypeParameters(Unbinder.Instance, parameterTypes);
-                               modifiers = modifiers.Bind(Unbinder.Instance);
-                       }
-                       return new MethodSignature(returnType, parameterTypes, modifiers, callingConvention, genericParamCount);
-               }
-
-               internal bool MatchParameterTypes(MethodSignature other)
-               {
-                       return Util.ArrayEquals(other.parameterTypes, parameterTypes);
-               }
-
-               internal bool MatchParameterTypes(Type[] types)
-               {
-                       return Util.ArrayEquals(types, parameterTypes);
-               }
-
-               internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
-               {
-                       WriteSigImpl(module, bb, parameterTypes.Length);
-               }
-
-               internal void WriteMethodRefSig(ModuleBuilder module, ByteBuffer bb, Type[] optionalParameterTypes, CustomModifiers[] customModifiers)
-               {
-                       WriteSigImpl(module, bb, parameterTypes.Length + optionalParameterTypes.Length);
-                       if (optionalParameterTypes.Length > 0)
-                       {
-                               bb.Write(SENTINEL);
-                               for (int i = 0; i < optionalParameterTypes.Length; i++)
-                               {
-                                       WriteCustomModifiers(module, bb, Util.NullSafeElementAt(customModifiers, i));
-                                       WriteType(module, bb, optionalParameterTypes[i]);
-                               }
-                       }
-               }
-
-               private void WriteSigImpl(ModuleBuilder module, ByteBuffer bb, int parameterCount)
-               {
-                       byte first;
-                       if ((callingConvention & CallingConventions.Any) == CallingConventions.VarArgs)
-                       {
-                               Debug.Assert(genericParamCount == 0);
-                               first = VARARG;
-                       }
-                       else if (genericParamCount > 0)
-                       {
-                               first = GENERIC;
-                       }
-                       else
-                       {
-                               first = DEFAULT;
-                       }
-                       if ((callingConvention & CallingConventions.HasThis) != 0)
-                       {
-                               first |= HASTHIS;
-                       }
-                       if ((callingConvention & CallingConventions.ExplicitThis) != 0)
-                       {
-                               first |= EXPLICITTHIS;
-                       }
-                       bb.Write(first);
-                       if (genericParamCount > 0)
-                       {
-                               bb.WriteCompressedUInt(genericParamCount);
-                       }
-                       bb.WriteCompressedUInt(parameterCount);
-                       // RetType
-                       WriteCustomModifiers(module, bb, modifiers.GetReturnTypeCustomModifiers());
-                       WriteType(module, bb, returnType);
-                       // Param
-                       for (int i = 0; i < parameterTypes.Length; i++)
-                       {
-                               WriteCustomModifiers(module, bb, modifiers.GetParameterCustomModifiers(i));
-                               WriteType(module, bb, parameterTypes[i]);
-                       }
-               }
-       }
-
-       struct PackedCustomModifiers
-       {
-               // element 0 is the return type, the rest are the parameters
-               private readonly CustomModifiers[] customModifiers;
-
-               private PackedCustomModifiers(CustomModifiers[] customModifiers)
-               {
-                       this.customModifiers = customModifiers;
-               }
-
-               public override int GetHashCode()
-               {
-                       return Util.GetHashCode(customModifiers);
-               }
-
-               public override bool Equals(object obj)
-               {
-                       PackedCustomModifiers? other = obj as PackedCustomModifiers?;
-                       return other != null && Equals(other.Value);
-               }
-
-               internal bool Equals(PackedCustomModifiers other)
-               {
-                       return Util.ArrayEquals(customModifiers, other.customModifiers);
-               }
-
-               internal CustomModifiers GetReturnTypeCustomModifiers()
-               {
-                       if (customModifiers == null)
-                       {
-                               return new CustomModifiers();
-                       }
-                       return customModifiers[0];
-               }
-
-               internal CustomModifiers GetParameterCustomModifiers(int index)
-               {
-                       if (customModifiers == null)
-                       {
-                               return new CustomModifiers();
-                       }
-                       return customModifiers[index + 1];
-               }
-
-               internal PackedCustomModifiers Bind(IGenericBinder binder)
-               {
-                       if (customModifiers == null)
-                       {
-                               return new PackedCustomModifiers();
-                       }
-                       CustomModifiers[] expanded = new CustomModifiers[customModifiers.Length];
-                       for (int i = 0; i < customModifiers.Length; i++)
-                       {
-                               expanded[i] = customModifiers[i].Bind(binder);
-                       }
-                       return new PackedCustomModifiers(expanded);
-               }
-
-               // this method make a copy of the incoming arrays (where necessary) and returns a normalized modifiers array
-               internal static PackedCustomModifiers CreateFromExternal(Type[] returnOptional, Type[] returnRequired, Type[][] parameterOptional, Type[][] parameterRequired, int parameterCount)
-               {
-                       CustomModifiers[] modifiers = null;
-                       Pack(ref modifiers, 0, CustomModifiers.FromReqOpt(returnRequired, returnOptional), parameterCount + 1);
-                       for (int i = 0; i < parameterCount; i++)
-                       {
-                               Pack(ref modifiers, i + 1, CustomModifiers.FromReqOpt(Util.NullSafeElementAt(parameterRequired, i), Util.NullSafeElementAt(parameterOptional, i)), parameterCount + 1);
-                       }
-                       return new PackedCustomModifiers(modifiers);
-               }
-
-               internal static PackedCustomModifiers CreateFromExternal(CustomModifiers returnTypeCustomModifiers, CustomModifiers[] parameterTypeCustomModifiers, int parameterCount)
-               {
-                       CustomModifiers[] customModifiers = null;
-                       Pack(ref customModifiers, 0, returnTypeCustomModifiers, parameterCount + 1);
-                       if (parameterTypeCustomModifiers != null)
-                       {
-                               for (int i = 0; i < parameterCount; i++)
-                               {
-                                       Pack(ref customModifiers, i + 1, parameterTypeCustomModifiers[i], parameterCount + 1);
-                               }
-                       }
-                       return new PackedCustomModifiers(customModifiers);
-               }
-
-               internal static PackedCustomModifiers Wrap(CustomModifiers[] modifiers)
-               {
-                       return new PackedCustomModifiers(modifiers);
-               }
-
-               internal static void Pack(ref CustomModifiers[] array, int index, CustomModifiers mods, int count)
-               {
-                       if (!mods.IsEmpty)
-                       {
-                               if (array == null)
-                               {
-                                       array = new CustomModifiers[count];
-                               }
-                               array[index] = mods;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Missing.cs b/mcs/class/IKVM.Reflection/Missing.cs
deleted file mode 100644 (file)
index 67c0a85..0000000
+++ /dev/null
@@ -1,1170 +0,0 @@
-/*
-  Copyright (C) 2011-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
-namespace IKVM.Reflection
-{
-       [Serializable]
-       public sealed class MissingAssemblyException : InvalidOperationException
-       {
-               [NonSerialized]
-               private readonly MissingAssembly assembly;
-
-               internal MissingAssemblyException(MissingAssembly assembly)
-                       : base("Assembly '" + assembly.FullName + "' is a missing assembly and does not support the requested operation.")
-               {
-                       this.assembly = assembly;
-               }
-
-               private MissingAssemblyException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
-                       : base(info, context)
-               {
-               }
-
-               public Assembly Assembly
-               {
-                       get { return assembly; }
-               }
-       }
-
-       [Serializable]
-       public sealed class MissingModuleException : InvalidOperationException
-       {
-               [NonSerialized]
-               private readonly MissingModule module;
-
-               internal MissingModuleException(MissingModule module)
-                       : base("Module from missing assembly '" + module.Assembly.FullName + "' does not support the requested operation.")
-               {
-                       this.module = module;
-               }
-
-               private MissingModuleException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
-                       : base(info, context)
-               {
-               }
-
-               public Module Module
-               {
-                       get { return module; }
-               }
-       }
-
-       [Serializable]
-       public sealed class MissingMemberException : InvalidOperationException
-       {
-               [NonSerialized]
-               private readonly MemberInfo member;
-
-               internal MissingMemberException(MemberInfo member)
-                       : base("Member '" + member + "' is a missing member and does not support the requested operation.")
-               {
-                       this.member = member;
-               }
-
-               private MissingMemberException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
-                       : base(info, context)
-               {
-               }
-
-               public MemberInfo MemberInfo
-               {
-                       get { return member; }
-               }
-       }
-
-       public struct MissingGenericMethodBuilder
-       {
-               private readonly MissingMethod method;
-
-               public MissingGenericMethodBuilder(Type declaringType, CallingConventions callingConvention, string name, int genericParameterCount)
-               {
-                       method = new MissingMethod(declaringType, name, new MethodSignature(null, null, new PackedCustomModifiers(), callingConvention, genericParameterCount));
-               }
-
-               public Type[] GetGenericArguments()
-               {
-                       return method.GetGenericArguments();
-               }
-
-               public void SetSignature(Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       method.signature = new MethodSignature(
-                               returnType ?? method.Module.universe.System_Void,
-                               Util.Copy(parameterTypes),
-                               PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length),
-                               method.signature.CallingConvention,
-                               method.signature.GenericParameterCount);
-               }
-
-               [Obsolete("Please use SetSignature(Type, CustomModifiers, Type[], CustomModifiers[]) instead.")]
-               public void SetSignature(Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       method.signature = new MethodSignature(
-                               returnType ?? method.Module.universe.System_Void,
-                               Util.Copy(parameterTypes),
-                               PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length),
-                               method.signature.CallingConvention,
-                               method.signature.GenericParameterCount);
-               }
-
-               public MethodInfo Finish()
-               {
-                       return method;
-               }
-       }
-
-       sealed class MissingAssembly : Assembly
-       {
-               private readonly MissingModule module;
-
-               internal MissingAssembly(Universe universe, string name)
-                       : base(universe)
-               {
-                       module = new MissingModule(this);
-                       this.fullName = name;
-               }
-
-               public override Type[] GetTypes()
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override AssemblyName GetName()
-               {
-                       return new AssemblyName(fullName);
-               }
-
-               public override string ImageRuntimeVersion
-               {
-                       get { throw new MissingAssemblyException(this); }
-               }
-
-               public override Module ManifestModule
-               {
-                       get { return module; }
-               }
-
-               public override MethodInfo EntryPoint
-               {
-                       get { throw new MissingAssemblyException(this); }
-               }
-
-               public override string Location
-               {
-                       get { throw new MissingAssemblyException(this); }
-               }
-
-               public override AssemblyName[] GetReferencedAssemblies()
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override Module[] GetModules(bool getResourceModules)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override Module[] GetLoadedModules(bool getResourceModules)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override Module GetModule(string name)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override string[] GetManifestResourceNames()
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override System.IO.Stream GetManifestResourceStream(string resourceName)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return true; }
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       return null;
-               }
-
-               internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
-               {
-                       throw new MissingAssemblyException(this);
-               }
-       }
-
-       sealed class MissingModule : NonPEModule
-       {
-               private readonly Assembly assembly;
-
-               internal MissingModule(Assembly assembly)
-                       : base(assembly.universe)
-               {
-                       this.assembly = assembly;
-               }
-
-               public override int MDStreamVersion
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               public override Assembly Assembly
-               {
-                       get { return assembly; }
-               }
-
-               public override string FullyQualifiedName
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               public override string Name
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               public override Guid ModuleVersionId
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               public override string ScopeName
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       return null;
-               }
-
-               internal override void GetTypesImpl(System.Collections.Generic.List<Type> list)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override long __RelativeVirtualAddressToFileOffset(int rva)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override int __Subsystem
-               {
-                       get { throw new MissingModuleException(this); }
-               }
-
-               internal override void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
-               {
-                       throw new MissingModuleException(this);
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return true; }
-               }
-
-               protected override Exception InvalidOperationException()
-               {
-                       return new MissingModuleException(this);
-               }
-
-               protected override Exception NotSupportedException()
-               {
-                       return new MissingModuleException(this);
-               }
-
-               protected override Exception ArgumentOutOfRangeException()
-               {
-                       return new MissingModuleException(this);
-               }
-       }
-
-       sealed class MissingType : Type
-       {
-               private readonly Module module;
-               private readonly Type declaringType;
-               private readonly string ns;
-               private readonly string name;
-               private Type[] typeArgs;
-               private int token;
-               private int flags;
-
-               internal MissingType(Module module, Type declaringType, string ns, string name)
-               {
-                       this.module = module;
-                       this.declaringType = declaringType;
-                       this.ns = ns;
-                       this.name = name;
-                       MarkEnumOrValueType(ns, name);
-               }
-
-               internal override MethodBase FindMethod(string name, MethodSignature signature)
-               {
-                       MethodInfo method = new MissingMethod(this, name, signature);
-                       if (name == ".ctor")
-                       {
-                               return new ConstructorInfoImpl(method);
-                       }
-                       return method;
-               }
-
-               internal override FieldInfo FindField(string name, FieldSignature signature)
-               {
-                       return new MissingField(this, name, signature);
-               }
-
-               internal override Type FindNestedType(TypeName name)
-               {
-                       return null;
-               }
-
-               internal override Type FindNestedTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       return null;
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return true; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType; }
-               }
-
-               public override string __Name
-               {
-                       get { return name; }
-               }
-
-               public override string __Namespace
-               {
-                       get { return ns; }
-               }
-
-               public override string Name
-               {
-                       get { return TypeNameParser.Escape(name); }
-               }
-
-               public override string FullName
-               {
-                       get { return GetFullName(); }
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return token; }
-               }
-
-               public override bool IsValueType
-               {
-                       get
-                       {
-                               switch (typeFlags & (TypeFlags.ValueType | TypeFlags.NotValueType))
-                               {
-                                       case TypeFlags.ValueType:
-                                               return true;
-                                       case TypeFlags.NotValueType:
-                                               return false;
-                                       default:
-                                               if (module.universe.ResolveMissingTypeIsValueType(this))
-                                               {
-                                                       typeFlags |= TypeFlags.ValueType;
-                                               }
-                                               else
-                                               {
-                                                       typeFlags |= TypeFlags.NotValueType;
-                                               }
-                                               return (typeFlags & TypeFlags.ValueType) != 0;
-                               }
-                       }
-               }
-
-               public override Type BaseType
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override Type[] __GetDeclaredTypes()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override __MethodImplMap __GetMethodImplMap()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override FieldInfo[] __GetDeclaredFields()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override EventInfo[] __GetDeclaredEvents()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override PropertyInfo[] __GetDeclaredProperties()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override CustomModifiers __GetCustomModifiers()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override bool IsGenericType
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override bool IsGenericTypeDefinition
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               internal override Type GetGenericTypeArgument(int index)
-               {
-                       if (typeArgs == null)
-                       {
-                               typeArgs = new Type[index + 1];
-                       }
-                       else if (typeArgs.Length <= index)
-                       {
-                               Array.Resize(ref typeArgs, index + 1);
-                       }
-                       return typeArgs[index] ?? (typeArgs[index] = new MissingTypeParameter(this, index));
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       return this;
-               }
-
-               internal override Type SetMetadataTokenForMissing(int token, int flags)
-               {
-                       this.token = token;
-                       this.flags = flags;
-                       return this;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override bool __IsTypeForwarder
-               {
-                       // CorTypeAttr.tdForwarder
-                       get { return (flags & 0x00200000) != 0; }
-               }
-       }
-
-       sealed class MissingTypeParameter : IKVM.Reflection.Reader.TypeParameterType
-       {
-               private readonly MemberInfo owner;
-               private readonly int index;
-
-               internal MissingTypeParameter(MemberInfo owner, int index)
-               {
-                       this.owner = owner;
-                       this.index = index;
-               }
-
-               public override Module Module
-               {
-                       get { return owner.Module; }
-               }
-
-               public override string Name
-               {
-                       get { return null; }
-               }
-
-               public override int GenericParameterPosition
-               {
-                       get { return index; }
-               }
-
-               public override MethodBase DeclaringMethod
-               {
-                       get { return owner as MethodBase; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return owner as Type; }
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       if (owner is MethodBase)
-                       {
-                               return binder.BindMethodParameter(this);
-                       }
-                       else
-                       {
-                               return binder.BindTypeParameter(this);
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return owner.IsBaked; }
-               }
-       }
-
-       sealed class MissingMethod : MethodInfo
-       {
-               private readonly Type declaringType;
-               private readonly string name;
-               internal MethodSignature signature;
-               private MethodInfo forwarder;
-               private Type[] typeArgs;
-
-               internal MissingMethod(Type declaringType, string name, MethodSignature signature)
-               {
-                       this.declaringType = declaringType;
-                       this.name = name;
-                       this.signature = signature;
-               }
-
-               private MethodInfo Forwarder
-               {
-                       get
-                       {
-                               MethodInfo method = TryGetForwarder();
-                               if (method == null)
-                               {
-                                       throw new MissingMemberException(this);
-                               }
-                               return method;
-                       }
-               }
-
-               private MethodInfo TryGetForwarder()
-               {
-                       if (forwarder == null && !declaringType.__IsMissing)
-                       {
-                               MethodBase mb = declaringType.FindMethod(name, signature);
-                               ConstructorInfo ci = mb as ConstructorInfo;
-                               if (ci != null)
-                               {
-                                       forwarder = ci.GetMethodInfo();
-                               }
-                               else
-                               {
-                                       forwarder = (MethodInfo)mb;
-                               }
-                       }
-                       return forwarder;
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return TryGetForwarder() == null; }
-               }
-
-               public override Type ReturnType
-               {
-                       get { return signature.GetReturnType(this); }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get { return new ParameterInfoImpl(this, -1); }
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get { return signature; }
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return signature.GetParameterCount(); }
-               }
-
-               private sealed class ParameterInfoImpl : ParameterInfo
-               {
-                       private readonly MissingMethod method;
-                       private readonly int index;
-
-                       internal ParameterInfoImpl(MissingMethod method, int index)
-                       {
-                               this.method = method;
-                               this.index = index;
-                       }
-
-                       private ParameterInfo Forwarder
-                       {
-                               get { return index == -1 ? method.Forwarder.ReturnParameter : method.Forwarder.GetParameters()[index]; }
-                       }
-
-                       public override string Name
-                       {
-                               get { return Forwarder.Name; }
-                       }
-
-                       public override Type ParameterType
-                       {
-                               get { return index == -1 ? method.signature.GetReturnType(method) : method.signature.GetParameterType(method, index); }
-                       }
-
-                       public override ParameterAttributes Attributes
-                       {
-                               get { return Forwarder.Attributes; }
-                       }
-
-                       public override int Position
-                       {
-                               get { return index; }
-                       }
-
-                       public override object RawDefaultValue
-                       {
-                               get { return Forwarder.RawDefaultValue; }
-                       }
-
-                       public override CustomModifiers __GetCustomModifiers()
-                       {
-                               return index == -1
-                                       ? method.signature.GetReturnTypeCustomModifiers(method)
-                                       : method.signature.GetParameterCustomModifiers(method, index);
-                       }
-
-                       public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-                       {
-                               return Forwarder.__TryGetFieldMarshal(out fieldMarshal);
-                       }
-
-                       public override MemberInfo Member
-                       {
-                               get { return method; }
-                       }
-
-                       public override int MetadataToken
-                       {
-                               get { return Forwarder.MetadataToken; }
-                       }
-
-                       internal override Module Module
-                       {
-                               get { return method.Module; }
-                       }
-
-                       public override string ToString()
-                       {
-                               return Forwarder.ToString();
-                       }
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameters = new ParameterInfo[signature.GetParameterCount()];
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoImpl(this, i);
-                       }
-                       return parameters;
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return Forwarder.Attributes; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return Forwarder.GetMethodImplementationFlags();
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       return Forwarder.GetMethodBody();
-               }
-
-               public override int __MethodRVA
-               {
-                       get { return Forwarder.__MethodRVA; }
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return signature.CallingConvention; }
-               }
-
-               internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
-               {
-                       MethodInfo method = TryGetForwarder();
-                       if (method != null)
-                       {
-                               return method.ImportTo(module);
-                       }
-                       return module.ImportMethodOrField(declaringType, this.Name, this.MethodSignature);
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType.IsModulePseudoType ? null : declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return declaringType.Module; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       MissingMethod other = obj as MissingMethod;
-                       return other != null
-                               && other.declaringType == declaringType
-                               && other.name == name
-                               && other.signature.Equals(signature);
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() ^ name.GetHashCode() ^ signature.GetHashCode();
-               }
-
-               internal override MethodBase BindTypeParameters(Type type)
-               {
-                       MethodInfo forwarder = TryGetForwarder();
-                       if (forwarder != null)
-                       {
-                               return forwarder.BindTypeParameters(type);
-                       }
-                       return new GenericMethodInstance(type, this, null);
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get { return Forwarder.ContainsGenericParameters; }
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       MethodInfo method = TryGetForwarder();
-                       if (method != null)
-                       {
-                               return Forwarder.GetGenericArguments();
-                       }
-                       if (typeArgs == null)
-                       {
-                               typeArgs = new Type[signature.GenericParameterCount];
-                               for (int i = 0; i < typeArgs.Length; i++)
-                               {
-                                       typeArgs[i] = new MissingTypeParameter(this, i);
-                               }
-                       }
-                       return Util.Copy(typeArgs);
-               }
-
-               internal override Type GetGenericMethodArgument(int index)
-               {
-                       return GetGenericArguments()[index];
-               }
-
-               internal override int GetGenericMethodArgumentCount()
-               {
-                       return Forwarder.GetGenericMethodArgumentCount();
-               }
-
-               public override MethodInfo GetGenericMethodDefinition()
-               {
-                       return Forwarder.GetGenericMethodDefinition();
-               }
-
-               internal override MethodInfo GetMethodOnTypeDefinition()
-               {
-                       return Forwarder.GetMethodOnTypeDefinition();
-               }
-
-               internal override bool HasThis
-               {
-                       get { return (signature.CallingConvention & (CallingConventions.HasThis | CallingConventions.ExplicitThis)) == CallingConventions.HasThis; }
-               }
-
-               public override bool IsGenericMethod
-               {
-                       get { return IsGenericMethodDefinition; }
-               }
-
-               public override bool IsGenericMethodDefinition
-               {
-                       get { return signature.GenericParameterCount != 0; }
-               }
-
-               public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       MethodInfo method = TryGetForwarder();
-                       if (method != null)
-                       {
-                               return method.MakeGenericMethod(typeArguments);
-                       }
-                       return new GenericMethodInstance(declaringType, this, typeArguments);
-               }
-
-               public override int MetadataToken
-               {
-                       get { return Forwarder.MetadataToken; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return Forwarder.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return Forwarder.IsBaked; }
-               }
-       }
-
-       sealed class MissingField : FieldInfo
-       {
-               private readonly Type declaringType;
-               private readonly string name;
-               private readonly FieldSignature signature;
-               private FieldInfo forwarder;
-
-               internal MissingField(Type declaringType, string name, FieldSignature signature)
-               {
-                       this.declaringType = declaringType;
-                       this.name = name;
-                       this.signature = signature;
-               }
-
-               private FieldInfo Forwarder
-               {
-                       get
-                       {
-                               FieldInfo field = TryGetForwarder();
-                               if (field == null)
-                               {
-                                       throw new MissingMemberException(this);
-                               }
-                               return field;
-                       }
-               }
-
-               private FieldInfo TryGetForwarder()
-               {
-                       if (forwarder == null && !declaringType.__IsMissing)
-                       {
-                               forwarder = declaringType.FindField(name, signature);
-                       }
-                       return forwarder;
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return TryGetForwarder() == null; }
-               }
-
-               public override FieldAttributes Attributes
-               {
-                       get { return Forwarder.Attributes; }
-               }
-
-               public override void __GetDataFromRVA(byte[] data, int offset, int length)
-               {
-                       Forwarder.__GetDataFromRVA(data, offset, length);
-               }
-
-               public override int __FieldRVA
-               {
-                       get { return Forwarder.__FieldRVA; }
-               }
-
-               public override bool __TryGetFieldOffset(out int offset)
-               {
-                       return Forwarder.__TryGetFieldOffset(out offset);
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return Forwarder.GetRawConstantValue();
-               }
-
-               internal override FieldSignature FieldSignature
-               {
-                       get { return signature; }
-               }
-
-               internal override int ImportTo(IKVM.Reflection.Emit.ModuleBuilder module)
-               {
-                       FieldInfo field = TryGetForwarder();
-                       if (field != null)
-                       {
-                               return field.ImportTo(module);
-                       }
-                       return module.ImportMethodOrField(declaringType, this.Name, this.FieldSignature);
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType.IsModulePseudoType ? null : declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return declaringType.Module; }
-               }
-
-               internal override FieldInfo BindTypeParameters(Type type)
-               {
-                       FieldInfo forwarder = TryGetForwarder();
-                       if (forwarder != null)
-                       {
-                               return forwarder.BindTypeParameters(type);
-                       }
-                       return new GenericFieldInstance(type, this);
-               }
-
-               public override int MetadataToken
-               {
-                       get { return Forwarder.MetadataToken; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       MissingField other = obj as MissingField;
-                       return other != null
-                               && other.declaringType == declaringType
-                               && other.name == name
-                               && other.signature.Equals(signature);
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() ^ name.GetHashCode() ^ signature.GetHashCode();
-               }
-
-               public override string ToString()
-               {
-                       return this.FieldType.Name + " " + this.Name;
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return Forwarder.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return Forwarder.IsBaked; }
-               }
-       }
-
-       // NOTE this is currently only used by CustomAttributeData (because there is no other way to refer to a property)
-       sealed class MissingProperty : PropertyInfo
-       {
-               private readonly Type declaringType;
-               private readonly string name;
-               private readonly PropertySignature signature;
-
-               internal MissingProperty(Type declaringType, string name, PropertySignature signature)
-               {
-                       this.declaringType = declaringType;
-                       this.name = name;
-                       this.signature = signature;
-               }
-
-               public override PropertyAttributes Attributes
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override bool CanRead
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override bool CanWrite
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               public override MethodInfo GetGetMethod(bool nonPublic)
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override MethodInfo GetSetMethod(bool nonPublic)
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override MethodInfo[] GetAccessors(bool nonPublic)
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       throw new MissingMemberException(this);
-               }
-
-               internal override bool IsPublic
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               internal override bool IsStatic
-               {
-                       get { throw new MissingMemberException(this); }
-               }
-
-               internal override PropertySignature PropertySignature
-               {
-                       get { return signature; }
-               }
-
-               public override string Name
-               {
-                       get { return name; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return declaringType.Module; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return declaringType.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       throw new MissingMemberException(this);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Module.cs b/mcs/class/IKVM.Reflection/Module.cs
deleted file mode 100644 (file)
index 191a98d..0000000
+++ /dev/null
@@ -1,685 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using IKVM.Reflection.Metadata;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       public sealed class RawModule : IDisposable
-       {
-               private readonly ModuleReader module;
-               private readonly bool isManifestModule;
-               private bool imported;
-
-               internal RawModule(ModuleReader module)
-               {
-                       this.module = module;
-                       this.isManifestModule = module.Assembly != null;
-               }
-
-               public string Location
-               {
-                       get { return module.FullyQualifiedName; }
-               }
-
-               public bool IsManifestModule
-               {
-                       get { return isManifestModule; }
-               }
-
-               public Guid ModuleVersionId
-               {
-                       get { return module.ModuleVersionId; }
-               }
-
-               private void CheckManifestModule()
-               {
-                       if (!IsManifestModule)
-                       {
-                               throw new BadImageFormatException("Module does not contain a manifest");
-                       }
-               }
-
-               public AssemblyName GetAssemblyName()
-               {
-                       CheckManifestModule();
-                       return module.Assembly.GetName();
-               }
-
-               public AssemblyName[] GetReferencedAssemblies()
-               {
-                       return module.__GetReferencedAssemblies();
-               }
-
-               public void Dispose()
-               {
-                       if (!imported)
-                       {
-                               module.stream.Dispose();
-                       }
-               }
-
-               internal AssemblyReader ToAssembly()
-               {
-                       if (imported)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       imported = true;
-                       return (AssemblyReader)module.Assembly;
-               }
-
-               internal Module ToModule(Assembly assembly)
-               {
-                       if (module.Assembly != null)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       imported = true;
-                       module.SetAssembly(assembly);
-                       return module;
-               }
-       }
-
-       public abstract class Module : ICustomAttributeProvider
-       {
-               internal readonly Universe universe;
-               internal readonly ModuleTable ModuleTable = new ModuleTable();
-               internal readonly TypeRefTable TypeRef = new TypeRefTable();
-               internal readonly TypeDefTable TypeDef = new TypeDefTable();
-               internal readonly FieldPtrTable FieldPtr = new FieldPtrTable();
-               internal readonly FieldTable Field = new FieldTable();
-               internal readonly MemberRefTable MemberRef = new MemberRefTable();
-               internal readonly ConstantTable Constant = new ConstantTable();
-               internal readonly CustomAttributeTable CustomAttribute = new CustomAttributeTable();
-               internal readonly FieldMarshalTable FieldMarshal = new FieldMarshalTable();
-               internal readonly DeclSecurityTable DeclSecurity = new DeclSecurityTable();
-               internal readonly ClassLayoutTable ClassLayout = new ClassLayoutTable();
-               internal readonly FieldLayoutTable FieldLayout = new FieldLayoutTable();
-               internal readonly ParamPtrTable ParamPtr = new ParamPtrTable();
-               internal readonly ParamTable Param = new ParamTable();
-               internal readonly InterfaceImplTable InterfaceImpl = new InterfaceImplTable();
-               internal readonly StandAloneSigTable StandAloneSig = new StandAloneSigTable();
-               internal readonly EventMapTable EventMap = new EventMapTable();
-               internal readonly EventPtrTable EventPtr = new EventPtrTable();
-               internal readonly EventTable Event = new EventTable();
-               internal readonly PropertyMapTable PropertyMap = new PropertyMapTable();
-               internal readonly PropertyPtrTable PropertyPtr = new PropertyPtrTable();
-               internal readonly PropertyTable Property = new PropertyTable();
-               internal readonly MethodSemanticsTable MethodSemantics = new MethodSemanticsTable();
-               internal readonly MethodImplTable MethodImpl = new MethodImplTable();
-               internal readonly ModuleRefTable ModuleRef = new ModuleRefTable();
-               internal readonly TypeSpecTable TypeSpec = new TypeSpecTable();
-               internal readonly ImplMapTable ImplMap = new ImplMapTable();
-               internal readonly FieldRVATable FieldRVA = new FieldRVATable();
-               internal readonly AssemblyTable AssemblyTable = new AssemblyTable();
-               internal readonly AssemblyRefTable AssemblyRef = new AssemblyRefTable();
-               internal readonly MethodPtrTable MethodPtr = new MethodPtrTable();
-               internal readonly MethodDefTable MethodDef = new MethodDefTable();
-               internal readonly NestedClassTable NestedClass = new NestedClassTable();
-               internal readonly FileTable File = new FileTable();
-               internal readonly ExportedTypeTable ExportedType = new ExportedTypeTable();
-               internal readonly ManifestResourceTable ManifestResource = new ManifestResourceTable();
-               internal readonly GenericParamTable GenericParam = new GenericParamTable();
-               internal readonly MethodSpecTable MethodSpec = new MethodSpecTable();
-               internal readonly GenericParamConstraintTable GenericParamConstraint = new GenericParamConstraintTable();
-
-               protected Module(Universe universe)
-               {
-                       this.universe = universe;
-               }
-
-               internal Table[] GetTables()
-               {
-                       Table[] tables = new Table[64];
-                       tables[ModuleTable.Index] = ModuleTable;
-                       tables[TypeRefTable.Index] = TypeRef;
-                       tables[TypeDefTable.Index] = TypeDef;
-                       tables[FieldPtrTable.Index] = FieldPtr;
-                       tables[FieldTable.Index] = Field;
-                       tables[MemberRefTable.Index] = MemberRef;
-                       tables[ConstantTable.Index] = Constant;
-                       tables[CustomAttributeTable.Index] = CustomAttribute;
-                       tables[FieldMarshalTable.Index] = FieldMarshal;
-                       tables[DeclSecurityTable.Index] = DeclSecurity;
-                       tables[ClassLayoutTable.Index] = ClassLayout;
-                       tables[FieldLayoutTable.Index] = FieldLayout;
-                       tables[ParamPtrTable.Index] = ParamPtr;
-                       tables[ParamTable.Index] = Param;
-                       tables[InterfaceImplTable.Index] = InterfaceImpl;
-                       tables[StandAloneSigTable.Index] = StandAloneSig;
-                       tables[EventMapTable.Index] = EventMap;
-                       tables[EventPtrTable.Index] = EventPtr;
-                       tables[EventTable.Index] = Event;
-                       tables[PropertyMapTable.Index] = PropertyMap;
-                       tables[PropertyPtrTable.Index] = PropertyPtr;
-                       tables[PropertyTable.Index] = Property;
-                       tables[MethodSemanticsTable.Index] = MethodSemantics;
-                       tables[MethodImplTable.Index] = MethodImpl;
-                       tables[ModuleRefTable.Index] = ModuleRef;
-                       tables[TypeSpecTable.Index] = TypeSpec;
-                       tables[ImplMapTable.Index] = ImplMap;
-                       tables[FieldRVATable.Index] = FieldRVA;
-                       tables[AssemblyTable.Index] = AssemblyTable;
-                       tables[AssemblyRefTable.Index] = AssemblyRef;
-                       tables[MethodPtrTable.Index] = MethodPtr;
-                       tables[MethodDefTable.Index] = MethodDef;
-                       tables[NestedClassTable.Index] = NestedClass;
-                       tables[FileTable.Index] = File;
-                       tables[ExportedTypeTable.Index] = ExportedType;
-                       tables[ManifestResourceTable.Index] = ManifestResource;
-                       tables[GenericParamTable.Index] = GenericParam;
-                       tables[MethodSpecTable.Index] = MethodSpec;
-                       tables[GenericParamConstraintTable.Index] = GenericParamConstraint;
-                       return tables;
-               }
-
-               public virtual void __GetDataDirectoryEntry(int index, out int rva, out int length)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual long __RelativeVirtualAddressToFileOffset(int rva)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual bool __GetSectionInfo(int rva, out string name, out int characteristics)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual int __ReadDataFromRVA(int rva, byte[] data, int offset, int length)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual int __Subsystem
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public FieldInfo GetField(string name)
-               {
-                       return GetField(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
-               }
-
-               public FieldInfo GetField(string name, BindingFlags bindingFlags)
-               {
-                       return IsResource() ? null : GetModuleType().GetField(name, bindingFlags | BindingFlags.DeclaredOnly);
-               }
-
-               public FieldInfo[] GetFields()
-               {
-                       return GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
-               }
-
-               public FieldInfo[] GetFields(BindingFlags bindingFlags)
-               {
-                       return IsResource() ? Empty<FieldInfo>.Array : GetModuleType().GetFields(bindingFlags | BindingFlags.DeclaredOnly);
-               }
-
-               public MethodInfo GetMethod(string name)
-               {
-                       return IsResource() ? null : GetModuleType().GetMethod(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
-               }
-
-               public MethodInfo GetMethod(string name, Type[] types)
-               {
-                       return IsResource() ? null : GetModuleType().GetMethod(name, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, types, null);
-               }
-
-               public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return IsResource() ? null : GetModuleType().GetMethod(name, bindingAttr | BindingFlags.DeclaredOnly, binder, callConv, types, modifiers);
-               }
-
-               public MethodInfo[] GetMethods()
-               {
-                       return GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
-               }
-
-               public MethodInfo[] GetMethods(BindingFlags bindingFlags)
-               {
-                       return IsResource() ? Empty<MethodInfo>.Array : GetModuleType().GetMethods(bindingFlags | BindingFlags.DeclaredOnly);
-               }
-
-               public ConstructorInfo __ModuleInitializer
-               {
-                       get { return IsResource() ? null : GetModuleType().TypeInitializer; }
-               }
-
-               public virtual byte[] ResolveSignature(int metadataToken)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public int MetadataToken
-               {
-                       get { return IsResource() ? 0 : 1; }
-               }
-
-               public abstract int MDStreamVersion { get ;}
-               public abstract Assembly Assembly { get; }
-               public abstract string FullyQualifiedName { get; }
-               public abstract string Name { get; }
-               public abstract Guid ModuleVersionId { get; }
-               public abstract MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments);
-               public abstract FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments);
-               public abstract MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments);
-
-               public abstract string ResolveString(int metadataToken);
-               public abstract Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers);
-               public abstract string ScopeName { get; }
-
-               internal abstract void GetTypesImpl(List<Type> list);
-
-               internal abstract Type FindType(TypeName name);
-               internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
-
-               [Obsolete("Please use __ResolveOptionalParameterTypes(int, Type[], Type[], out CustomModifiers[]) instead.")]
-               public Type[] __ResolveOptionalParameterTypes(int metadataToken)
-               {
-                       CustomModifiers[] dummy;
-                       return __ResolveOptionalParameterTypes(metadataToken, null, null, out dummy);
-               }
-
-               public Type GetType(string className)
-               {
-                       return GetType(className, false, false);
-               }
-
-               public Type GetType(string className, bool ignoreCase)
-               {
-                       return GetType(className, false, ignoreCase);
-               }
-
-               public Type GetType(string className, bool throwOnError, bool ignoreCase)
-               {
-                       TypeNameParser parser = TypeNameParser.Parse(className, throwOnError);
-                       if (parser.Error)
-                       {
-                               return null;
-                       }
-                       if (parser.AssemblyName != null)
-                       {
-                               if (throwOnError)
-                               {
-                                       throw new ArgumentException("Type names passed to Module.GetType() must not specify an assembly.");
-                               }
-                               else
-                               {
-                                       return null;
-                               }
-                       }
-                       TypeName typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
-                       Type type = ignoreCase
-                               ? FindTypeIgnoreCase(typeName.ToLowerInvariant())
-                               : FindType(typeName);
-                       if (type == null && __IsMissing)
-                       {
-                               throw new MissingModuleException((MissingModule)this);
-                       }
-                       return parser.Expand(type, this.Assembly, throwOnError, className, false, ignoreCase);
-               }
-
-               public Type[] GetTypes()
-               {
-                       List<Type> list = new List<Type>();
-                       GetTypesImpl(list);
-                       return list.ToArray();
-               }
-
-               public Type[] FindTypes(TypeFilter filter, object filterCriteria)
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (Type type in GetTypes())
-                       {
-                               if (filter(type, filterCriteria))
-                               {
-                                       list.Add(type);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public virtual bool IsResource()
-               {
-                       return false;
-               }
-
-               public Type ResolveType(int metadataToken)
-               {
-                       return ResolveType(metadataToken, null, null);
-               }
-
-               internal sealed class GenericContext : IGenericContext
-               {
-                       private readonly Type[] genericTypeArguments;
-                       private readonly Type[] genericMethodArguments;
-
-                       internal GenericContext(Type[] genericTypeArguments, Type[] genericMethodArguments)
-                       {
-                               this.genericTypeArguments = genericTypeArguments;
-                               this.genericMethodArguments = genericMethodArguments;
-                       }
-
-                       public Type GetGenericTypeArgument(int index)
-                       {
-                               return genericTypeArguments[index];
-                       }
-
-                       public Type GetGenericMethodArgument(int index)
-                       {
-                               return genericMethodArguments[index];
-                       }
-               }
-
-               public Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       if ((metadataToken >> 24) == TypeSpecTable.Index)
-                       {
-                               return ResolveType(metadataToken, new GenericContext(genericTypeArguments, genericMethodArguments));
-                       }
-                       else
-                       {
-                               return ResolveType(metadataToken, null);
-                       }
-               }
-
-               internal abstract Type ResolveType(int metadataToken, IGenericContext context);
-
-               public MethodBase ResolveMethod(int metadataToken)
-               {
-                       return ResolveMethod(metadataToken, null, null);
-               }
-
-               public FieldInfo ResolveField(int metadataToken)
-               {
-                       return ResolveField(metadataToken, null, null);
-               }
-
-               public MemberInfo ResolveMember(int metadataToken)
-               {
-                       return ResolveMember(metadataToken, null, null);
-               }
-
-               public bool IsDefined(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
-               }
-
-               public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
-               }
-
-               public IList<CustomAttributeData> GetCustomAttributesData()
-               {
-                       return CustomAttributeData.GetCustomAttributes(this);
-               }
-
-               public IEnumerable<CustomAttributeData> CustomAttributes
-               {
-                       get { return GetCustomAttributesData(); }
-               }
-
-               public virtual IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
-               {
-                       return Empty<CustomAttributeData>.Array;
-               }
-
-               public abstract AssemblyName[] __GetReferencedAssemblies();
-
-               public virtual void __ResolveReferencedAssemblies(Assembly[] assemblies)
-               {
-                       throw new NotSupportedException();
-               }
-
-               public abstract string[] __GetReferencedModules();
-
-               public abstract Type[] __GetReferencedTypes();
-
-               public abstract Type[] __GetExportedTypes();
-
-               public virtual bool __IsMissing
-               {
-                       get { return false; }
-               }
-
-               public long __ImageBase
-               {
-                       get { return GetImageBaseImpl(); }
-               }
-
-               protected abstract long GetImageBaseImpl();
-
-               public long __StackReserve
-               {
-                       get { return GetStackReserveImpl(); }
-               }
-
-               protected abstract long GetStackReserveImpl();
-
-               public int __FileAlignment
-               {
-                       get { return GetFileAlignmentImpl(); }
-               }
-
-               protected abstract int GetFileAlignmentImpl();
-
-               public DllCharacteristics __DllCharacteristics
-               {
-                       get { return GetDllCharacteristicsImpl(); }
-               }
-
-               protected abstract DllCharacteristics GetDllCharacteristicsImpl();
-
-               public virtual byte[] __ModuleHash
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public virtual int __EntryPointRVA
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public virtual int __EntryPointToken
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public virtual string __ImageRuntimeVersion
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public IEnumerable<CustomAttributeData> __EnumerateCustomAttributeTable()
-               {
-                       List<CustomAttributeData> list = new List<CustomAttributeData>(CustomAttribute.RowCount);
-                       for (int i = 0; i < CustomAttribute.RowCount; i++)
-                       {
-                               list.Add(new CustomAttributeData(this, i));
-                       }
-                       return list;
-               }
-
-               [Obsolete]
-               public List<CustomAttributeData> __GetCustomAttributesFor(int token)
-               {
-                       return CustomAttributeData.GetCustomAttributesImpl(new List<CustomAttributeData>(), this, token, null);
-               }
-
-               public virtual System.Security.Cryptography.X509Certificates.X509Certificate GetSignerCertificate()
-               {
-                       return null;
-               }
-
-               internal abstract Type GetModuleType();
-
-               internal abstract ByteReader GetBlob(int blobIndex);
-
-               internal IList<CustomAttributeData> GetDeclarativeSecurity(int metadataToken)
-               {
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       foreach (int i in DeclSecurity.Filter(metadataToken))
-                       {
-                               CustomAttributeData.ReadDeclarativeSecurity(this, i, list);
-                       }
-                       return list;
-               }
-
-               internal virtual void Dispose()
-               {
-               }
-
-               internal virtual void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
-               {
-               }
-
-               internal virtual string GetString(int index)
-               {
-                       throw new NotSupportedException();
-               }
-       }
-
-       abstract class NonPEModule : Module
-       {
-               protected NonPEModule(Universe universe)
-                       : base(universe)
-               {
-               }
-
-               protected virtual Exception InvalidOperationException()
-               {
-                       return new InvalidOperationException();
-               }
-
-               protected virtual Exception NotSupportedException()
-               {
-                       return new NotSupportedException();
-               }
-
-               protected virtual Exception ArgumentOutOfRangeException()
-               {
-                       return new ArgumentOutOfRangeException();
-               }
-
-               internal sealed override Type GetModuleType()
-               {
-                       throw InvalidOperationException();
-               }
-
-               internal sealed override ByteReader GetBlob(int blobIndex)
-               {
-                       throw InvalidOperationException();
-               }
-
-               public sealed override AssemblyName[] __GetReferencedAssemblies()
-               {
-                       throw NotSupportedException();
-               }
-
-               public sealed override string[] __GetReferencedModules()
-               {
-                       throw NotSupportedException();
-               }
-
-               public override Type[] __GetReferencedTypes()
-               {
-                       throw NotSupportedException();
-               }
-
-               public override Type[] __GetExportedTypes()
-               {
-                       throw NotSupportedException();
-               }
-
-               protected sealed override long GetImageBaseImpl()
-               {
-                       throw NotSupportedException();
-               }
-
-               protected sealed override long GetStackReserveImpl()
-               {
-                       throw NotSupportedException();
-               }
-
-               protected sealed override int GetFileAlignmentImpl()
-               {
-                       throw NotSupportedException();
-               }
-
-               protected override DllCharacteristics GetDllCharacteristicsImpl()
-               {
-                       throw NotSupportedException();
-               }
-
-               internal sealed override Type ResolveType(int metadataToken, IGenericContext context)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-
-               public sealed override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-
-               public sealed override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-
-               public sealed override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-
-               public sealed override string ResolveString(int metadataToken)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-
-               public sealed override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers)
-               {
-                       throw ArgumentOutOfRangeException();
-               }
-       }
-
-       public delegate bool TypeFilter(Type m, object filterCriteria);
-       public delegate bool MemberFilter(MemberInfo m, object filterCriteria);
-}
diff --git a/mcs/class/IKVM.Reflection/ParameterInfo.cs b/mcs/class/IKVM.Reflection/ParameterInfo.cs
deleted file mode 100644 (file)
index ca70d33..0000000
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System.Collections.Generic;
-
-namespace IKVM.Reflection
-{
-       public abstract class ParameterInfo : ICustomAttributeProvider
-       {
-               // prevent external subclasses
-               internal ParameterInfo()
-               {
-               }
-
-               public sealed override bool Equals(object obj)
-               {
-                       ParameterInfo other = obj as ParameterInfo;
-                       return other != null && other.Member == this.Member && other.Position == this.Position;
-               }
-
-               public sealed override int GetHashCode()
-               {
-                       return this.Member.GetHashCode() * 1777 + this.Position;
-               }
-
-               public static bool operator ==(ParameterInfo p1, ParameterInfo p2)
-               {
-                       return ReferenceEquals(p1, p2) || (!ReferenceEquals(p1, null) && p1.Equals(p2));
-               }
-
-               public static bool operator !=(ParameterInfo p1, ParameterInfo p2)
-               {
-                       return !(p1 == p2);
-               }
-
-               public abstract string Name { get; }
-               public abstract Type ParameterType { get; }
-               public abstract ParameterAttributes Attributes { get; }
-               public abstract int Position { get; }
-               public abstract object RawDefaultValue { get; }
-               public abstract CustomModifiers __GetCustomModifiers();
-               public abstract bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal);
-               public abstract MemberInfo Member { get; }
-               public abstract int MetadataToken { get; }
-               internal abstract Module Module { get; }
-
-               public Type[] GetOptionalCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetOptional();
-               }
-
-               public Type[] GetRequiredCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetRequired();
-               }
-
-               public bool IsIn
-               {
-                       get { return (Attributes & ParameterAttributes.In) != 0; }
-               }
-
-               public bool IsOut
-               {
-                       get { return (Attributes & ParameterAttributes.Out) != 0; }
-               }
-
-               public bool IsLcid
-               {
-                       get { return (Attributes & ParameterAttributes.Lcid) != 0; }
-               }
-
-               public bool IsRetval
-               {
-                       get { return (Attributes & ParameterAttributes.Retval) != 0; }
-               }
-
-               public bool IsOptional
-               {
-                       get { return (Attributes & ParameterAttributes.Optional) != 0; }
-               }
-
-               public bool HasDefaultValue
-               {
-                       get { return (Attributes & ParameterAttributes.HasDefault) != 0; }
-               }
-
-               public bool IsDefined(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
-               }
-
-               public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
-               {
-                       return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
-               }
-
-               public IList<CustomAttributeData> GetCustomAttributesData()
-               {
-                       return CustomAttributeData.GetCustomAttributes(this);
-               }
-
-               public IEnumerable<CustomAttributeData> CustomAttributes
-               {
-                       get { return GetCustomAttributesData(); }
-               }
-       }
-
-       sealed class ParameterInfoWrapper : ParameterInfo
-       {
-               private readonly MemberInfo member;
-               private readonly ParameterInfo forward;
-
-               internal ParameterInfoWrapper(MemberInfo member, ParameterInfo forward)
-               {
-                       this.member = member;
-                       this.forward = forward;
-               }
-
-               public override string Name
-               {
-                       get { return forward.Name; }
-               }
-
-               public override Type ParameterType
-               {
-                       get { return forward.ParameterType; }
-               }
-
-               public override ParameterAttributes Attributes
-               {
-                       get { return forward.Attributes; }
-               }
-
-               public override int Position
-               {
-                       get { return forward.Position; }
-               }
-
-               public override object RawDefaultValue
-               {
-                       get { return forward.RawDefaultValue; }
-               }
-
-               public override CustomModifiers __GetCustomModifiers()
-               {
-                       return forward.__GetCustomModifiers();
-               }
-
-               public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-               {
-                       return forward.__TryGetFieldMarshal(out fieldMarshal);
-               }
-
-               public override MemberInfo Member
-               {
-                       get { return member; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return forward.MetadataToken; }
-               }
-
-               internal override Module Module
-               {
-                       get { return member.Module; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/ParameterModifier.cs b/mcs/class/IKVM.Reflection/ParameterModifier.cs
deleted file mode 100644 (file)
index 605cca4..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       public struct ParameterModifier
-       {
-               private readonly bool[] values;
-
-               public ParameterModifier(int parameterCount)
-               {
-                       values = new bool[parameterCount];
-               }
-
-               public bool this[int index]
-               {
-                       get { return values[index]; }
-                       set { values[index] = value; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Properties/AssemblyInfo.cs b/mcs/class/IKVM.Reflection/Properties/AssemblyInfo.cs
deleted file mode 100644 (file)
index f453241..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System.Reflection;
-
-[assembly: AssemblyTitle("IKVM.Reflection")]
-[assembly: AssemblyDescription("Alternative implementation of System.Reflection[.Emit]")]
diff --git a/mcs/class/IKVM.Reflection/PropertyInfo.cs b/mcs/class/IKVM.Reflection/PropertyInfo.cs
deleted file mode 100644 (file)
index 4d5ce9f..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-
-namespace IKVM.Reflection
-{
-       public abstract class PropertyInfo : MemberInfo
-       {
-               // prevent external subclasses
-               internal PropertyInfo()
-               {
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return MemberTypes.Property; }
-               }
-
-               public abstract PropertyAttributes Attributes { get; }
-               public abstract bool CanRead { get; }
-               public abstract bool CanWrite { get; }
-               public abstract MethodInfo GetGetMethod(bool nonPublic);
-               public abstract MethodInfo GetSetMethod(bool nonPublic);
-               public abstract MethodInfo[] GetAccessors(bool nonPublic);
-               public abstract object GetRawConstantValue();
-               internal abstract bool IsPublic { get; }
-               internal abstract bool IsNonPrivate { get; }
-               internal abstract bool IsStatic { get; }
-               internal abstract PropertySignature PropertySignature { get; }
-
-               private sealed class ParameterInfoImpl : ParameterInfo
-               {
-                       private readonly PropertyInfo property;
-                       private readonly int parameter;
-
-                       internal ParameterInfoImpl(PropertyInfo property, int parameter)
-                       {
-                               this.property = property;
-                               this.parameter = parameter;
-                       }
-
-                       public override string Name
-                       {
-                               get { return null; }
-                       }
-
-                       public override Type ParameterType
-                       {
-                               get { return property.PropertySignature.GetParameter(parameter); }
-                       }
-
-                       public override ParameterAttributes Attributes
-                       {
-                               get { return ParameterAttributes.None; }
-                       }
-
-                       public override int Position
-                       {
-                               get { return parameter; }
-                       }
-
-                       public override object RawDefaultValue
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       public override CustomModifiers __GetCustomModifiers()
-                       {
-                               return property.PropertySignature.GetParameterCustomModifiers(parameter);
-                       }
-
-                       public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-                       {
-                               fieldMarshal = new FieldMarshal();
-                               return false;
-                       }
-
-                       public override MemberInfo Member
-                       {
-                               get { return property; }
-                       }
-
-                       public override int MetadataToken
-                       {
-                               get { return 0x08000000; }
-                       }
-
-                       internal override Module Module
-                       {
-                               get { return property.Module; }
-                       }
-               }
-
-               public virtual ParameterInfo[] GetIndexParameters()
-               {
-                       ParameterInfo[] parameters = new ParameterInfo[this.PropertySignature.ParameterCount];
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoImpl(this, i);
-                       }
-                       return parameters;
-               }
-
-               public Type PropertyType
-               {
-                       get { return this.PropertySignature.PropertyType; }
-               }
-
-               public CustomModifiers __GetCustomModifiers()
-               {
-                       return this.PropertySignature.GetCustomModifiers();
-               }
-
-               public Type[] GetRequiredCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetRequired();
-               }
-
-               public Type[] GetOptionalCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetOptional();
-               }
-
-               public bool IsSpecialName
-               {
-                       get { return (Attributes & PropertyAttributes.SpecialName) != 0; }
-               }
-
-               public MethodInfo GetMethod
-               {
-                       get { return GetGetMethod(true); }
-               }
-
-               public MethodInfo SetMethod
-               {
-                       get { return GetSetMethod(true); }
-               }
-
-               public MethodInfo GetGetMethod()
-               {
-                       return GetGetMethod(false);
-               }
-
-               public MethodInfo GetSetMethod()
-               {
-                       return GetSetMethod(false);
-               }
-
-               public MethodInfo[] GetAccessors()
-               {
-                       return GetAccessors(false);
-               }
-
-               public CallingConventions __CallingConvention
-               {
-                       get { return this.PropertySignature.CallingConvention; }
-               }
-
-               internal virtual PropertyInfo BindTypeParameters(Type type)
-               {
-                       return new GenericPropertyInfo(this.DeclaringType.BindTypeParameters(type), this);
-               }
-
-               public override string ToString()
-               {
-                       return this.DeclaringType.ToString() + " " + Name;
-               }
-
-               internal sealed override bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       return BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static, BindingFlags.Instance);
-               }
-
-               internal sealed override bool BindingFlagsMatchInherited(BindingFlags flags)
-               {
-                       return IsNonPrivate
-                               && BindingFlagsMatch(IsPublic, flags, BindingFlags.Public, BindingFlags.NonPublic)
-                               && BindingFlagsMatch(IsStatic, flags, BindingFlags.Static | BindingFlags.FlattenHierarchy, BindingFlags.Instance);
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       return new PropertyInfoWithReflectedType(type, this);
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       // properties don't have pseudo custom attributes
-                       return null;
-               }
-       }
-
-       sealed class PropertyInfoWithReflectedType : PropertyInfo
-       {
-               private readonly Type reflectedType;
-               private readonly PropertyInfo property;
-
-               internal PropertyInfoWithReflectedType(Type reflectedType, PropertyInfo property)
-               {
-                       this.reflectedType = reflectedType;
-                       this.property = property;
-               }
-
-               public override PropertyAttributes Attributes
-               {
-                       get { return property.Attributes; }
-               }
-
-               public override bool CanRead
-               {
-                       get { return property.CanRead; }
-               }
-
-               public override bool CanWrite
-               {
-                       get { return property.CanWrite; }
-               }
-
-               public override MethodInfo GetGetMethod(bool nonPublic)
-               {
-                       return SetReflectedType(property.GetGetMethod(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo GetSetMethod(bool nonPublic)
-               {
-                       return SetReflectedType(property.GetSetMethod(nonPublic), reflectedType);
-               }
-
-               public override MethodInfo[] GetAccessors(bool nonPublic)
-               {
-                       return SetReflectedType(property.GetAccessors(nonPublic), reflectedType);
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return property.GetRawConstantValue();
-               }
-
-               internal override bool IsPublic
-               {
-                       get { return property.IsPublic; }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get { return property.IsNonPrivate; }
-               }
-
-               internal override bool IsStatic
-               {
-                       get { return property.IsStatic; }
-               }
-
-               internal override PropertySignature PropertySignature
-               {
-                       get { return property.PropertySignature; }
-               }
-
-               public override ParameterInfo[] GetIndexParameters()
-               {
-                       ParameterInfo[] parameters = property.GetIndexParameters();
-                       for (int i = 0; i < parameters.Length; i++)
-                       {
-                               parameters[i] = new ParameterInfoWrapper(this, parameters[i]);
-                       }
-                       return parameters;
-               }
-
-               internal override PropertyInfo BindTypeParameters(Type type)
-               {
-                       return property.BindTypeParameters(type);
-               }
-
-               public override string ToString()
-               {
-                       return property.ToString();
-               }
-
-               public override bool __IsMissing
-               {
-                       get { return property.__IsMissing; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return property.DeclaringType; }
-               }
-
-               public override Type ReflectedType
-               {
-                       get { return reflectedType; }
-               }
-
-               public override bool Equals(object obj)
-               {
-                       PropertyInfoWithReflectedType other = obj as PropertyInfoWithReflectedType;
-                       return other != null
-                               && other.reflectedType == reflectedType
-                               && other.property == property;
-               }
-
-               public override int GetHashCode()
-               {
-                       return reflectedType.GetHashCode() ^ property.GetHashCode();
-               }
-
-               public override int MetadataToken
-               {
-                       get { return property.MetadataToken; }
-               }
-
-               public override Module Module
-               {
-                       get { return property.Module; }
-               }
-
-               public override string Name
-               {
-                       get { return property.Name; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return property.IsBaked; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return property.GetCurrentToken();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/PropertySignature.cs b/mcs/class/IKVM.Reflection/PropertySignature.cs
deleted file mode 100644 (file)
index e6e0fee..0000000
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       sealed class PropertySignature : Signature
-       {
-               private CallingConventions callingConvention;
-               private readonly Type propertyType;
-               private readonly Type[] parameterTypes;
-               private readonly PackedCustomModifiers customModifiers;
-
-               internal static PropertySignature Create(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       return new PropertySignature(callingConvention, propertyType, Util.Copy(parameterTypes), customModifiers);
-               }
-
-               private PropertySignature(CallingConventions callingConvention, Type propertyType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       this.callingConvention = callingConvention;
-                       this.propertyType = propertyType;
-                       this.parameterTypes = parameterTypes;
-                       this.customModifiers = customModifiers;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       PropertySignature other = obj as PropertySignature;
-                       return other != null
-                               && other.propertyType.Equals(propertyType)
-                               && other.customModifiers.Equals(customModifiers);
-               }
-
-               public override int GetHashCode()
-               {
-                       return propertyType.GetHashCode() ^ customModifiers.GetHashCode();
-               }
-
-               internal int ParameterCount
-               {
-                       get { return parameterTypes.Length; }
-               }
-
-               internal bool HasThis
-               {
-                       set
-                       {
-                               if (value)
-                               {
-                                       callingConvention |= CallingConventions.HasThis;
-                               }
-                               else
-                               {
-                                       callingConvention &= ~CallingConventions.HasThis;
-                               }
-                       }
-               }
-
-               internal Type PropertyType
-               {
-                       get { return propertyType; }
-               }
-
-               internal CustomModifiers GetCustomModifiers()
-               {
-                       return customModifiers.GetReturnTypeCustomModifiers();
-               }
-
-               internal PropertySignature ExpandTypeParameters(Type declaringType)
-               {
-                       return new PropertySignature(
-                               callingConvention,
-                               propertyType.BindTypeParameters(declaringType),
-                               BindTypeParameters(declaringType, parameterTypes),
-                               customModifiers.Bind(declaringType));
-               }
-
-               internal override void WriteSig(ModuleBuilder module, ByteBuffer bb)
-               {
-                       byte flags = PROPERTY;
-                       if ((callingConvention & CallingConventions.HasThis) != 0)
-                       {
-                               flags |= HASTHIS;
-                       }
-                       if ((callingConvention & CallingConventions.ExplicitThis) != 0)
-                       {
-                               flags |= EXPLICITTHIS;
-                       }
-                       if ((callingConvention & CallingConventions.VarArgs) != 0)
-                       {
-                               flags |= VARARG;
-                       }
-                       bb.Write(flags);
-                       bb.WriteCompressedUInt(parameterTypes == null ? 0 : parameterTypes.Length);
-                       WriteCustomModifiers(module, bb, customModifiers.GetReturnTypeCustomModifiers());
-                       WriteType(module, bb, propertyType);
-                       if (parameterTypes != null)
-                       {
-                               for (int i = 0; i < parameterTypes.Length; i++)
-                               {
-                                       WriteCustomModifiers(module, bb, customModifiers.GetParameterCustomModifiers(i));
-                                       WriteType(module, bb, parameterTypes[i]);
-                               }
-                       }
-               }
-
-               internal Type GetParameter(int parameter)
-               {
-                       return parameterTypes[parameter];
-               }
-
-               internal CustomModifiers GetParameterCustomModifiers(int parameter)
-               {
-                       return customModifiers.GetParameterCustomModifiers(parameter);
-               }
-
-               internal CallingConventions CallingConvention
-               {
-                       get { return callingConvention; }
-               }
-
-               internal bool MatchParameterTypes(Type[] types)
-               {
-                       return Util.ArrayEquals(types, parameterTypes);
-               }
-
-               internal static PropertySignature ReadSig(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       byte flags = br.ReadByte();
-                       if ((flags & PROPERTY) == 0)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       CallingConventions callingConvention = CallingConventions.Standard;
-                       if ((flags & HASTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.HasThis;
-                       }
-                       if ((flags & EXPLICITTHIS) != 0)
-                       {
-                               callingConvention |= CallingConventions.ExplicitThis;
-                       }
-                       Type returnType;
-                       Type[] parameterTypes;
-                       int paramCount = br.ReadCompressedUInt();
-                       CustomModifiers[] mods = null;
-                       PackedCustomModifiers.Pack(ref mods, 0, CustomModifiers.Read(module, br, context), paramCount + 1);
-                       returnType = ReadRetType(module, br, context);
-                       parameterTypes = new Type[paramCount];
-                       for (int i = 0; i < parameterTypes.Length; i++)
-                       {
-                               PackedCustomModifiers.Pack(ref mods, i + 1, CustomModifiers.Read(module, br, context), paramCount + 1);
-                               parameterTypes[i] = ReadParam(module, br, context);
-                       }
-                       return new PropertySignature(callingConvention, returnType, parameterTypes, PackedCustomModifiers.Wrap(mods));
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/AssemblyReader.cs b/mcs/class/IKVM.Reflection/Reader/AssemblyReader.cs
deleted file mode 100644 (file)
index c64189e..0000000
+++ /dev/null
@@ -1,330 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Configuration.Assemblies;
-using System.IO;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class AssemblyReader : Assembly
-       {
-               private const int ContainsNoMetaData = 0x0001;
-               private readonly string location;
-               private readonly ModuleReader manifestModule;
-               private readonly Module[] externalModules;
-
-               internal AssemblyReader(string location, ModuleReader manifestModule)
-                       : base(manifestModule.universe)
-               {
-                       this.location = location;
-                       this.manifestModule = manifestModule;
-                       externalModules = new Module[manifestModule.File.records.Length];
-               }
-
-               public override string Location
-               {
-                       get { return location; }
-               }
-
-               public override AssemblyName GetName()
-               {
-                       return GetNameImpl(ref manifestModule.AssemblyTable.records[0]);
-               }
-
-               private AssemblyName GetNameImpl(ref AssemblyTable.Record rec)
-               {
-                       AssemblyName name = new AssemblyName();
-                       name.Name = manifestModule.GetString(rec.Name);
-                       name.Version = new Version(rec.MajorVersion, rec.MinorVersion, rec.BuildNumber, rec.RevisionNumber);
-                       if (rec.PublicKey != 0)
-                       {
-                               name.SetPublicKey(manifestModule.GetBlobCopy(rec.PublicKey));
-                       }
-                       else
-                       {
-                               name.SetPublicKey(Empty<byte>.Array);
-                       }
-                       if (rec.Culture != 0)
-                       {
-                               name.Culture = manifestModule.GetString(rec.Culture);
-                       }
-                       else
-                       {
-                               name.Culture = "";
-                       }
-                       name.HashAlgorithm = (AssemblyHashAlgorithm)rec.HashAlgId;
-                       name.CodeBase = this.CodeBase;
-                       PortableExecutableKinds peKind;
-                       ImageFileMachine machine;
-                       manifestModule.GetPEKind(out peKind, out machine);
-                       switch (machine)
-                       {
-                               case ImageFileMachine.I386:
-                                       // FXBUG we copy the .NET bug that Preferred32Bit implies x86
-                                       if ((peKind & (PortableExecutableKinds.Required32Bit | PortableExecutableKinds.Preferred32Bit)) != 0)
-                                       {
-                                               name.ProcessorArchitecture = ProcessorArchitecture.X86;
-                                       }
-                                       else if ((rec.Flags & 0x70) == 0x70)
-                                       {
-                                               // it's a reference assembly
-                                               name.ProcessorArchitecture = ProcessorArchitecture.None;
-                                       }
-                                       else
-                                       {
-                                               name.ProcessorArchitecture = ProcessorArchitecture.MSIL;
-                                       }
-                                       break;
-                               case ImageFileMachine.IA64:
-                                       name.ProcessorArchitecture = ProcessorArchitecture.IA64;
-                                       break;
-                               case ImageFileMachine.AMD64:
-                                       name.ProcessorArchitecture = ProcessorArchitecture.Amd64;
-                                       break;
-                               case ImageFileMachine.ARM:
-                                       name.ProcessorArchitecture = ProcessorArchitecture.Arm;
-                                       break;
-                       }
-                       name.RawFlags = (AssemblyNameFlags)rec.Flags;
-                       return name;
-               }
-
-               public override Type[] GetTypes()
-               {
-                       if (externalModules.Length == 0)
-                       {
-                               return manifestModule.GetTypes();
-                       }
-
-                       List<Type> list = new List<Type>();
-                       foreach (Module module in GetModules(false))
-                       {
-                               list.AddRange(module.GetTypes());
-                       }
-                       return list.ToArray();
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       Type type = manifestModule.FindType(typeName);
-                       for (int i = 0; type == null && i < externalModules.Length; i++)
-                       {
-                               if ((manifestModule.File.records[i].Flags & ContainsNoMetaData) == 0)
-                               {
-                                       type = GetModule(i).FindType(typeName);
-                               }
-                       }
-                       return type;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       Type type = manifestModule.FindTypeIgnoreCase(lowerCaseName);
-                       for (int i = 0; type == null && i < externalModules.Length; i++)
-                       {
-                               if ((manifestModule.File.records[i].Flags & ContainsNoMetaData) == 0)
-                               {
-                                       type = GetModule(i).FindTypeIgnoreCase(lowerCaseName);
-                               }
-                       }
-                       return type;
-               }
-
-               public override string ImageRuntimeVersion
-               {
-                       get { return manifestModule.__ImageRuntimeVersion; }
-               }
-
-               public override Module ManifestModule
-               {
-                       get { return manifestModule; }
-               }
-
-               public override Module[] GetLoadedModules(bool getResourceModules)
-               {
-                       List<Module> list = new List<Module>();
-                       list.Add(manifestModule);
-                       foreach (Module m in externalModules)
-                       {
-                               if (m != null)
-                               {
-                                       list.Add(m);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public override Module[] GetModules(bool getResourceModules)
-               {
-                       if (externalModules.Length == 0)
-                       {
-                               return new Module[] { manifestModule };
-                       }
-                       else
-                       {
-                               List<Module> list = new List<Module>();
-                               list.Add(manifestModule);
-                               for (int i = 0; i < manifestModule.File.records.Length; i++)
-                               {
-                                       if (getResourceModules || (manifestModule.File.records[i].Flags & ContainsNoMetaData) == 0)
-                                       {
-                                               list.Add(GetModule(i));
-                                       }
-                               }
-                               return list.ToArray();
-                       }
-               }
-
-               public override Module GetModule(string name)
-               {
-                       if (name.Equals(manifestModule.ScopeName, StringComparison.InvariantCultureIgnoreCase))
-                       {
-                               return manifestModule;
-                       }
-                       int index = GetModuleIndex(name);
-                       if (index != -1)
-                       {
-                               return GetModule(index);
-                       }
-                       return null;
-               }
-
-               private int GetModuleIndex(string name)
-               {
-                       for (int i = 0; i < manifestModule.File.records.Length; i++)
-                       {
-                               if (name.Equals(manifestModule.GetString(manifestModule.File.records[i].Name), StringComparison.InvariantCultureIgnoreCase))
-                               {
-                                       return i;
-                               }
-                       }
-                       return -1;
-               }
-
-               private Module GetModule(int index)
-               {
-                       if (externalModules[index] != null)
-                       {
-                               return externalModules[index];
-                       }
-                       return LoadModule(index, null, manifestModule.GetString(manifestModule.File.records[index].Name));
-               }
-
-               private Module LoadModule(int index, byte[] rawModule, string name)
-               {
-                       string location = name == null ? null : Path.Combine(Path.GetDirectoryName(this.location), name);
-                       if ((manifestModule.File.records[index].Flags & ContainsNoMetaData) != 0)
-                       {
-                               return externalModules[index] = new ResourceModule(manifestModule, index, location);
-                       }
-                       else
-                       {
-                               if (rawModule == null)
-                               {
-                                       try
-                                       {
-                                               rawModule = File.ReadAllBytes(location);
-                                       }
-                                       catch (FileNotFoundException)
-                                       {
-                                               if (resolvers != null)
-                                               {
-                                                       ResolveEventArgs arg = new ResolveEventArgs(name, this);
-                                                       foreach (ModuleResolveEventHandler resolver in resolvers)
-                                                       {
-                                                               Module module = resolver(this, arg);
-                                                               if (module != null)
-                                                               {
-                                                                       return module;
-                                                               }
-                                                       }
-                                               }
-                                               if (universe.MissingMemberResolution)
-                                               {
-                                                       return externalModules[index] = new MissingModule(this);
-                                               }
-                                               throw;
-                                       }
-                               }
-                               return externalModules[index] = new ModuleReader(this, manifestModule.universe, new MemoryStream(rawModule), location);
-                       }
-               }
-
-               public override Module LoadModule(string moduleName, byte[] rawModule)
-               {
-                       int index = GetModuleIndex(moduleName);
-                       if (index == -1)
-                       {
-                               throw new ArgumentException();
-                       }
-                       if (externalModules[index] != null)
-                       {
-                               return externalModules[index];
-                       }
-                       return LoadModule(index, rawModule, null);
-               }
-
-               public override MethodInfo EntryPoint
-               {
-                       get { return manifestModule.GetEntryPoint(); }
-               }
-
-               public override string[] GetManifestResourceNames()
-               {
-                       return manifestModule.GetManifestResourceNames();
-               }
-
-               public override ManifestResourceInfo GetManifestResourceInfo(string resourceName)
-               {
-                       return manifestModule.GetManifestResourceInfo(resourceName);
-               }
-
-               public override Stream GetManifestResourceStream(string resourceName)
-               {
-                       return manifestModule.GetManifestResourceStream(resourceName);
-               }
-
-               public override AssemblyName[] GetReferencedAssemblies()
-               {
-                       return manifestModule.__GetReferencedAssemblies();
-               }
-
-               protected override AssemblyNameFlags GetAssemblyFlags()
-               {
-                       return (AssemblyNameFlags)manifestModule.AssemblyTable.records[0].Flags;
-               }
-
-               internal string Name
-               {
-                       get { return manifestModule.GetString(manifestModule.AssemblyTable.records[0].Name); }
-               }
-
-               internal override IList<CustomAttributeData> GetCustomAttributesData(Type attributeType)
-               {
-                       return CustomAttributeData.GetCustomAttributesImpl(null, manifestModule, 0x20000001, attributeType) ?? CustomAttributeData.EmptyList;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/Authenticode.cs b/mcs/class/IKVM.Reflection/Reader/Authenticode.cs
deleted file mode 100644 (file)
index 76a78f3..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using System.IO;
-using System.Security.Cryptography;
-using System.Security.Cryptography.X509Certificates;
-
-namespace IKVM.Reflection.Reader
-{
-       static class Authenticode
-       {
-               internal static X509Certificate GetSignerCertificate(Stream stream)
-               {
-                       throw new NotSupportedException ("mcs");
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/ByteReader.cs b/mcs/class/IKVM.Reflection/Reader/ByteReader.cs
deleted file mode 100644 (file)
index e85328b..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class ByteReader
-       {
-               private byte[] buffer;
-               private int pos;
-               private int end;
-
-               internal ByteReader(byte[] buffer, int offset, int length)
-               {
-                       this.buffer = buffer;
-                       this.pos = offset;
-                       this.end = pos + length;
-               }
-
-               internal static ByteReader FromBlob(byte[] blobHeap, int blob)
-               {
-                       ByteReader br = new ByteReader(blobHeap, blob, 4);
-                       int length = br.ReadCompressedUInt();
-                       br.end = br.pos + length;
-                       return br;
-               }
-
-               internal int Length
-               {
-                       get { return end - pos; }
-               }
-
-               internal byte PeekByte()
-               {
-                       if (pos == end)
-                               throw new BadImageFormatException();
-                       return buffer[pos];
-               }
-
-               internal byte ReadByte()
-               {
-                       if (pos == end)
-                               throw new BadImageFormatException();
-                       return buffer[pos++];
-               }
-
-               internal byte[] ReadBytes(int count)
-               {
-                       if (count < 0)
-                               throw new BadImageFormatException();
-                       if (end - pos < count)
-                               throw new BadImageFormatException();
-                       byte[] buf = new byte[count];
-                       Buffer.BlockCopy(buffer, pos, buf, 0, count);
-                       pos += count;
-                       return buf;
-               }
-
-               internal int ReadCompressedUInt()
-               {
-                       byte b1 = ReadByte();
-                       if (b1 <= 0x7F)
-                       {
-                               return b1;
-                       }
-                       else if ((b1 & 0xC0) == 0x80)
-                       {
-                               byte b2 = ReadByte();
-                               return ((b1 & 0x3F) << 8) | b2;
-                       }
-                       else
-                       {
-                               byte b2 = ReadByte();
-                               byte b3 = ReadByte();
-                               byte b4 = ReadByte();
-                               return ((b1 & 0x3F) << 24) + (b2 << 16) + (b3 << 8) + b4;
-                       }
-               }
-
-               internal int ReadCompressedInt()
-               {
-                       byte b1 = PeekByte();
-                       int value = ReadCompressedUInt();
-                       if ((value & 1) == 0)
-                       {
-                               return value >> 1;
-                       }
-                       else
-                       {
-                               switch (b1 & 0xC0)
-                               {
-                                       case 0:
-                                       case 0x40:
-                                               return (value >> 1) - 0x40;
-                                       case 0x80:
-                                               return (value >> 1) - 0x2000;
-                                       default:
-                                               return (value >> 1) - 0x10000000;
-                               }
-                       }
-               }
-
-               internal string ReadString()
-               {
-                       if (PeekByte() == 0xFF)
-                       {
-                               pos++;
-                               return null;
-                       }
-                       int length = ReadCompressedUInt();
-                       string str = Encoding.UTF8.GetString(buffer, pos, length);
-                       pos += length;
-                       return str;
-               }
-
-               internal char ReadChar()
-               {
-                       return (char)ReadInt16();
-               }
-
-               internal sbyte ReadSByte()
-               {
-                       return (sbyte)ReadByte();
-               }
-
-               internal short ReadInt16()
-               {
-                       if (end - pos < 2)
-                               throw new BadImageFormatException();
-                       byte b1 = buffer[pos++];
-                       byte b2 = buffer[pos++];
-                       return (short)(b1 | (b2 << 8));
-               }
-
-               internal ushort ReadUInt16()
-               {
-                       return (ushort)ReadInt16();
-               }
-
-               internal int ReadInt32()
-               {
-                       if (end - pos < 4)
-                               throw new BadImageFormatException();
-                       byte b1 = buffer[pos++];
-                       byte b2 = buffer[pos++];
-                       byte b3 = buffer[pos++];
-                       byte b4 = buffer[pos++];
-                       return (int)(b1 | (b2 << 8) | (b3 << 16) | (b4 << 24));
-               }
-
-               internal uint ReadUInt32()
-               {
-                       return (uint)ReadInt32();
-               }
-
-               internal long ReadInt64()
-               {
-                       ulong lo = ReadUInt32();
-                       ulong hi = ReadUInt32();
-                       return (long)(lo | (hi << 32));
-               }
-
-               internal ulong ReadUInt64()
-               {
-                       return (ulong)ReadInt64();
-               }
-
-               internal float ReadSingle()
-               {
-                       return SingleConverter.Int32BitsToSingle(ReadInt32());
-               }
-
-               internal double ReadDouble()
-               {
-                       return BitConverter.Int64BitsToDouble(ReadInt64());
-               }
-
-               internal ByteReader Slice(int length)
-               {
-                       if (end - pos < length)
-                               throw new BadImageFormatException();
-                       ByteReader br = new ByteReader(buffer, pos, length);
-                       pos += length;
-                       return br;
-               }
-
-               // NOTE this method only works if the original offset was aligned and for alignments that are a power of 2
-               internal void Align(int alignment)
-               {
-                       alignment--;
-                       pos = (pos + alignment) & ~alignment;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/EventInfoImpl.cs b/mcs/class/IKVM.Reflection/Reader/EventInfoImpl.cs
deleted file mode 100644 (file)
index 68d0bc0..0000000
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class EventInfoImpl : EventInfo
-       {
-               private readonly ModuleReader module;
-               private readonly Type declaringType;
-               private readonly int index;
-               private bool isPublic;
-               private bool isNonPrivate;
-               private bool isStatic;
-               private bool flagsCached;
-
-               internal EventInfoImpl(ModuleReader module, Type declaringType, int index)
-               {
-                       this.module = module;
-                       this.declaringType = declaringType;
-                       this.index = index;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       EventInfoImpl other = obj as EventInfoImpl;
-                       return other != null && other.declaringType == declaringType && other.index == index;
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() * 123 + index;
-               }
-
-               public override EventAttributes Attributes
-               {
-                       get { return (EventAttributes)module.Event.records[index].EventFlags; }
-               }
-
-               public override MethodInfo GetAddMethod(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.AddOn);
-               }
-
-               public override MethodInfo GetRaiseMethod(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Fire);
-               }
-
-               public override MethodInfo GetRemoveMethod(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.RemoveOn);
-               }
-
-               public override MethodInfo[] GetOtherMethods(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethods(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Other);
-               }
-
-               public override MethodInfo[] __GetMethods()
-               {
-                       return module.MethodSemantics.GetMethods(module, this.MetadataToken, true, -1);
-               }
-
-               public override Type EventHandlerType
-               {
-                       get { return module.ResolveType(module.Event.records[index].EventType, declaringType); }
-               }
-
-               public override string Name
-               {
-                       get { return module.GetString(module.Event.records[index].Name); }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (EventTable.Index << 24) + index + 1; }
-               }
-
-               internal override bool IsPublic
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isPublic;
-                       }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isNonPrivate;
-                       }
-               }
-
-               internal override bool IsStatic
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isStatic;
-                       }
-               }
-
-               private void ComputeFlags()
-               {
-                       module.MethodSemantics.ComputeFlags(module, this.MetadataToken, out isPublic, out isNonPrivate, out isStatic);
-                       flagsCached = true;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/Field.cs b/mcs/class/IKVM.Reflection/Reader/Field.cs
deleted file mode 100644 (file)
index 2aba292..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class FieldDefImpl : FieldInfo
-       {
-               private readonly ModuleReader module;
-               private readonly TypeDefImpl declaringType;
-               private readonly int index;
-               private FieldSignature lazyFieldSig;
-
-               internal FieldDefImpl(ModuleReader module, TypeDefImpl declaringType, int index)
-               {
-                       this.module = module;
-                       this.declaringType = declaringType;
-                       this.index = index;
-               }
-
-               public override FieldAttributes Attributes
-               {
-                       get { return (FieldAttributes)module.Field.records[index].Flags; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType.IsModulePseudoType ? null : declaringType; }
-               }
-
-               public override string Name
-               {
-                       get { return module.GetString(module.Field.records[index].Name); }
-               }
-
-               public override string ToString()
-               {
-                       return this.FieldType.Name + " " + this.Name;
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (FieldTable.Index << 24) + index + 1; }
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return module.Constant.GetRawConstantValue(module, this.MetadataToken);
-               }
-
-               public override void __GetDataFromRVA(byte[] data, int offset, int length)
-               {
-                       int rva = this.__FieldRVA;
-                       if (rva == 0)
-                       {
-                               // C++ assemblies can have fields that have an RVA that is zero
-                               Array.Clear(data, offset, length);
-                               return;
-                       }
-                       module.__ReadDataFromRVA(rva, data, offset, length);
-               }
-
-               public override int __FieldRVA
-               {
-                       get
-                       {
-                               foreach (int i in module.FieldRVA.Filter(index + 1))
-                               {
-                                       return module.FieldRVA.records[i].RVA;
-                               }
-                               throw new InvalidOperationException();
-                       }
-               }
-
-               public override bool __TryGetFieldOffset(out int offset)
-               {
-                       foreach (int i in this.Module.FieldLayout.Filter(index + 1))
-                       {
-                               offset = this.Module.FieldLayout.records[i].Offset;
-                               return true;
-                       }
-                       offset = 0;
-                       return false;
-               }
-
-               internal override FieldSignature FieldSignature
-               {
-                       get { return lazyFieldSig ?? (lazyFieldSig = FieldSignature.ReadSig(module, module.GetBlob(module.Field.records[index].Signature), declaringType)); }
-               }
-
-               internal override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       return module.ImportMethodOrField(declaringType, this.Name, this.FieldSignature);
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/GenericTypeParameter.cs b/mcs/class/IKVM.Reflection/Reader/GenericTypeParameter.cs
deleted file mode 100644 (file)
index d0c7405..0000000
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       abstract class TypeParameterType : TypeInfo
-       {
-               public sealed override string AssemblyQualifiedName
-               {
-                       get { return null; }
-               }
-
-               public sealed override bool IsValueType
-               {
-                       get { return (this.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0; }
-               }
-
-               public sealed override Type BaseType
-               {
-                       get
-                       {
-                               foreach (Type type in GetGenericParameterConstraints())
-                               {
-                                       if (!type.IsInterface && !type.IsGenericParameter)
-                                       {
-                                               return type;
-                                       }
-                               }
-                               return this.IsValueType ? this.Module.universe.System_ValueType : this.Module.universe.System_Object;
-                       }
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (Type type in GetGenericParameterConstraints())
-                       {
-                               if (type.IsInterface)
-                               {
-                                       list.Add(type);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public sealed override TypeAttributes Attributes
-               {
-                       get { return TypeAttributes.Public; }
-               }
-
-               public sealed override string FullName
-               {
-                       get { return null; }
-               }
-
-               public sealed override string ToString()
-               {
-                       return this.Name;
-               }
-
-               public sealed override bool IsGenericParameter
-               {
-                       get { return true; }
-               }
-
-               public sealed override bool __ContainsMissingType
-               {
-                       get
-                       {
-                               bool freeList = false;
-                               try
-                               {
-                                       foreach (Type type in GetGenericParameterConstraints())
-                                       {
-                                               if (type.__IsMissing)
-                                               {
-                                                       return true;
-                                               }
-                                               else if (type.IsConstructedGenericType || type.HasElementType || type.__IsFunctionPointer)
-                                               {
-                                                       // if a constructed type contains generic parameters,
-                                                       // it might contain this type parameter again and
-                                                       // to prevent infinite recurssion, we keep a thread local
-                                                       // list of type parameters we've already processed
-                                                       if (type.ContainsGenericParameters)
-                                                       {
-                                                               if (containsMissingTypeHack == null)
-                                                               {
-                                                                       freeList = true;
-                                                                       containsMissingTypeHack = new List<Type>();
-                                                               }
-                                                               else if (containsMissingTypeHack.Contains(this))
-                                                               {
-                                                                       return false;
-                                                               }
-                                                               containsMissingTypeHack.Add(this);
-                                                       }
-                                                       if (type.__ContainsMissingType)
-                                                       {
-                                                               return true;
-                                                       }
-                                               }
-                                       }
-                                       return false;
-                               }
-                               finally
-                               {
-                                       if (freeList)
-                                       {
-                                               containsMissingTypeHack = null;
-                                       }
-                               }
-                       }
-               }
-
-               [ThreadStatic]
-               private static List<Type> containsMissingTypeHack;
-       }
-
-       sealed class UnboundGenericMethodParameter : TypeParameterType
-       {
-               private static readonly DummyModule module = new DummyModule();
-               private readonly int position;
-
-               private sealed class DummyModule : NonPEModule
-               {
-                       internal DummyModule()
-                               : base(new Universe())
-                       {
-                       }
-
-                       protected override Exception NotSupportedException()
-                       {
-                               return new InvalidOperationException();
-                       }
-
-                       protected override Exception ArgumentOutOfRangeException()
-                       {
-                               return new InvalidOperationException();
-                       }
-
-                       public override bool Equals(object obj)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override int GetHashCode()
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override string ToString()
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override int MDStreamVersion
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       public override Assembly Assembly
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       internal override Type FindType(TypeName typeName)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       internal override void GetTypesImpl(List<Type> list)
-                       {
-                               throw new InvalidOperationException();
-                       }
-
-                       public override string FullyQualifiedName
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       public override string Name
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       public override Guid ModuleVersionId
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-
-                       public override string ScopeName
-                       {
-                               get { throw new InvalidOperationException(); }
-                       }
-               }
-
-               internal static Type Make(int position)
-               {
-                       return module.universe.CanonicalizeType(new UnboundGenericMethodParameter(position));
-               }
-
-               private UnboundGenericMethodParameter(int position)
-               {
-                       this.position = position;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       UnboundGenericMethodParameter other = obj as UnboundGenericMethodParameter;
-                       return other != null && other.position == position;
-               }
-
-               public override int GetHashCode()
-               {
-                       return position;
-               }
-
-               public override string Namespace
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override string Name
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override int MetadataToken
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int GenericParameterPosition
-               {
-                       get { return position; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return null; }
-               }
-
-               public override MethodBase DeclaringMethod
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override Type[] GetGenericParameterConstraints()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public override GenericParameterAttributes GenericParameterAttributes
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       return binder.BindMethodParameter(this);
-               }
-
-               internal override bool IsBaked
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-       }
-
-       sealed class GenericTypeParameter : TypeParameterType
-       {
-               private readonly ModuleReader module;
-               private readonly int index;
-
-               internal GenericTypeParameter(ModuleReader module, int index)
-               {
-                       this.module = module;
-                       this.index = index;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return base.Equals(obj);
-               }
-
-               public override int GetHashCode()
-               {
-                       return base.GetHashCode();
-               }
-
-               public override string Namespace
-               {
-                       get { return DeclaringType.Namespace; }
-               }
-
-               public override string Name
-               {
-                       get { return module.GetString(module.GenericParam.records[index].Name); }
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (GenericParamTable.Index << 24) + index + 1; }
-               }
-
-               public override int GenericParameterPosition
-               {
-                       get { return module.GenericParam.records[index].Number; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get
-                       {
-                               int owner = module.GenericParam.records[index].Owner;
-                               return (owner >> 24) == TypeDefTable.Index ? module.ResolveType(owner) : null;
-                       }
-               }
-
-               public override MethodBase DeclaringMethod
-               {
-                       get
-                       {
-                               int owner = module.GenericParam.records[index].Owner;
-                               return (owner >> 24) == MethodDefTable.Index ? module.ResolveMethod(owner) : null;
-                       }
-               }
-
-               public override Type[] GetGenericParameterConstraints()
-               {
-                       IGenericContext context = (this.DeclaringMethod as IGenericContext) ?? this.DeclaringType;
-                       List<Type> list = new List<Type>();
-                       foreach (int i in module.GenericParamConstraint.Filter(this.MetadataToken))
-                       {
-                               list.Add(module.ResolveType(module.GenericParamConstraint.records[i].Constraint, context));
-                       }
-                       return list.ToArray();
-               }
-
-               public override GenericParameterAttributes GenericParameterAttributes
-               {
-                       get { return (GenericParameterAttributes)module.GenericParam.records[index].Flags; }
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       int owner = module.GenericParam.records[index].Owner;
-                       if ((owner >> 24) == MethodDefTable.Index)
-                       {
-                               return binder.BindMethodParameter(this);
-                       }
-                       else
-                       {
-                               return binder.BindTypeParameter(this);
-                       }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/MetadataReader.cs b/mcs/class/IKVM.Reflection/Reader/MetadataReader.cs
deleted file mode 100644 (file)
index 28a4720..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class MetadataReader : MetadataRW
-       {
-               private readonly Stream stream;
-               private const int bufferLength = 2048;
-               private readonly byte[] buffer = new byte[bufferLength];
-               private int pos = bufferLength;
-
-               internal MetadataReader(ModuleReader module, Stream stream, byte heapSizes)
-                       : base(module, (heapSizes & 0x01) != 0, (heapSizes & 0x02) != 0, (heapSizes & 0x04) != 0)
-               {
-                       this.stream = stream;
-               }
-
-               private void FillBuffer(int needed)
-               {
-                       int count = bufferLength - pos;
-                       if (count != 0)
-                       {
-                               // move remaining bytes to the front of the buffer
-                               Buffer.BlockCopy(buffer, pos, buffer, 0, count);
-                       }
-                       pos = 0;
-
-                       while (count < needed)
-                       {
-                               int len = stream.Read(buffer, count, bufferLength - count);
-                               if (len == 0)
-                               {
-                                       throw new BadImageFormatException();
-                               }
-                               count += len;
-                       }
-
-                       if (count != bufferLength)
-                       {
-                               // we didn't fill the buffer completely, so have to restore the invariant
-                               // that all data from pos up until the end of the buffer is valid
-                               Buffer.BlockCopy(buffer, 0, buffer, bufferLength - count, count);
-                               pos = bufferLength - count;
-                       }
-               }
-
-               internal ushort ReadUInt16()
-               {
-                       return (ushort)ReadInt16();
-               }
-
-               internal short ReadInt16()
-               {
-                       if (pos > bufferLength - 2)
-                       {
-                               FillBuffer(2);
-                       }
-                       byte b1 = buffer[pos++];
-                       byte b2 = buffer[pos++];
-                       return (short)(b1 | (b2 << 8));
-               }
-
-               internal int ReadInt32()
-               {
-                       if (pos > bufferLength - 4)
-                       {
-                               FillBuffer(4);
-                       }
-                       byte b1 = buffer[pos++];
-                       byte b2 = buffer[pos++];
-                       byte b3 = buffer[pos++];
-                       byte b4 = buffer[pos++];
-                       return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
-               }
-
-               private int ReadIndex(bool big)
-               {
-                       if (big)
-                       {
-                               return ReadInt32();
-                       }
-                       else
-                       {
-                               return ReadUInt16();
-                       }
-               }
-
-               internal int ReadStringIndex()
-               {
-                       return ReadIndex(bigStrings);
-               }
-
-               internal int ReadGuidIndex()
-               {
-                       return ReadIndex(bigGuids);
-               }
-
-               internal int ReadBlobIndex()
-               {
-                       return ReadIndex(bigBlobs);
-               }
-
-               internal int ReadResolutionScope()
-               {
-                       int codedIndex = ReadIndex(bigResolutionScope);
-                       switch (codedIndex & 3)
-                       {
-                               case 0:
-                                       return (ModuleTable.Index << 24) + (codedIndex >> 2);
-                               case 1:
-                                       return (ModuleRefTable.Index << 24) + (codedIndex >> 2);
-                               case 2:
-                                       return (AssemblyRefTable.Index << 24) + (codedIndex >> 2);
-                               case 3:
-                                       return (TypeRefTable.Index << 24) + (codedIndex >> 2);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadTypeDefOrRef()
-               {
-                       int codedIndex = ReadIndex(bigTypeDefOrRef);
-                       switch (codedIndex & 3)
-                       {
-                               case 0:
-                                       return (TypeDefTable.Index << 24) + (codedIndex >> 2);
-                               case 1:
-                                       return (TypeRefTable.Index << 24) + (codedIndex >> 2);
-                               case 2:
-                                       return (TypeSpecTable.Index << 24) + (codedIndex >> 2);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadMemberRefParent()
-               {
-                       int codedIndex = ReadIndex(bigMemberRefParent);
-                       switch (codedIndex & 7)
-                       {
-                               case 0:
-                                       return (TypeDefTable.Index << 24) + (codedIndex >> 3);
-                               case 1:
-                                       return (TypeRefTable.Index << 24) + (codedIndex >> 3);
-                               case 2:
-                                       return (ModuleRefTable.Index << 24) + (codedIndex >> 3);
-                               case 3:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 3);
-                               case 4:
-                                       return (TypeSpecTable.Index << 24) + (codedIndex >> 3);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadHasCustomAttribute()
-               {
-                       int codedIndex = ReadIndex(bigHasCustomAttribute);
-                       switch (codedIndex & 31)
-                       {
-                               case 0:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 5);
-                               case 1:
-                                       return (FieldTable.Index << 24) + (codedIndex >> 5);
-                               case 2:
-                                       return (TypeRefTable.Index << 24) + (codedIndex >> 5);
-                               case 3:
-                                       return (TypeDefTable.Index << 24) + (codedIndex >> 5);
-                               case 4:
-                                       return (ParamTable.Index << 24) + (codedIndex >> 5);
-                               case 5:
-                                       return (InterfaceImplTable.Index << 24) + (codedIndex >> 5);
-                               case 6:
-                                       return (MemberRefTable.Index << 24) + (codedIndex >> 5);
-                               case 7:
-                                       return (ModuleTable.Index << 24) + (codedIndex >> 5);
-                               case 8:
-                                       throw new BadImageFormatException();
-                               case 9:
-                                       return (PropertyTable.Index << 24) + (codedIndex >> 5);
-                               case 10:
-                                       return (EventTable.Index << 24) + (codedIndex >> 5);
-                               case 11:
-                                       return (StandAloneSigTable.Index << 24) + (codedIndex >> 5);
-                               case 12:
-                                       return (ModuleRefTable.Index << 24) + (codedIndex >> 5);
-                               case 13:
-                                       return (TypeSpecTable.Index << 24) + (codedIndex >> 5);
-                               case 14:
-                                       return (AssemblyTable.Index << 24) + (codedIndex >> 5);
-                               case 15:
-                                       return (AssemblyRefTable.Index << 24) + (codedIndex >> 5);
-                               case 16:
-                                       return (FileTable.Index << 24) + (codedIndex >> 5);
-                               case 17:
-                                       return (ExportedTypeTable.Index << 24) + (codedIndex >> 5);
-                               case 18:
-                                       return (ManifestResourceTable.Index << 24) + (codedIndex >> 5);
-                               case 19:
-                                       return (GenericParamTable.Index << 24) + (codedIndex >> 5);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadCustomAttributeType()
-               {
-                       int codedIndex = ReadIndex(bigCustomAttributeType);
-                       switch (codedIndex & 7)
-                       {
-                               case 2:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 3);
-                               case 3:
-                                       return (MemberRefTable.Index << 24) + (codedIndex >> 3);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadMethodDefOrRef()
-               {
-                       int codedIndex = ReadIndex(bigMethodDefOrRef);
-                       switch (codedIndex & 1)
-                       {
-                               case 0:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 1);
-                               case 1:
-                                       return (MemberRefTable.Index << 24) + (codedIndex >> 1);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadHasConstant()
-               {
-                       int codedIndex = ReadIndex(bigHasConstant);
-                       switch (codedIndex & 3)
-                       {
-                               case 0:
-                                       return (FieldTable.Index << 24) + (codedIndex >> 2);
-                               case 1:
-                                       return (ParamTable.Index << 24) + (codedIndex >> 2);
-                               case 2:
-                                       return (PropertyTable.Index << 24) + (codedIndex >> 2);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadHasSemantics()
-               {
-                       int codedIndex = ReadIndex(bigHasSemantics);
-                       switch (codedIndex & 1)
-                       {
-                               case 0:
-                                       return (EventTable.Index << 24) + (codedIndex >> 1);
-                               case 1:
-                                       return (PropertyTable.Index << 24) + (codedIndex >> 1);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadHasFieldMarshal()
-               {
-                       int codedIndex = ReadIndex(bigHasFieldMarshal);
-                       switch (codedIndex & 1)
-                       {
-                               case 0:
-                                       return (FieldTable.Index << 24) + (codedIndex >> 1);
-                               case 1:
-                                       return (ParamTable.Index << 24) + (codedIndex >> 1);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadHasDeclSecurity()
-               {
-                       int codedIndex = ReadIndex(bigHasDeclSecurity);
-                       switch (codedIndex & 3)
-                       {
-                               case 0:
-                                       return (TypeDefTable.Index << 24) + (codedIndex >> 2);
-                               case 1:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 2);
-                               case 2:
-                                       return (AssemblyTable.Index << 24) + (codedIndex >> 2);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadTypeOrMethodDef()
-               {
-                       int codedIndex = ReadIndex(bigTypeOrMethodDef);
-                       switch (codedIndex & 1)
-                       {
-                               case 0:
-                                       return (TypeDefTable.Index << 24) + (codedIndex >> 1);
-                               case 1:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 1);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadMemberForwarded()
-               {
-                       int codedIndex = ReadIndex(bigMemberForwarded);
-                       switch (codedIndex & 1)
-                       {
-                               case 0:
-                                       return (FieldTable.Index << 24) + (codedIndex >> 1);
-                               case 1:
-                                       return (MethodDefTable.Index << 24) + (codedIndex >> 1);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadImplementation()
-               {
-                       int codedIndex = ReadIndex(bigImplementation);
-                       switch (codedIndex & 3)
-                       {
-                               case 0:
-                                       return (FileTable.Index << 24) + (codedIndex >> 2);
-                               case 1:
-                                       return (AssemblyRefTable.Index << 24) + (codedIndex >> 2);
-                               case 2:
-                                       return (ExportedTypeTable.Index << 24) + (codedIndex >> 2);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal int ReadField()
-               {
-                       return ReadIndex(bigField);
-               }
-
-               internal int ReadMethodDef()
-               {
-                       return ReadIndex(bigMethodDef);
-               }
-
-               internal int ReadParam()
-               {
-                       return ReadIndex(bigParam);
-               }
-
-               internal int ReadProperty()
-               {
-                       return ReadIndex(bigProperty);
-               }
-
-               internal int ReadEvent()
-               {
-                       return ReadIndex(bigEvent);
-               }
-
-               internal int ReadTypeDef()
-               {
-                       return ReadIndex(bigTypeDef) | (TypeDefTable.Index << 24);
-               }
-
-               internal int ReadGenericParam()
-               {
-                       return ReadIndex(bigGenericParam) | (GenericParamTable.Index << 24);
-               }
-
-               internal int ReadModuleRef()
-               {
-                       return ReadIndex(bigModuleRef) | (ModuleRefTable.Index << 24);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/Method.cs b/mcs/class/IKVM.Reflection/Reader/Method.cs
deleted file mode 100644 (file)
index dd2712e..0000000
+++ /dev/null
@@ -1,394 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class MethodDefImpl : MethodInfo
-       {
-               private readonly ModuleReader module;
-               private readonly int index;
-               private readonly TypeDefImpl declaringType;
-               private MethodSignature lazyMethodSignature;
-               private ParameterInfo returnParameter;
-               private ParameterInfo[] parameters;
-               private Type[] typeArgs;
-
-               internal MethodDefImpl(ModuleReader module, TypeDefImpl declaringType, int index)
-               {
-                       this.module = module;
-                       this.index = index;
-                       this.declaringType = declaringType;
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       return GetMethodBody(this);
-               }
-
-               internal MethodBody GetMethodBody(IGenericContext context)
-               {
-                       if ((GetMethodImplementationFlags() & MethodImplAttributes.CodeTypeMask) != MethodImplAttributes.IL)
-                       {
-                               // method is not IL
-                               return null;
-                       }
-                       int rva = module.MethodDef.records[index].RVA;
-                       return rva == 0 ? null : new MethodBody(module, rva, context);
-               }
-
-               public override int __MethodRVA
-               {
-                       get { return module.MethodDef.records[index].RVA; }
-               }
-
-               public override CallingConventions CallingConvention
-               {
-                       get { return this.MethodSignature.CallingConvention; }
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return (MethodAttributes)module.MethodDef.records[index].Flags; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return (MethodImplAttributes)module.MethodDef.records[index].ImplFlags;
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       PopulateParameters();
-                       return (ParameterInfo[])parameters.Clone();
-               }
-
-               private void PopulateParameters()
-               {
-                       if (parameters == null)
-                       {
-                               MethodSignature methodSignature = this.MethodSignature;
-                               parameters = new ParameterInfo[methodSignature.GetParameterCount()];
-                               int parameter = module.MethodDef.records[index].ParamList - 1;
-                               int end = module.MethodDef.records.Length > index + 1 ? module.MethodDef.records[index + 1].ParamList - 1 : module.Param.records.Length;
-                               for (; parameter < end; parameter++)
-                               {
-                                       int seq = module.Param.records[parameter].Sequence - 1;
-                                       if (seq == -1)
-                                       {
-                                               returnParameter = new ParameterInfoImpl(this, seq, parameter);
-                                       }
-                                       else
-                                       {
-                                               parameters[seq] = new ParameterInfoImpl(this, seq, parameter);
-                                       }
-                               }
-                               for (int i = 0; i < parameters.Length; i++)
-                               {
-                                       if (parameters[i] == null)
-                                       {
-                                               parameters[i] = new ParameterInfoImpl(this, i, -1);
-                                       }
-                               }
-                               if (returnParameter == null)
-                               {
-                                       returnParameter = new ParameterInfoImpl(this, -1, -1);
-                               }
-                       }
-               }
-
-               internal override int ParameterCount
-               {
-                       get { return this.MethodSignature.GetParameterCount(); }
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get
-                       {
-                               PopulateParameters();
-                               return returnParameter;
-                       }
-               }
-
-               public override Type ReturnType
-               {
-                       get
-                       {
-                               return this.ReturnParameter.ParameterType;
-                       }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType.IsModulePseudoType ? null : declaringType; }
-               }
-
-               public override string Name
-               {
-                       get { return module.GetString(module.MethodDef.records[index].Name); }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (MethodDefTable.Index << 24) + index + 1; }
-               }
-
-               public override bool IsGenericMethodDefinition
-               {
-                       get
-                       {
-                               PopulateGenericArguments();
-                               return typeArgs.Length > 0;
-                       }
-               }
-
-               public override bool IsGenericMethod
-               {
-                       get { return IsGenericMethodDefinition; }
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       PopulateGenericArguments();
-                       return Util.Copy(typeArgs);
-               }
-
-               private void PopulateGenericArguments()
-               {
-                       if (typeArgs == null)
-                       {
-                               int token = this.MetadataToken;
-                               int first = module.GenericParam.FindFirstByOwner(token);
-                               if (first == -1)
-                               {
-                                       typeArgs = Type.EmptyTypes;
-                               }
-                               else
-                               {
-                                       List<Type> list = new List<Type>();
-                                       int len = module.GenericParam.records.Length;
-                                       for (int i = first; i < len && module.GenericParam.records[i].Owner == token; i++)
-                                       {
-                                               list.Add(new GenericTypeParameter(module, i));
-                                       }
-                                       typeArgs = list.ToArray();
-                               }
-                       }
-               }
-
-               internal override Type GetGenericMethodArgument(int index)
-               {
-                       PopulateGenericArguments();
-                       return typeArgs[index];
-               }
-
-               internal override int GetGenericMethodArgumentCount()
-               {
-                       PopulateGenericArguments();
-                       return typeArgs.Length;
-               }
-
-               public override MethodInfo GetGenericMethodDefinition()
-               {
-                       if (this.IsGenericMethodDefinition)
-                       {
-                               return this;
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               public override MethodInfo MakeGenericMethod(params Type[] typeArguments)
-               {
-                       return new GenericMethodInstance(declaringType, this, typeArguments);
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               internal override MethodSignature MethodSignature
-               {
-                       get { return lazyMethodSignature ?? (lazyMethodSignature = MethodSignature.ReadSig(module, module.GetBlob(module.MethodDef.records[index].Signature), this)); }
-               }
-
-               internal override int ImportTo(Emit.ModuleBuilder module)
-               {
-                       return module.ImportMethodOrField(declaringType, this.Name, this.MethodSignature);
-               }
-
-               public override MethodInfo[] __GetMethodImpls()
-               {
-                       Type[] typeArgs = null;
-                       List<MethodInfo> list = null;
-                       foreach (int i in module.MethodImpl.Filter(declaringType.MetadataToken))
-                       {
-                               if (module.MethodImpl.records[i].MethodBody == this.MetadataToken)
-                               {
-                                       if (typeArgs == null)
-                                       {
-                                               typeArgs = declaringType.GetGenericArguments();
-                                       }
-                                       if (list == null)
-                                       {
-                                               list = new List<MethodInfo>();
-                                       }
-                                       list.Add((MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null));
-                               }
-                       }
-                       return Util.ToArray(list, Empty<MethodInfo>.Array);
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-
-       sealed class ParameterInfoImpl : ParameterInfo
-       {
-               private readonly MethodDefImpl method;
-               private readonly int position;
-               private readonly int index;
-
-               internal ParameterInfoImpl(MethodDefImpl method, int position, int index)
-               {
-                       this.method = method;
-                       this.position = position;
-                       this.index = index;
-               }
-
-               public override string Name
-               {
-                       get { return index == -1 ? null : ((ModuleReader)this.Module).GetString(this.Module.Param.records[index].Name); }
-               }
-
-               public override Type ParameterType
-               {
-                       get { return position == -1 ? method.MethodSignature.GetReturnType(method) : method.MethodSignature.GetParameterType(method, position); }
-               }
-
-               public override ParameterAttributes Attributes
-               {
-                       get { return index == -1 ? ParameterAttributes.None : (ParameterAttributes)this.Module.Param.records[index].Flags; }
-               }
-
-               public override int Position
-               {
-                       get { return position; }
-               }
-
-               public override object RawDefaultValue
-               {
-                       get
-                       {
-                               if ((this.Attributes & ParameterAttributes.HasDefault) != 0)
-                               {
-                                       return this.Module.Constant.GetRawConstantValue(this.Module, this.MetadataToken);
-                               }
-                               Universe universe = this.Module.universe;
-                               if (this.ParameterType == universe.System_Decimal)
-                               {
-                                       Type attr = universe.System_Runtime_CompilerServices_DecimalConstantAttribute;
-                                       if (attr != null)
-                                       {
-                                               foreach (CustomAttributeData cad in CustomAttributeData.__GetCustomAttributes(this, attr, false))
-                                               {
-                                                       IList<CustomAttributeTypedArgument> args = cad.ConstructorArguments;
-                                                       if (args.Count == 5)
-                                                       {
-                                                               if (args[0].ArgumentType == universe.System_Byte
-                                                                       && args[1].ArgumentType == universe.System_Byte
-                                                                       && args[2].ArgumentType == universe.System_Int32
-                                                                       && args[3].ArgumentType == universe.System_Int32
-                                                                       && args[4].ArgumentType == universe.System_Int32)
-                                                               {
-                                                                       return new Decimal((int)args[4].Value, (int)args[3].Value, (int)args[2].Value, (byte)args[1].Value != 0, (byte)args[0].Value);
-                                                               }
-                                                               else if (args[0].ArgumentType == universe.System_Byte
-                                                                       && args[1].ArgumentType == universe.System_Byte
-                                                                       && args[2].ArgumentType == universe.System_UInt32
-                                                                       && args[3].ArgumentType == universe.System_UInt32
-                                                                       && args[4].ArgumentType == universe.System_UInt32)
-                                                               {
-                                                                       return new Decimal(unchecked((int)(uint)args[4].Value), unchecked((int)(uint)args[3].Value), unchecked((int)(uint)args[2].Value), (byte)args[1].Value != 0, (byte)args[0].Value);
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-                               if ((this.Attributes & ParameterAttributes.Optional) != 0)
-                               {
-                                       return Missing.Value;
-                               }
-                               return null;
-                       }
-               }
-
-               public override CustomModifiers __GetCustomModifiers()
-               {
-                       return position == -1
-                               ? method.MethodSignature.GetReturnTypeCustomModifiers(method)
-                               : method.MethodSignature.GetParameterCustomModifiers(method, position);
-               }
-
-               public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-               {
-                       return FieldMarshal.ReadFieldMarshal(this.Module, this.MetadataToken, out fieldMarshal);
-               }
-
-               public override MemberInfo Member
-               {
-                       get
-                       {
-                               // return the right ConstructorInfo wrapper
-                               return method.Module.ResolveMethod(method.MetadataToken);
-                       }
-               }
-
-               public override int MetadataToken
-               {
-                       get
-                       {
-                               // for parameters that don't have a row in the Param table, we return 0x08000000 (because index is -1 in that case),
-                               // just like .NET
-                               return (ParamTable.Index << 24) + index + 1;
-                       }
-               }
-
-               internal override Module Module
-               {
-                       get { return method.Module; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/ModuleReader.cs b/mcs/class/IKVM.Reflection/Reader/ModuleReader.cs
deleted file mode 100644 (file)
index c392033..0000000
+++ /dev/null
@@ -1,1269 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using System.Text;
-using System.Collections.Generic;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class StreamHeader
-       {
-               internal uint Offset;
-               internal uint Size;
-               internal string Name;
-
-               internal void Read(BinaryReader br)
-               {
-                       Offset = br.ReadUInt32();
-                       Size = br.ReadUInt32();
-                       byte[] buf = new byte[32];
-                       byte b;
-                       int len = 0;
-                       while ((b = br.ReadByte()) != 0)
-                       {
-                               buf[len++] = b;
-                       }
-                       Name = Encoding.UTF8.GetString(buf, 0, len); ;
-                       int padding = -1 + ((len + 4) & ~3) - len;
-                       br.BaseStream.Seek(padding, SeekOrigin.Current);
-               }
-       }
-
-       sealed class ModuleReader : Module
-       {
-               internal readonly Stream stream;
-               private readonly string location;
-               private Assembly assembly;
-               private readonly PEReader peFile = new PEReader();
-               private readonly CliHeader cliHeader = new CliHeader();
-               private string imageRuntimeVersion;
-               private int metadataStreamVersion;
-               private byte[] stringHeap;
-               private byte[] blobHeap;
-               private byte[] userStringHeap;
-               private byte[] guidHeap;
-               private TypeDefImpl[] typeDefs;
-               private TypeDefImpl moduleType;
-               private Assembly[] assemblyRefs;
-               private Type[] typeRefs;
-               private Type[] typeSpecs;
-               private FieldInfo[] fields;
-               private MethodBase[] methods;
-               private MemberInfo[] memberRefs;
-               private Dictionary<int, string> strings = new Dictionary<int, string>();
-               private Dictionary<TypeName, Type> types = new Dictionary<TypeName, Type>();
-               private Dictionary<TypeName, LazyForwardedType> forwardedTypes = new Dictionary<TypeName, LazyForwardedType>();
-
-               private sealed class LazyForwardedType
-               {
-                       private readonly int index;
-                       private Type type;
-
-                       internal LazyForwardedType(int index)
-                       {
-                               this.index = index;
-                       }
-
-                       internal Type GetType(ModuleReader module)
-                       {
-                               return type ?? (type = module.ResolveExportedType(index));
-                       }
-               }
-
-               internal ModuleReader(AssemblyReader assembly, Universe universe, Stream stream, string location)
-                       : base(universe)
-               {
-                       this.stream = stream;
-                       this.location = location;
-                       Read();
-                       if (assembly == null && AssemblyTable.records.Length != 0)
-                       {
-                               assembly = new AssemblyReader(location, this);
-                       }
-                       this.assembly = assembly;
-               }
-
-               private void Read()
-               {
-                       BinaryReader br = new BinaryReader(stream);
-                       peFile.Read(br);
-                       stream.Seek(peFile.RvaToFileOffset(peFile.GetComDescriptorVirtualAddress()), SeekOrigin.Begin);
-                       cliHeader.Read(br);
-                       stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress), SeekOrigin.Begin);
-                       foreach (StreamHeader sh in ReadStreamHeaders(br, out imageRuntimeVersion))
-                       {
-                               switch (sh.Name)
-                               {
-                                       case "#Strings":
-                                               stringHeap = ReadHeap(stream, sh);
-                                               break;
-                                       case "#Blob":
-                                               blobHeap = ReadHeap(stream, sh);
-                                               break;
-                                       case "#US":
-                                               userStringHeap = ReadHeap(stream, sh);
-                                               break;
-                                       case "#GUID":
-                                               guidHeap = ReadHeap(stream, sh);
-                                               break;
-                                       case "#~":
-                                       case "#-":
-                                               stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + sh.Offset), SeekOrigin.Begin);
-                                               ReadTables(br);
-                                               break;
-                                       default:
-                                               // we ignore unknown streams, because the CLR does so too
-                                               // (and some obfuscators add bogus streams)
-                                               break;
-                               }
-                       }
-               }
-
-               internal void SetAssembly(Assembly assembly)
-               {
-                       this.assembly = assembly;
-               }
-
-               private static StreamHeader[] ReadStreamHeaders(BinaryReader br, out string Version)
-               {
-                       uint Signature = br.ReadUInt32();
-                       if (Signature != 0x424A5342)
-                       {
-                               throw new BadImageFormatException("Invalid metadata signature");
-                       }
-                       /*ushort MajorVersion =*/ br.ReadUInt16();
-                       /*ushort MinorVersion =*/ br.ReadUInt16();
-                       /*uint Reserved =*/ br.ReadUInt32();
-                       uint Length = br.ReadUInt32();
-                       byte[] buf = br.ReadBytes((int)Length);
-                       Version = Encoding.UTF8.GetString(buf).TrimEnd('\u0000');
-                       /*ushort Flags =*/ br.ReadUInt16();
-                       ushort Streams = br.ReadUInt16();
-                       StreamHeader[] streamHeaders = new StreamHeader[Streams];
-                       for (int i = 0; i < streamHeaders.Length; i++)
-                       {
-                               streamHeaders[i] = new StreamHeader();
-                               streamHeaders[i].Read(br);
-                       }
-                       return streamHeaders;
-               }
-
-               private void ReadTables(BinaryReader br)
-               {
-                       Table[] tables = GetTables();
-                       /*uint Reserved0 =*/ br.ReadUInt32();
-                       byte MajorVersion = br.ReadByte();
-                       byte MinorVersion = br.ReadByte();
-                       metadataStreamVersion = MajorVersion << 16 | MinorVersion;
-                       byte HeapSizes = br.ReadByte();
-                       /*byte Reserved7 =*/ br.ReadByte();
-                       ulong Valid = br.ReadUInt64();
-                       ulong Sorted = br.ReadUInt64();
-                       for (int i = 0; i < 64; i++)
-                       {
-                               if ((Valid & (1UL << i)) != 0)
-                               {
-                                       tables[i].Sorted = (Sorted & (1UL << i)) != 0;
-                                       tables[i].RowCount = br.ReadInt32();
-                               }
-                       }
-                       MetadataReader mr = new MetadataReader(this, br.BaseStream, HeapSizes);
-                       for (int i = 0; i < 64; i++)
-                       {
-                               if ((Valid & (1UL << i)) != 0)
-                               {
-                                       tables[i].Read(mr);
-                               }
-                       }
-                       if (ParamPtr.RowCount != 0)
-                       {
-                               throw new NotImplementedException("ParamPtr table support has not yet been implemented.");
-                       }
-               }
-
-               private byte[] ReadHeap(Stream stream, StreamHeader sh)
-               {
-                       byte[] buf = new byte[sh.Size];
-                       stream.Seek(peFile.RvaToFileOffset(cliHeader.MetaData.VirtualAddress + sh.Offset), SeekOrigin.Begin);
-                       for (int pos = 0; pos < buf.Length; )
-                       {
-                               int read = stream.Read(buf, pos, buf.Length - pos);
-                               if (read == 0)
-                               {
-                                       throw new BadImageFormatException();
-                               }
-                               pos += read;
-                       }
-                       return buf;
-               }
-
-               internal void SeekRVA(int rva)
-               {
-                       stream.Seek(peFile.RvaToFileOffset((uint)rva), SeekOrigin.Begin);
-               }
-
-               internal override void GetTypesImpl(List<Type> list)
-               {
-                       PopulateTypeDef();
-                       foreach (TypeDefImpl type in typeDefs)
-                       {
-                               if (type != moduleType)
-                               {
-                                       list.Add(type);
-                               }
-                       }
-               }
-
-               private void PopulateTypeDef()
-               {
-                       if (typeDefs == null)
-                       {
-                               typeDefs = new TypeDefImpl[TypeDef.records.Length];
-                               for (int i = 0; i < typeDefs.Length; i++)
-                               {
-                                       TypeDefImpl type = new TypeDefImpl(this, i);
-                                       typeDefs[i] = type;
-                                       if (type.IsModulePseudoType)
-                                       {
-                                               moduleType = type;
-                                       }
-                                       else if (!type.IsNestedByFlags)
-                                       {
-                                               types.Add(new TypeName(type.__Namespace, type.__Name), type);
-                                       }
-                               }
-                               // add forwarded types to forwardedTypes dictionary (because Module.GetType(string) should return them)
-                               for (int i = 0; i < ExportedType.records.Length; i++)
-                               {
-                                       int implementation = ExportedType.records[i].Implementation;
-                                       if (implementation >> 24 == AssemblyRefTable.Index)
-                                       {
-                                               TypeName typeName = GetTypeName(ExportedType.records[i].TypeNamespace, ExportedType.records[i].TypeName);
-                                               forwardedTypes.Add(typeName, new LazyForwardedType(i));
-                                       }
-                               }
-                       }
-               }
-
-               internal override string GetString(int index)
-               {
-                       if (index == 0)
-                       {
-                               return null;
-                       }
-                       string str;
-                       if (!strings.TryGetValue(index, out str))
-                       {
-                               int len = 0;
-                               while (stringHeap[index + len] != 0)
-                               {
-                                       len++;
-                               }
-                               str = Encoding.UTF8.GetString(stringHeap, index, len);
-                               strings.Add(index, str);
-                       }
-                       return str;
-               }
-
-               private static int ReadCompressedUInt(byte[] buffer, ref int offset)
-               {
-                       byte b1 = buffer[offset++];
-                       if (b1 <= 0x7F)
-                       {
-                               return b1;
-                       }
-                       else if ((b1 & 0xC0) == 0x80)
-                       {
-                               byte b2 = buffer[offset++];
-                               return ((b1 & 0x3F) << 8) | b2;
-                       }
-                       else
-                       {
-                               byte b2 = buffer[offset++];
-                               byte b3 = buffer[offset++];
-                               byte b4 = buffer[offset++];
-                               return ((b1 & 0x3F) << 24) + (b2 << 16) + (b3 << 8) + b4;
-                       }
-               }
-
-               internal byte[] GetBlobCopy(int blobIndex)
-               {
-                       int len = ReadCompressedUInt(blobHeap, ref blobIndex);
-                       byte[] buf = new byte[len];
-                       Buffer.BlockCopy(blobHeap, blobIndex, buf, 0, len);
-                       return buf;
-               }
-
-               internal override ByteReader GetBlob(int blobIndex)
-               {
-                       return ByteReader.FromBlob(blobHeap, blobIndex);
-               }
-
-               public override string ResolveString(int metadataToken)
-               {
-                       string str;
-                       if (!strings.TryGetValue(metadataToken, out str))
-                       {
-                               if ((metadataToken >> 24) != 0x70)
-                               {
-                                       throw TokenOutOfRangeException(metadataToken);
-                               }
-                               int index = metadataToken & 0xFFFFFF;
-                               int len = ReadCompressedUInt(userStringHeap, ref index) & ~1;
-                               StringBuilder sb = new StringBuilder(len / 2);
-                               for (int i = 0; i < len; i += 2)
-                               {
-                                       char ch = (char)(userStringHeap[index + i] | userStringHeap[index + i + 1] << 8);
-                                       sb.Append(ch);
-                               }
-                               str = sb.ToString();
-                               strings.Add(metadataToken, str);
-                       }
-                       return str;
-               }
-
-               internal override Type ResolveType(int metadataToken, IGenericContext context)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if (index < 0)
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-                       else if ((metadataToken >> 24) == TypeDefTable.Index && index < TypeDef.RowCount)
-                       {
-                               PopulateTypeDef();
-                               return typeDefs[index];
-                       }
-                       else if ((metadataToken >> 24) == TypeRefTable.Index && index < TypeRef.RowCount)
-                       {
-                               if (typeRefs == null)
-                               {
-                                       typeRefs = new Type[TypeRef.records.Length];
-                               }
-                               if (typeRefs[index] == null)
-                               {
-                                       int scope = TypeRef.records[index].ResolutionScope;
-                                       switch (scope >> 24)
-                                       {
-                                               case AssemblyRefTable.Index:
-                                                       {
-                                                               Assembly assembly = ResolveAssemblyRef((scope & 0xFFFFFF) - 1);
-                                                               TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
-                                                               typeRefs[index] = assembly.ResolveType(typeName);
-                                                               break;
-                                                       }
-                                               case TypeRefTable.Index:
-                                                       {
-                                                               Type outer = ResolveType(scope, null);
-                                                               TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
-                                                               typeRefs[index] = outer.ResolveNestedType(typeName);
-                                                               break;
-                                                       }
-                                               case ModuleTable.Index:
-                                               case ModuleRefTable.Index:
-                                                       {
-                                                               Module module;
-                                                               if (scope >> 24 == ModuleTable.Index)
-                                                               {
-                                                                       if (scope == 0 || scope == 1)
-                                                                       {
-                                                                               module = this;
-                                                                       }
-                                                                       else
-                                                                       {
-                                                                               throw new NotImplementedException("self reference scope?");
-                                                                       }
-                                                               }
-                                                               else
-                                                               {
-                                                                       module = ResolveModuleRef(ModuleRef.records[(scope & 0xFFFFFF) - 1]);
-                                                               }
-                                                               TypeName typeName = GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName);
-                                                               typeRefs[index] = module.FindType(typeName) ?? module.universe.GetMissingTypeOrThrow(module, null, typeName);
-                                                               break;
-                                                       }
-                                               default:
-                                                       throw new NotImplementedException("ResolutionScope = " + scope.ToString("X"));
-                                       }
-                               }
-                               return typeRefs[index];
-                       }
-                       else if ((metadataToken >> 24) == TypeSpecTable.Index && index < TypeSpec.RowCount)
-                       {
-                               if (typeSpecs == null)
-                               {
-                                       typeSpecs = new Type[TypeSpec.records.Length];
-                               }
-                               Type type = typeSpecs[index];
-                               if (type == null)
-                               {
-                                       TrackingGenericContext tc = context == null ? null : new TrackingGenericContext(context);
-                                       type = Signature.ReadTypeSpec(this, ByteReader.FromBlob(blobHeap, TypeSpec.records[index]), tc);
-                                       if (tc == null || !tc.IsUsed)
-                                       {
-                                               typeSpecs[index] = type;
-                                       }
-                               }
-                               return type;
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               private Module ResolveModuleRef(int moduleNameIndex)
-               {
-                       string moduleName = GetString(moduleNameIndex);
-                       Module module = assembly.GetModule(moduleName);
-                       if (module == null)
-                       {
-                               throw new FileNotFoundException(moduleName);
-                       }
-                       return module;
-               }
-
-               private sealed class TrackingGenericContext : IGenericContext
-               {
-                       private readonly IGenericContext context;
-                       private bool used;
-
-                       internal TrackingGenericContext(IGenericContext context)
-                       {
-                               this.context = context;
-                       }
-
-                       internal bool IsUsed
-                       {
-                               get { return used; }
-                       }
-
-                       public Type GetGenericTypeArgument(int index)
-                       {
-                               used = true;
-                               return context.GetGenericTypeArgument(index);
-                       }
-
-                       public Type GetGenericMethodArgument(int index)
-                       {
-                               used = true;
-                               return context.GetGenericMethodArgument(index);
-                       }
-               }
-
-               private TypeName GetTypeName(int typeNamespace, int typeName)
-               {
-                       return new TypeName(GetString(typeNamespace), GetString(typeName));
-               }
-
-               internal Assembly ResolveAssemblyRef(int index)
-               {
-                       if (assemblyRefs == null)
-                       {
-                               assemblyRefs = new Assembly[AssemblyRef.RowCount];
-                       }
-                       if (assemblyRefs[index] == null)
-                       {
-                               assemblyRefs[index] = ResolveAssemblyRefImpl(ref AssemblyRef.records[index]);
-                       }
-                       return assemblyRefs[index];
-               }
-
-               private Assembly ResolveAssemblyRefImpl(ref AssemblyRefTable.Record rec)
-               {
-                       const int PublicKey = 0x0001;
-                       string name = String.Format("{0}, Version={1}.{2}.{3}.{4}, Culture={5}, {6}={7}",
-                               GetString(rec.Name),
-                               rec.MajorVersion,
-                               rec.MinorVersion,
-                               rec.BuildNumber,
-                               rec.RevisionNumber,
-                               rec.Culture == 0 ? "neutral" : GetString(rec.Culture),
-                               (rec.Flags & PublicKey) == 0 ? "PublicKeyToken" : "PublicKey",
-                               PublicKeyOrTokenToString(rec.PublicKeyOrToken));
-                       return universe.Load(name, this.Assembly, true);
-               }
-
-               private string PublicKeyOrTokenToString(int publicKeyOrToken)
-               {
-                       if (publicKeyOrToken == 0)
-                       {
-                               return "null";
-                       }
-                       ByteReader br = GetBlob(publicKeyOrToken);
-                       if (br.Length == 0)
-                       {
-                               return "null";
-                       }
-                       StringBuilder sb = new StringBuilder(br.Length * 2);
-                       while (br.Length > 0)
-                       {
-                               sb.AppendFormat("{0:x2}", br.ReadByte());
-                       }
-                       return sb.ToString();
-               }
-
-               public override Guid ModuleVersionId
-               {
-                       get
-                       {
-                               byte[] buf = new byte[16];
-                               Buffer.BlockCopy(guidHeap, 16 * (ModuleTable.records[0].Mvid - 1), buf, 0, 16);
-                               return new Guid(buf);
-                       }
-               }
-
-               public override string FullyQualifiedName
-               {
-                       get { return location ?? "<Unknown>"; }
-               }
-
-               public override string Name
-               {
-                       get { return location == null ? "<Unknown>" : System.IO.Path.GetFileName(location); }
-               }
-
-               public override Assembly Assembly
-               {
-                       get { return assembly; }
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       PopulateTypeDef();
-                       Type type;
-                       if (!types.TryGetValue(typeName, out type))
-                       {
-                               LazyForwardedType fw;
-                               if (forwardedTypes.TryGetValue(typeName, out fw))
-                               {
-                                       return fw.GetType(this);
-                               }
-                       }
-                       return type;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       PopulateTypeDef();
-                       foreach (Type type in types.Values)
-                       {
-                               if (new TypeName(type.__Namespace, type.__Name).ToLowerInvariant() == lowerCaseName)
-                               {
-                                       return type;
-                               }
-                       }
-                       foreach (TypeName name in forwardedTypes.Keys)
-                       {
-                               if (name.ToLowerInvariant() == lowerCaseName)
-                               {
-                                       return forwardedTypes[name].GetType(this);
-                               }
-                       }
-                       return null;
-               }
-
-               private Exception TokenOutOfRangeException(int metadataToken)
-               {
-                       return new ArgumentOutOfRangeException("metadataToken", String.Format("Token 0x{0:x8} is not valid in the scope of module {1}.", metadataToken, this.Name));
-               }
-
-               public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       switch (metadataToken >> 24)
-                       {
-                               case FieldTable.Index:
-                                       return ResolveField(metadataToken, genericTypeArguments, genericMethodArguments);
-                               case MemberRefTable.Index:
-                                       int index = (metadataToken & 0xFFFFFF) - 1;
-                                       if (index < 0 || index >= MemberRef.RowCount)
-                                       {
-                                               goto default;
-                                       }
-                                       return GetMemberRef(index, genericTypeArguments, genericMethodArguments);
-                               case MethodDefTable.Index:
-                               case MethodSpecTable.Index:
-                                       return ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments);
-                               case TypeRefTable.Index:
-                               case TypeDefTable.Index:
-                               case TypeSpecTable.Index:
-                                       return ResolveType(metadataToken, genericTypeArguments, genericMethodArguments);
-                               default:
-                                       throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               internal FieldInfo GetFieldAt(TypeDefImpl owner, int index)
-               {
-                       if (fields == null)
-                       {
-                               fields = new FieldInfo[Field.records.Length];
-                       }
-                       if (fields[index] == null)
-                       {
-                               fields[index] = new FieldDefImpl(this, owner ?? FindFieldOwner(index), index);
-                       }
-                       return fields[index];
-               }
-
-               public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if (index < 0)
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-                       else if ((metadataToken >> 24) == FieldTable.Index && index < Field.RowCount)
-                       {
-                               return GetFieldAt(null, index);
-                       }
-                       else if ((metadataToken >> 24) == MemberRefTable.Index && index < MemberRef.RowCount)
-                       {
-                               FieldInfo field = GetMemberRef(index, genericTypeArguments, genericMethodArguments) as FieldInfo;
-                               if (field != null)
-                               {
-                                       return field;
-                               }
-                               throw new ArgumentException(String.Format("Token 0x{0:x8} is not a valid FieldInfo token in the scope of module {1}.", metadataToken, this.Name), "metadataToken");
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               private TypeDefImpl FindFieldOwner(int fieldIndex)
-               {
-                       // TODO use binary search?
-                       for (int i = 0; i < TypeDef.records.Length; i++)
-                       {
-                               int field = TypeDef.records[i].FieldList - 1;
-                               int end = TypeDef.records.Length > i + 1 ? TypeDef.records[i + 1].FieldList - 1 : Field.records.Length;
-                               if (field <= fieldIndex && fieldIndex < end)
-                               {
-                                       PopulateTypeDef();
-                                       return typeDefs[i];
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               internal MethodBase GetMethodAt(TypeDefImpl owner, int index)
-               {
-                       if (methods == null)
-                       {
-                               methods = new MethodBase[MethodDef.records.Length];
-                       }
-                       if (methods[index] == null)
-                       {
-                               MethodDefImpl method = new MethodDefImpl(this, owner ?? FindMethodOwner(index), index);
-                               methods[index] = method.IsConstructor ? new ConstructorInfoImpl(method) : (MethodBase)method;
-                       }
-                       return methods[index];
-               }
-
-               public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if (index < 0)
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-                       else if ((metadataToken >> 24) == MethodDefTable.Index && index < MethodDef.RowCount)
-                       {
-                               return GetMethodAt(null, index);
-                       }
-                       else if ((metadataToken >> 24) == MemberRefTable.Index && index < MemberRef.RowCount)
-                       {
-                               MethodBase method = GetMemberRef(index, genericTypeArguments, genericMethodArguments) as MethodBase;
-                               if (method != null)
-                               {
-                                       return method;
-                               }
-                               throw new ArgumentException(String.Format("Token 0x{0:x8} is not a valid MethodBase token in the scope of module {1}.", metadataToken, this.Name), "metadataToken");
-                       }
-                       else if ((metadataToken >> 24) == MethodSpecTable.Index && index < MethodSpec.RowCount)
-                       {
-                               MethodInfo method = (MethodInfo)ResolveMethod(MethodSpec.records[index].Method, genericTypeArguments, genericMethodArguments);
-                               ByteReader instantiation = ByteReader.FromBlob(blobHeap, MethodSpec.records[index].Instantiation);
-                               return method.MakeGenericMethod(Signature.ReadMethodSpec(this, instantiation, new GenericContext(genericTypeArguments, genericMethodArguments)));
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               public override Type[] __ResolveOptionalParameterTypes(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments, out CustomModifiers[] customModifiers)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if (index < 0)
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-                       else if ((metadataToken >> 24) == MemberRefTable.Index && index < MemberRef.RowCount)
-                       {
-                               int sig = MemberRef.records[index].Signature;
-                               return Signature.ReadOptionalParameterTypes(this, GetBlob(sig), new GenericContext(genericTypeArguments, genericMethodArguments), out customModifiers);
-                       }
-                       else if ((metadataToken >> 24) == MethodDefTable.Index && index < MethodDef.RowCount)
-                       {
-                               // for convenience, we support passing a MethodDef token as well, because in some places
-                               // it makes sense to have a vararg method that is referred to by its methoddef (e.g. ldftn).
-                               // Note that MethodSpec doesn't make sense, because generic methods cannot be vararg.
-                               customModifiers = Empty<CustomModifiers>.Array;
-                               return Type.EmptyTypes;
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               public override string ScopeName
-               {
-                       get { return GetString(ModuleTable.records[0].Name); }
-               }
-
-               private TypeDefImpl FindMethodOwner(int methodIndex)
-               {
-                       // TODO use binary search?
-                       for (int i = 0; i < TypeDef.records.Length; i++)
-                       {
-                               int method = TypeDef.records[i].MethodList - 1;
-                               int end = TypeDef.records.Length > i + 1 ? TypeDef.records[i + 1].MethodList - 1 : MethodDef.records.Length;
-                               if (method <= methodIndex && methodIndex < end)
-                               {
-                                       PopulateTypeDef();
-                                       return typeDefs[i];
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               private MemberInfo GetMemberRef(int index, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       if (memberRefs == null)
-                       {
-                               memberRefs = new MemberInfo[MemberRef.records.Length];
-                       }
-                       if (memberRefs[index] == null)
-                       {
-                               int owner = MemberRef.records[index].Class;
-                               int sig = MemberRef.records[index].Signature;
-                               string name = GetString(MemberRef.records[index].Name);
-                               switch (owner >> 24)
-                               {
-                                       case MethodDefTable.Index:
-                                               return GetMethodAt(null, (owner & 0xFFFFFF) - 1);
-                                       case ModuleRefTable.Index:
-                                               memberRefs[index] = ResolveTypeMemberRef(ResolveModuleType(owner), name, ByteReader.FromBlob(blobHeap, sig));
-                                               break;
-                                       case TypeDefTable.Index:
-                                       case TypeRefTable.Index:
-                                               memberRefs[index] = ResolveTypeMemberRef(ResolveType(owner), name, ByteReader.FromBlob(blobHeap, sig));
-                                               break;
-                                       case TypeSpecTable.Index:
-                                       {
-                                               Type type = ResolveType(owner, genericTypeArguments, genericMethodArguments);
-                                               if (type.IsArray)
-                                               {
-                                                       MethodSignature methodSig = MethodSignature.ReadSig(this, ByteReader.FromBlob(blobHeap, sig), new GenericContext(genericTypeArguments, genericMethodArguments));
-                                                       return type.FindMethod(name, methodSig)
-                                                               ?? universe.GetMissingMethodOrThrow(type, name, methodSig);
-                                               }
-                                               else if (type.IsConstructedGenericType)
-                                               {
-                                                       MemberInfo member = ResolveTypeMemberRef(type.GetGenericTypeDefinition(), name, ByteReader.FromBlob(blobHeap, sig));
-                                                       MethodBase mb = member as MethodBase;
-                                                       if (mb != null)
-                                                       {
-                                                               member = mb.BindTypeParameters(type);
-                                                       }
-                                                       FieldInfo fi = member as FieldInfo;
-                                                       if (fi != null)
-                                                       {
-                                                               member = fi.BindTypeParameters(type);
-                                                       }
-                                                       return member;
-                                               }
-                                               else
-                                               {
-                                                       return ResolveTypeMemberRef(type, name, ByteReader.FromBlob(blobHeap, sig));
-                                               }
-                                       }
-                                       default:
-                                               throw new BadImageFormatException();
-                               }
-                       }
-                       return memberRefs[index];
-               }
-
-               private Type ResolveModuleType(int token)
-               {
-                       int index = (token & 0xFFFFFF) - 1;
-                       string name = GetString(ModuleRef.records[index]);
-                       Module module = assembly.GetModule(name);
-                       if (module == null || module.IsResource())
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       return module.GetModuleType();
-               }
-
-               private MemberInfo ResolveTypeMemberRef(Type type, string name, ByteReader sig)
-               {
-                       if (sig.PeekByte() == Signature.FIELD)
-                       {
-                               Type org = type;
-                               FieldSignature fieldSig = FieldSignature.ReadSig(this, sig, type);
-                               FieldInfo field = type.FindField(name, fieldSig);
-                               if (field == null && universe.MissingMemberResolution)
-                               {
-                                       return universe.GetMissingFieldOrThrow(type, name, fieldSig);
-                               }
-                               while (field == null && (type = type.BaseType) != null)
-                               {
-                                       field = type.FindField(name, fieldSig);
-                               }
-                               if (field != null)
-                               {
-                                       return field;
-                               }
-                               throw new MissingFieldException(org.ToString(), name);
-                       }
-                       else
-                       {
-                               Type org = type;
-                               MethodSignature methodSig = MethodSignature.ReadSig(this, sig, type);
-                               MethodBase method = type.FindMethod(name, methodSig);
-                               if (method == null && universe.MissingMemberResolution)
-                               {
-                                       return universe.GetMissingMethodOrThrow(type, name, methodSig);
-                               }
-                               while (method == null && (type = type.BaseType) != null)
-                               {
-                                       method = type.FindMethod(name, methodSig);
-                               }
-                               if (method != null)
-                               {
-                                       return method;
-                               }
-                               throw new MissingMethodException(org.ToString(), name);
-                       }
-               }
-
-               internal ByteReader GetStandAloneSig(int index)
-               {
-                       return ByteReader.FromBlob(blobHeap, StandAloneSig.records[index]);
-               }
-
-               public override byte[] ResolveSignature(int metadataToken)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if ((metadataToken >> 24) == StandAloneSigTable.Index && index >= 0 && index < StandAloneSig.RowCount)
-                       {
-                               ByteReader br = GetStandAloneSig(index);
-                               return br.ReadBytes(br.Length);
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               public override __StandAloneMethodSig __ResolveStandAloneMethodSig(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
-               {
-                       int index = (metadataToken & 0xFFFFFF) - 1;
-                       if ((metadataToken >> 24) == StandAloneSigTable.Index && index >= 0 && index < StandAloneSig.RowCount)
-                       {
-                               return MethodSignature.ReadStandAloneMethodSig(this, GetStandAloneSig(index), new GenericContext(genericTypeArguments, genericMethodArguments));
-                       }
-                       else
-                       {
-                               throw TokenOutOfRangeException(metadataToken);
-                       }
-               }
-
-               internal MethodInfo GetEntryPoint()
-               {
-                       if (cliHeader.EntryPointToken != 0 && (cliHeader.Flags & CliHeader.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT) == 0)
-                       {
-                               return (MethodInfo)ResolveMethod((int)cliHeader.EntryPointToken);
-                       }
-                       return null;
-               }
-
-               internal string[] GetManifestResourceNames()
-               {
-                       string[] names = new string[ManifestResource.records.Length];
-                       for (int i = 0; i < ManifestResource.records.Length; i++)
-                       {
-                               names[i] = GetString(ManifestResource.records[i].Name);
-                       }
-                       return names;
-               }
-
-               internal ManifestResourceInfo GetManifestResourceInfo(string resourceName)
-               {
-                       for (int i = 0; i < ManifestResource.records.Length; i++)
-                       {
-                               if (resourceName == GetString(ManifestResource.records[i].Name))
-                               {
-                                       ManifestResourceInfo info = new ManifestResourceInfo(this, i);
-                                       Assembly asm = info.ReferencedAssembly;
-                                       if (asm != null && !asm.__IsMissing && asm.GetManifestResourceInfo(resourceName) == null)
-                                       {
-                                               return null;
-                                       }
-                                       return info;
-                               }
-                       }
-                       return null;
-               }
-
-               internal Stream GetManifestResourceStream(string resourceName)
-               {
-                       for (int i = 0; i < ManifestResource.records.Length; i++)
-                       {
-                               if (resourceName == GetString(ManifestResource.records[i].Name))
-                               {
-                                       if (ManifestResource.records[i].Implementation != 0x26000000)
-                                       {
-                                               ManifestResourceInfo info = new ManifestResourceInfo(this, i);
-                                               switch (ManifestResource.records[i].Implementation >> 24)
-                                               {
-                                                       case FileTable.Index:
-                                                               string fileName = Path.Combine(Path.GetDirectoryName(location), info.FileName);
-                                                               if (System.IO.File.Exists(fileName))
-                                                               {
-                                                                       // note that, like System.Reflection, we return null for zero length files and
-                                                                       // ManifestResource.Offset is ignored
-                                                                       FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete);
-                                                                       if (fs.Length == 0)
-                                                                       {
-                                                                               fs.Close();
-                                                                               return null;
-                                                                       }
-                                                                       return fs;
-                                                               }
-                                                               return null;
-                                                       case AssemblyRefTable.Index:
-                                                               Assembly asm = info.ReferencedAssembly;
-                                                               if (asm.__IsMissing)
-                                                               {
-                                                                       return null;
-                                                               }
-                                                               return asm.GetManifestResourceStream(resourceName);
-                                                       default:
-                                                               throw new BadImageFormatException();
-                                               }
-                                       }
-                                       SeekRVA((int)cliHeader.Resources.VirtualAddress + ManifestResource.records[i].Offset);
-                                       BinaryReader br = new BinaryReader(stream);
-                                       int length = br.ReadInt32();
-                                       return new MemoryStream(br.ReadBytes(length));
-                               }
-                       }
-                       return null;
-               }
-
-               public override AssemblyName[] __GetReferencedAssemblies()
-               {
-                       List<AssemblyName> list = new List<AssemblyName>();
-                       for (int i = 0; i < AssemblyRef.records.Length; i++)
-                       {
-                               AssemblyName name = new AssemblyName();
-                               name.Name = GetString(AssemblyRef.records[i].Name);
-                               name.Version = new Version(
-                                       AssemblyRef.records[i].MajorVersion,
-                                       AssemblyRef.records[i].MinorVersion,
-                                       AssemblyRef.records[i].BuildNumber,
-                                       AssemblyRef.records[i].RevisionNumber);
-                               if (AssemblyRef.records[i].PublicKeyOrToken != 0)
-                               {
-                                       byte[] keyOrToken = GetBlobCopy(AssemblyRef.records[i].PublicKeyOrToken);
-                                       const int PublicKey = 0x0001;
-                                       if ((AssemblyRef.records[i].Flags & PublicKey) != 0)
-                                       {
-                                               name.SetPublicKey(keyOrToken);
-                                       }
-                                       else
-                                       {
-                                               name.SetPublicKeyToken(keyOrToken);
-                                       }
-                               }
-                               else
-                               {
-                                       name.SetPublicKeyToken(Empty<byte>.Array);
-                               }
-                               if (AssemblyRef.records[i].Culture != 0)
-                               {
-                                       name.Culture = GetString(AssemblyRef.records[i].Culture);
-                               }
-                               else
-                               {
-                                       name.Culture = "";
-                               }
-                               if (AssemblyRef.records[i].HashValue != 0)
-                               {
-                                       name.hash = GetBlobCopy(AssemblyRef.records[i].HashValue);
-                               }
-                               name.Flags = (AssemblyNameFlags)AssemblyRef.records[i].Flags;
-                               list.Add(name);
-                       }
-                       return list.ToArray();
-               }
-
-               public override void __ResolveReferencedAssemblies(Assembly[] assemblies)
-               {
-                       if (assemblyRefs == null)
-                       {
-                               assemblyRefs = new Assembly[AssemblyRef.RowCount];
-                       }
-                       for (int i = 0; i < assemblies.Length; i++)
-                       {
-                               if (assemblyRefs[i] == null)
-                               {
-                                       assemblyRefs[i] = assemblies[i];
-                               }
-                       }
-               }
-
-               public override string[] __GetReferencedModules()
-               {
-                       string[] arr = new string[this.ModuleRef.RowCount];
-                       for (int i = 0; i < arr.Length; i++)
-                       {
-                               arr[i] = GetString(this.ModuleRef.records[i]);
-                       }
-                       return arr;
-               }
-
-               public override Type[] __GetReferencedTypes()
-               {
-                       Type[] arr = new Type[this.TypeRef.RowCount];
-                       for (int i = 0; i < arr.Length; i++)
-                       {
-                               arr[i] = ResolveType((TypeRefTable.Index << 24) + i + 1);
-                       }
-                       return arr;
-               }
-
-               public override Type[] __GetExportedTypes()
-               {
-                       Type[] arr = new Type[this.ExportedType.RowCount];
-                       for (int i = 0; i < arr.Length; i++)
-                       {
-                               arr[i] = ResolveExportedType(i);
-                       }
-                       return arr;
-               }
-
-               private Type ResolveExportedType(int index)
-               {
-                       TypeName typeName = GetTypeName(ExportedType.records[index].TypeNamespace, ExportedType.records[index].TypeName);
-                       int implementation = ExportedType.records[index].Implementation;
-                       int token = ExportedType.records[index].TypeDefId;
-                       int flags = ExportedType.records[index].Flags;
-                       switch (implementation >> 24)
-                       {
-                               case AssemblyRefTable.Index:
-                                       return ResolveAssemblyRef((implementation & 0xFFFFFF) - 1).ResolveType(typeName).SetMetadataTokenForMissing(token, flags);
-                               case ExportedTypeTable.Index:
-                                       return ResolveExportedType((implementation & 0xFFFFFF) - 1).ResolveNestedType(typeName).SetMetadataTokenForMissing(token, flags);
-                               case FileTable.Index:
-                                       Module module = assembly.GetModule(GetString(File.records[(implementation & 0xFFFFFF) - 1].Name));
-                                       return module.FindType(typeName) ?? module.universe.GetMissingTypeOrThrow(module, null, typeName).SetMetadataTokenForMissing(token, flags);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal override Type GetModuleType()
-               {
-                       PopulateTypeDef();
-                       return moduleType;
-               }
-
-               public override string __ImageRuntimeVersion
-               {
-                       get { return imageRuntimeVersion; }
-               }
-
-               public override int MDStreamVersion
-               {
-                       get { return metadataStreamVersion; }
-               }
-
-               public override void __GetDataDirectoryEntry(int index, out int rva, out int length)
-               {
-                       peFile.GetDataDirectoryEntry(index, out rva, out length);
-               }
-
-               public override long __RelativeVirtualAddressToFileOffset(int rva)
-               {
-                       return peFile.RvaToFileOffset((uint)rva);
-               }
-
-               public override bool __GetSectionInfo(int rva, out string name, out int characteristics)
-               {
-                       return peFile.GetSectionInfo(rva, out name, out characteristics);
-               }
-
-               public override int __ReadDataFromRVA(int rva, byte[] data, int offset, int length)
-               {
-                       SeekRVA(rva);
-                       int totalBytesRead = 0;
-                       while (length > 0)
-                       {
-                               int read = stream.Read(data, offset, length);
-                               if (read == 0)
-                               {
-                                       // C++ assemblies can have fields that have an RVA that lies outside of the file
-                                       break;
-                               }
-                               offset += read;
-                               length -= read;
-                               totalBytesRead += read;
-                       }
-                       return totalBytesRead;
-               }
-
-               public override void GetPEKind(out PortableExecutableKinds peKind, out ImageFileMachine machine)
-               {
-                       peKind = 0;
-                       if ((cliHeader.Flags & CliHeader.COMIMAGE_FLAGS_ILONLY) != 0)
-                       {
-                               peKind |= PortableExecutableKinds.ILOnly;
-                       }
-                       switch (cliHeader.Flags & (CliHeader.COMIMAGE_FLAGS_32BITREQUIRED | CliHeader.COMIMAGE_FLAGS_32BITPREFERRED))
-                       {
-                               case CliHeader.COMIMAGE_FLAGS_32BITREQUIRED:
-                                       peKind |= PortableExecutableKinds.Required32Bit;
-                                       break;
-                               case CliHeader.COMIMAGE_FLAGS_32BITREQUIRED | CliHeader.COMIMAGE_FLAGS_32BITPREFERRED:
-                                       peKind |= PortableExecutableKinds.Preferred32Bit;
-                                       break;
-                               default:
-                                       // COMIMAGE_FLAGS_32BITPREFERRED by itself is illegal, so we ignore it
-                                       // (not setting any flag is ok)
-                                       break;
-                       }
-                       if (peFile.OptionalHeader.Magic == IMAGE_OPTIONAL_HEADER.IMAGE_NT_OPTIONAL_HDR64_MAGIC)
-                       {
-                               peKind |= PortableExecutableKinds.PE32Plus;
-                       }
-
-                       machine = (ImageFileMachine)peFile.FileHeader.Machine;
-               }
-
-               public override int __Subsystem
-               {
-                       get { return peFile.OptionalHeader.Subsystem; }
-               }
-
-               public override IList<CustomAttributeData> __GetPlaceholderAssemblyCustomAttributes(bool multiple, bool security)
-               {
-                       TypeName typeName;
-                       switch ((multiple ? 1 : 0) + (security ? 2 : 0))
-                       {
-                               case 0:
-                                       typeName = new TypeName("System.Runtime.CompilerServices", "AssemblyAttributesGoHere");
-                                       break;
-                               case 1:
-                                       typeName = new TypeName("System.Runtime.CompilerServices", "AssemblyAttributesGoHereM");
-                                       break;
-                               case 2:
-                                       typeName = new TypeName("System.Runtime.CompilerServices", "AssemblyAttributesGoHereS");
-                                       break;
-                               case 3:
-                               default:
-                                       typeName = new TypeName("System.Runtime.CompilerServices", "AssemblyAttributesGoHereSM");
-                                       break;
-                       }
-                       List<CustomAttributeData> list = new List<CustomAttributeData>();
-                       for (int i = 0; i < CustomAttribute.records.Length; i++)
-                       {
-                               if ((CustomAttribute.records[i].Parent >> 24) == TypeRefTable.Index)
-                               {
-                                       int index = (CustomAttribute.records[i].Parent & 0xFFFFFF) - 1;
-                                       if (typeName == GetTypeName(TypeRef.records[index].TypeNameSpace, TypeRef.records[index].TypeName))
-                                       {
-                                               list.Add(new CustomAttributeData(this, i));
-                                       }
-                               }
-                       }
-                       return list;
-               }
-
-               internal override void Dispose()
-               {
-                       stream.Close();
-               }
-
-               internal override void ExportTypes(int fileToken, IKVM.Reflection.Emit.ModuleBuilder manifestModule)
-               {
-                       PopulateTypeDef();
-                       manifestModule.ExportTypes(typeDefs, fileToken);
-               }
-
-               protected override long GetImageBaseImpl()
-               {
-                       return (long)peFile.OptionalHeader.ImageBase;
-               }
-
-               protected override long GetStackReserveImpl()
-               {
-                       return (long)peFile.OptionalHeader.SizeOfStackReserve;
-               }
-
-               protected override int GetFileAlignmentImpl()
-               {
-                       return (int)peFile.OptionalHeader.FileAlignment;
-               }
-
-               protected override DllCharacteristics GetDllCharacteristicsImpl()
-               {
-                       return (DllCharacteristics)peFile.OptionalHeader.DllCharacteristics;
-               }
-
-               public override int __EntryPointRVA
-               {
-                       get { return (cliHeader.Flags & CliHeader.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT) != 0 ? (int)cliHeader.EntryPointToken : 0; }
-               }
-
-               public override int __EntryPointToken
-               {
-                       get { return (cliHeader.Flags & CliHeader.COMIMAGE_FLAGS_NATIVE_ENTRYPOINT) == 0 ? (int)cliHeader.EntryPointToken : 0; }
-               }
-
-               public override System.Security.Cryptography.X509Certificates.X509Certificate GetSignerCertificate()
-               {
-                       return Authenticode.GetSignerCertificate(stream);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/PEReader.cs b/mcs/class/IKVM.Reflection/Reader/PEReader.cs
deleted file mode 100644 (file)
index 24152ce..0000000
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
-  Copyright (C) 2009 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using BYTE = System.Byte;
-using WORD = System.UInt16;
-using DWORD = System.UInt32;
-using ULONGLONG = System.UInt64;
-using System.IO;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class MSDOS_HEADER
-       {
-               internal const WORD MAGIC_MZ = 0x5A4D;
-
-               internal WORD signature;        // 'MZ'
-               // skip 58 bytes
-               internal DWORD peSignatureOffset;
-       }
-
-       sealed class IMAGE_NT_HEADERS
-       {
-               public const DWORD MAGIC_SIGNATURE = 0x00004550;        // "PE\0\0"
-
-               public DWORD Signature;
-               public IMAGE_FILE_HEADER FileHeader = new IMAGE_FILE_HEADER();
-               public IMAGE_OPTIONAL_HEADER OptionalHeader = new IMAGE_OPTIONAL_HEADER();
-
-               internal void Read(BinaryReader br)
-               {
-                       Signature = br.ReadUInt32();
-                       if (Signature != IMAGE_NT_HEADERS.MAGIC_SIGNATURE)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       FileHeader.Read(br);
-                       OptionalHeader.Read(br);
-               }
-       }
-
-       sealed class IMAGE_FILE_HEADER
-       {
-               public const WORD IMAGE_FILE_MACHINE_I386 = 0x014c;
-               public const WORD IMAGE_FILE_MACHINE_IA64 = 0x0200;
-               public const WORD IMAGE_FILE_MACHINE_AMD64 = 0x8664;
-
-               public const WORD IMAGE_FILE_32BIT_MACHINE = 0x0100;
-               public const WORD IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002;
-               public const WORD IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020;
-               public const WORD IMAGE_FILE_DLL = 0x2000;
-
-               public WORD Machine;
-               public WORD NumberOfSections;
-               public DWORD TimeDateStamp;
-               public DWORD PointerToSymbolTable;
-               public DWORD NumberOfSymbols;
-               public WORD SizeOfOptionalHeader;
-               public WORD Characteristics;
-
-               internal void Read(BinaryReader br)
-               {
-                       Machine = br.ReadUInt16();
-                       NumberOfSections = br.ReadUInt16();
-                       TimeDateStamp = br.ReadUInt32();
-                       PointerToSymbolTable = br.ReadUInt32();
-                       NumberOfSymbols = br.ReadUInt32();
-                       SizeOfOptionalHeader = br.ReadUInt16();
-                       Characteristics = br.ReadUInt16();
-               }
-       }
-
-       sealed class IMAGE_OPTIONAL_HEADER
-       {
-               public const WORD IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b;
-               public const WORD IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b;
-
-               public const WORD IMAGE_SUBSYSTEM_WINDOWS_GUI = 2;
-               public const WORD IMAGE_SUBSYSTEM_WINDOWS_CUI = 3;
-
-               public WORD Magic;
-               public BYTE MajorLinkerVersion;
-               public BYTE MinorLinkerVersion;
-               public DWORD SizeOfCode;
-               public DWORD SizeOfInitializedData;
-               public DWORD SizeOfUninitializedData;
-               public DWORD AddressOfEntryPoint;
-               public DWORD BaseOfCode;
-               public DWORD BaseOfData;
-               public ULONGLONG ImageBase;
-               public DWORD SectionAlignment;
-               public DWORD FileAlignment;
-               public WORD MajorOperatingSystemVersion;
-               public WORD MinorOperatingSystemVersion;
-               public WORD MajorImageVersion;
-               public WORD MinorImageVersion;
-               public WORD MajorSubsystemVersion;
-               public WORD MinorSubsystemVersion;
-               public DWORD Win32VersionValue;
-               public DWORD SizeOfImage;
-               public DWORD SizeOfHeaders;
-               public DWORD CheckSum;
-               public WORD Subsystem;
-               public WORD DllCharacteristics;
-               public ULONGLONG SizeOfStackReserve;
-               public ULONGLONG SizeOfStackCommit;
-               public ULONGLONG SizeOfHeapReserve;
-               public ULONGLONG SizeOfHeapCommit;
-               public DWORD LoaderFlags;
-               public DWORD NumberOfRvaAndSizes;
-               public IMAGE_DATA_DIRECTORY[] DataDirectory;
-
-               internal void Read(BinaryReader br)
-               {
-                       Magic = br.ReadUInt16();
-                       if (Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC && Magic != IMAGE_NT_OPTIONAL_HDR64_MAGIC)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       MajorLinkerVersion = br.ReadByte();
-                       MinorLinkerVersion = br.ReadByte();
-                       SizeOfCode = br.ReadUInt32();
-                       SizeOfInitializedData = br.ReadUInt32();
-                       SizeOfUninitializedData = br.ReadUInt32();
-                       AddressOfEntryPoint = br.ReadUInt32();
-                       BaseOfCode = br.ReadUInt32();
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               BaseOfData = br.ReadUInt32();
-                               ImageBase = br.ReadUInt32();
-                       }
-                       else
-                       {
-                               ImageBase = br.ReadUInt64();
-                       }
-                       SectionAlignment = br.ReadUInt32();
-                       FileAlignment = br.ReadUInt32();
-                       MajorOperatingSystemVersion = br.ReadUInt16();
-                       MinorOperatingSystemVersion = br.ReadUInt16();
-                       MajorImageVersion = br.ReadUInt16();
-                       MinorImageVersion = br.ReadUInt16();
-                       MajorSubsystemVersion = br.ReadUInt16();
-                       MinorSubsystemVersion = br.ReadUInt16();
-                       Win32VersionValue = br.ReadUInt32();
-                       SizeOfImage = br.ReadUInt32();
-                       SizeOfHeaders = br.ReadUInt32();
-                       CheckSum = br.ReadUInt32();
-                       Subsystem = br.ReadUInt16();
-                       DllCharacteristics = br.ReadUInt16();
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               SizeOfStackReserve = br.ReadUInt32();
-                               SizeOfStackCommit = br.ReadUInt32();
-                               SizeOfHeapReserve = br.ReadUInt32();
-                               SizeOfHeapCommit = br.ReadUInt32();
-                       }
-                       else
-                       {
-                               SizeOfStackReserve = br.ReadUInt64();
-                               SizeOfStackCommit = br.ReadUInt64();
-                               SizeOfHeapReserve = br.ReadUInt64();
-                               SizeOfHeapCommit = br.ReadUInt64();
-                       }
-                       LoaderFlags = br.ReadUInt32();
-                       NumberOfRvaAndSizes = br.ReadUInt32();
-                       DataDirectory = new IMAGE_DATA_DIRECTORY[NumberOfRvaAndSizes];
-                       for (uint i = 0; i < NumberOfRvaAndSizes; i++)
-                       {
-                               DataDirectory[i] = new IMAGE_DATA_DIRECTORY();
-                               DataDirectory[i].Read(br);
-                       }
-               }
-       }
-
-       struct IMAGE_DATA_DIRECTORY
-       {
-               public DWORD VirtualAddress;
-               public DWORD Size;
-
-               internal void Read(BinaryReader br)
-               {
-                       VirtualAddress = br.ReadUInt32();
-                       Size = br.ReadUInt32();
-               }
-       }
-
-       class SectionHeader
-       {
-               public const DWORD IMAGE_SCN_CNT_CODE = 0x00000020;
-               public const DWORD IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040;
-               public const DWORD IMAGE_SCN_MEM_DISCARDABLE = 0x02000000;
-               public const DWORD IMAGE_SCN_MEM_EXECUTE = 0x20000000;
-               public const DWORD IMAGE_SCN_MEM_READ = 0x40000000;
-               public const DWORD IMAGE_SCN_MEM_WRITE = 0x80000000;
-
-               public string Name;             // 8 byte UTF8 encoded 0-padded
-               public DWORD VirtualSize;
-               public DWORD VirtualAddress;
-               public DWORD SizeOfRawData;
-               public DWORD PointerToRawData;
-               public DWORD PointerToRelocations;
-               public DWORD PointerToLinenumbers;
-               public WORD NumberOfRelocations;
-               public WORD NumberOfLinenumbers;
-               public DWORD Characteristics;
-
-               internal void Read(BinaryReader br)
-               {
-                       char[] name = new char[8];
-                       int len = 8;
-                       for (int i = 0; i < 8; i++)
-                       {
-                               byte b = br.ReadByte();
-                               name[i] = (char)b;
-                               if (b == 0 && len == 8)
-                               {
-                                       len = i;
-                               }
-                       }
-                       Name = new String(name, 0, len);
-                       VirtualSize = br.ReadUInt32();
-                       VirtualAddress = br.ReadUInt32();
-                       SizeOfRawData = br.ReadUInt32();
-                       PointerToRawData = br.ReadUInt32();
-                       PointerToRelocations = br.ReadUInt32();
-                       PointerToLinenumbers = br.ReadUInt32();
-                       NumberOfRelocations = br.ReadUInt16();
-                       NumberOfLinenumbers = br.ReadUInt16();
-                       Characteristics = br.ReadUInt32();
-               }
-       }
-
-       sealed class PEReader
-       {
-               private MSDOS_HEADER msdos = new MSDOS_HEADER();
-               private IMAGE_NT_HEADERS headers = new IMAGE_NT_HEADERS();
-               private SectionHeader[] sections;
-
-               internal void Read(BinaryReader br)
-               {
-                       msdos.signature = br.ReadUInt16();
-                       br.BaseStream.Seek(58, SeekOrigin.Current);
-                       msdos.peSignatureOffset = br.ReadUInt32();
-
-                       if (msdos.signature != MSDOS_HEADER.MAGIC_MZ)
-                       {
-                               throw new BadImageFormatException();
-                       }
-
-                       br.BaseStream.Seek(msdos.peSignatureOffset, SeekOrigin.Begin);
-                       headers.Read(br);
-                       sections = new SectionHeader[headers.FileHeader.NumberOfSections];
-                       for (int i = 0; i < sections.Length; i++)
-                       {
-                               sections[i] = new SectionHeader();
-                               sections[i].Read(br);
-                       }
-               }
-
-               internal IMAGE_FILE_HEADER FileHeader
-               {
-                       get { return headers.FileHeader; }
-               }
-
-               internal IMAGE_OPTIONAL_HEADER OptionalHeader
-               {
-                       get { return headers.OptionalHeader; }
-               }
-
-               internal DWORD GetComDescriptorVirtualAddress()
-               {
-                       return headers.OptionalHeader.DataDirectory[14].VirtualAddress;
-               }
-
-               internal void GetDataDirectoryEntry(int index, out int rva, out int length)
-               {
-                       rva = (int)headers.OptionalHeader.DataDirectory[index].VirtualAddress;
-                       length = (int)headers.OptionalHeader.DataDirectory[index].Size;
-               }
-
-               internal long RvaToFileOffset(DWORD rva)
-               {
-                       for (int i = 0; i < sections.Length; i++)
-                       {
-                               if (rva >= sections[i].VirtualAddress && rva < sections[i].VirtualAddress + sections[i].VirtualSize)
-                               {
-                                       return sections[i].PointerToRawData + rva - sections[i].VirtualAddress;
-                               }
-                       }
-                       throw new BadImageFormatException();
-               }
-
-               internal bool GetSectionInfo(int rva, out string name, out int characteristics)
-               {
-                       for (int i = 0; i < sections.Length; i++)
-                       {
-                               if (rva >= sections[i].VirtualAddress && rva < sections[i].VirtualAddress + sections[i].VirtualSize)
-                               {
-                                       name = sections[i].Name;
-                                       characteristics = (int)sections[i].Characteristics;
-                                       return true;
-                               }
-                       }
-                       name = null;
-                       characteristics = 0;
-                       return false;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/PropertyInfoImpl.cs b/mcs/class/IKVM.Reflection/Reader/PropertyInfoImpl.cs
deleted file mode 100644 (file)
index 120b839..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class PropertyInfoImpl : PropertyInfo
-       {
-               private readonly ModuleReader module;
-               private readonly Type declaringType;
-               private readonly int index;
-               private PropertySignature sig;
-               private bool isPublic;
-               private bool isNonPrivate;
-               private bool isStatic;
-               private bool flagsCached;
-
-               internal PropertyInfoImpl(ModuleReader module, Type declaringType, int index)
-               {
-                       this.module = module;
-                       this.declaringType = declaringType;
-                       this.index = index;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       PropertyInfoImpl other = obj as PropertyInfoImpl;
-                       return other != null && other.DeclaringType == declaringType && other.index == index;
-               }
-
-               public override int GetHashCode()
-               {
-                       return declaringType.GetHashCode() * 77 + index;
-               }
-
-               internal override PropertySignature PropertySignature
-               {
-                       get
-                       {
-                               if (sig == null)
-                               {
-                                       sig = PropertySignature.ReadSig(module, module.GetBlob(module.Property.records[index].Type), declaringType);
-                               }
-                               return sig;
-                       }
-               }
-
-               public override PropertyAttributes Attributes
-               {
-                       get { return (PropertyAttributes)module.Property.records[index].Flags; }
-               }
-
-               public override object GetRawConstantValue()
-               {
-                       return module.Constant.GetRawConstantValue(module, this.MetadataToken);
-               }
-
-               public override bool CanRead
-               {
-                       get { return GetGetMethod(true) != null; }
-               }
-
-               public override bool CanWrite
-               {
-                       get { return GetSetMethod(true) != null; }
-               }
-
-               public override MethodInfo GetGetMethod(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Getter);
-               }
-
-               public override MethodInfo GetSetMethod(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethod(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Setter);
-               }
-
-               public override MethodInfo[] GetAccessors(bool nonPublic)
-               {
-                       return module.MethodSemantics.GetMethods(module, this.MetadataToken, nonPublic, MethodSemanticsTable.Getter | MethodSemanticsTable.Setter | MethodSemanticsTable.Other);
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return declaringType; }
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (PropertyTable.Index << 24) + index + 1; }
-               }
-
-               public override string Name
-               {
-                       get { return module.GetString(module.Property.records[index].Name); }
-               }
-
-               internal override bool IsPublic
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isPublic;
-                       }
-               }
-
-               internal override bool IsNonPrivate
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isNonPrivate;
-                       }
-               }
-
-               internal override bool IsStatic
-               {
-                       get
-                       {
-                               if (!flagsCached)
-                               {
-                                       ComputeFlags();
-                               }
-                               return isStatic;
-                       }
-               }
-
-               private void ComputeFlags()
-               {
-                       module.MethodSemantics.ComputeFlags(module, this.MetadataToken, out isPublic, out isNonPrivate, out isStatic);
-                       flagsCached = true;
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/ResourceModule.cs b/mcs/class/IKVM.Reflection/Reader/ResourceModule.cs
deleted file mode 100644 (file)
index 0113e47..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class ResourceModule : NonPEModule
-       {
-               private readonly ModuleReader manifest;
-               private readonly int index;
-               private readonly string location;
-
-               internal ResourceModule(ModuleReader manifest, int index, string location)
-                       : base(manifest.universe)
-               {
-                       this.manifest = manifest;
-                       this.index = index;
-                       this.location = location;
-               }
-
-               public override int MDStreamVersion
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public override bool IsResource()
-               {
-                       return true;
-               }
-
-               public override Assembly Assembly
-               {
-                       get { return manifest.Assembly; }
-               }
-
-               public override string FullyQualifiedName
-               {
-                       get { return location ?? "<Unknown>"; }
-               }
-
-               public override string Name
-               {
-                       get { return location == null ? "<Unknown>" : System.IO.Path.GetFileName(location); }
-               }
-
-               public override string ScopeName
-               {
-                       get { return manifest.GetString(manifest.File.records[index].Name); }
-               }
-
-               public override Guid ModuleVersionId
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public override byte[] __ModuleHash
-               {
-                       get
-                       {
-                               int blob = manifest.File.records[index].HashValue;
-                               return blob == 0 ? Empty<byte>.Array : manifest.GetBlobCopy(blob);
-                       }
-               }
-
-               internal override Type FindType(TypeName typeName)
-               {
-                       return null;
-               }
-
-               internal override Type FindTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       return null;
-               }
-
-               internal override void GetTypesImpl(List<Type> list)
-               {
-               }
-
-               protected override Exception ArgumentOutOfRangeException()
-               {
-                       return new NotSupportedException();
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs b/mcs/class/IKVM.Reflection/Reader/TypeDefImpl.cs
deleted file mode 100644 (file)
index e4a036d..0000000
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
-  Copyright (C) 2009-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Runtime.InteropServices;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Reader
-{
-       sealed class TypeDefImpl : TypeInfo
-       {
-               private readonly ModuleReader module;
-               private readonly int index;
-               private readonly string typeName;
-               private readonly string typeNamespace;
-               private Type[] typeArgs;
-
-               internal TypeDefImpl(ModuleReader module, int index)
-               {
-                       this.module = module;
-                       this.index = index;
-                       this.typeName = module.GetString(module.TypeDef.records[index].TypeName);
-                       this.typeNamespace = module.GetString(module.TypeDef.records[index].TypeNamespace);
-                       MarkEnumOrValueType(typeNamespace, typeName);
-               }
-
-               public override Type BaseType
-               {
-                       get
-                       {
-                               int extends = module.TypeDef.records[index].Extends;
-                               if ((extends & 0xFFFFFF) == 0)
-                               {
-                                       return null;
-                               }
-                               return module.ResolveType(extends, this);
-                       }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return (TypeAttributes)module.TypeDef.records[index].Flags; }
-               }
-
-               public override EventInfo[] __GetDeclaredEvents()
-               {
-                       foreach (int i in module.EventMap.Filter(this.MetadataToken))
-                       {
-                               int evt = module.EventMap.records[i].EventList - 1;
-                               int end = module.EventMap.records.Length > i + 1 ? module.EventMap.records[i + 1].EventList - 1 : module.Event.records.Length;
-                               EventInfo[] events = new EventInfo[end - evt];
-                               if (module.EventPtr.RowCount == 0)
-                               {
-                                       for (int j = 0; evt < end; evt++, j++)
-                                       {
-                                               events[j] = new EventInfoImpl(module, this, evt);
-                                       }
-                               }
-                               else
-                               {
-                                       for (int j = 0; evt < end; evt++, j++)
-                                       {
-                                               events[j] = new EventInfoImpl(module, this, module.EventPtr.records[evt] - 1);
-                                       }
-                               }
-                               return events;
-                       }
-                       return Empty<EventInfo>.Array;
-               }
-
-               public override FieldInfo[] __GetDeclaredFields()
-               {
-                       int field = module.TypeDef.records[index].FieldList - 1;
-                       int end = module.TypeDef.records.Length > index + 1 ? module.TypeDef.records[index + 1].FieldList - 1 : module.Field.records.Length;
-                       FieldInfo[] fields = new FieldInfo[end - field];
-                       if (module.FieldPtr.RowCount == 0)
-                       {
-                               for (int i = 0; field < end; i++, field++)
-                               {
-                                       fields[i] = module.GetFieldAt(this, field);
-                               }
-                       }
-                       else
-                       {
-                               for (int i = 0; field < end; i++, field++)
-                               {
-                                       fields[i] = module.GetFieldAt(this, module.FieldPtr.records[field] - 1);
-                               }
-                       }
-                       return fields;
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       List<Type> list = null;
-                       foreach (int i in module.InterfaceImpl.Filter(this.MetadataToken))
-                       {
-                               if (list == null)
-                               {
-                                       list = new List<Type>();
-                               }
-                               list.Add(module.ResolveType(module.InterfaceImpl.records[i].Interface, this));
-                       }
-                       return Util.ToArray(list, Type.EmptyTypes);
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       int method = module.TypeDef.records[index].MethodList - 1;
-                       int end = module.TypeDef.records.Length > index + 1 ? module.TypeDef.records[index + 1].MethodList - 1 : module.MethodDef.records.Length;
-                       MethodBase[] methods = new MethodBase[end - method];
-                       if (module.MethodPtr.RowCount == 0)
-                       {
-                               for (int i = 0; method < end; method++, i++)
-                               {
-                                       methods[i] = module.GetMethodAt(this, method);
-                               }
-                       }
-                       else
-                       {
-                               for (int i = 0; method < end; method++, i++)
-                               {
-                                       methods[i] = module.GetMethodAt(this, module.MethodPtr.records[method] - 1);
-                               }
-                       }
-                       return methods;
-               }
-
-               public override __MethodImplMap __GetMethodImplMap()
-               {
-                       PopulateGenericArguments();
-                       List<MethodInfo> bodies = new List<MethodInfo>();
-                       List<List<MethodInfo>> declarations = new List<List<MethodInfo>>();
-                       foreach (int i in module.MethodImpl.Filter(this.MetadataToken))
-                       {
-                               MethodInfo body = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodBody, typeArgs, null);
-                               int index = bodies.IndexOf(body);
-                               if (index == -1)
-                               {
-                                       index = bodies.Count;
-                                       bodies.Add(body);
-                                       declarations.Add(new List<MethodInfo>());
-                               }
-                               MethodInfo declaration = (MethodInfo)module.ResolveMethod(module.MethodImpl.records[i].MethodDeclaration, typeArgs, null);
-                               declarations[index].Add(declaration);
-                       }
-                       __MethodImplMap map = new __MethodImplMap();
-                       map.TargetType = this;
-                       map.MethodBodies = bodies.ToArray();
-                       map.MethodDeclarations = new MethodInfo[declarations.Count][];
-                       for (int i = 0; i < map.MethodDeclarations.Length; i++)
-                       {
-                               map.MethodDeclarations[i] = declarations[i].ToArray();
-                       }
-                       return map;
-               }
-
-               public override Type[] __GetDeclaredTypes()
-               {
-                       int token = this.MetadataToken;
-                       List<Type> list = new List<Type>();
-                       // note that the NestedClass table is sorted on NestedClass, so we can't use binary search
-                       for (int i = 0; i < module.NestedClass.records.Length; i++)
-                       {
-                               if (module.NestedClass.records[i].EnclosingClass == token)
-                               {
-                                       list.Add(module.ResolveType(module.NestedClass.records[i].NestedClass));
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public override PropertyInfo[] __GetDeclaredProperties()
-               {
-                       foreach (int i in module.PropertyMap.Filter(this.MetadataToken))
-                       {
-                               int property = module.PropertyMap.records[i].PropertyList - 1;
-                               int end = module.PropertyMap.records.Length > i + 1 ? module.PropertyMap.records[i + 1].PropertyList - 1 : module.Property.records.Length;
-                               PropertyInfo[] properties = new PropertyInfo[end - property];
-                               if (module.PropertyPtr.RowCount == 0)
-                               {
-                                       for (int j = 0; property < end; property++, j++)
-                                       {
-                                               properties[j] = new PropertyInfoImpl(module, this, property);
-                                       }
-                               }
-                               else
-                               {
-                                       for (int j = 0; property < end; property++, j++)
-                                       {
-                                               properties[j] = new PropertyInfoImpl(module, this, module.PropertyPtr.records[property] - 1);
-                                       }
-                               }
-                               return properties;
-                       }
-                       return Empty<PropertyInfo>.Array;
-               }
-
-               public override string __Name
-               {
-                       get { return typeName; }
-               }
-
-               public override string __Namespace
-               {
-                       get { return typeNamespace; }
-               }
-
-               public override string Name
-               {
-                       get { return TypeNameParser.Escape(typeName); }
-               }
-
-               public override string FullName
-               {
-                       get { return GetFullName(); }
-               }
-
-               public override int MetadataToken
-               {
-                       get { return (TypeDefTable.Index << 24) + index + 1; }
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       PopulateGenericArguments();
-                       return Util.Copy(typeArgs);
-               }
-
-               private void PopulateGenericArguments()
-               {
-                       if (typeArgs == null)
-                       {
-                               int token = this.MetadataToken;
-                               int first = module.GenericParam.FindFirstByOwner(token);
-                               if (first == -1)
-                               {
-                                       typeArgs = Type.EmptyTypes;
-                               }
-                               else
-                               {
-                                       List<Type> list = new List<Type>();
-                                       int len = module.GenericParam.records.Length;
-                                       for (int i = first; i < len && module.GenericParam.records[i].Owner == token; i++)
-                                       {
-                                               list.Add(new GenericTypeParameter(module, i));
-                                       }
-                                       typeArgs = list.ToArray();
-                               }
-                       }
-               }
-
-               internal override Type GetGenericTypeArgument(int index)
-               {
-                       PopulateGenericArguments();
-                       return typeArgs[index];
-               }
-
-               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       PopulateGenericArguments();
-                       return new CustomModifiers[typeArgs.Length];
-               }
-
-               public override bool IsGenericType
-               {
-                       get { return IsGenericTypeDefinition; }
-               }
-
-               public override bool IsGenericTypeDefinition
-               {
-                       get
-                       {
-                               if ((typeFlags & (TypeFlags.IsGenericTypeDefinition | TypeFlags.NotGenericTypeDefinition)) == 0)
-                               {
-                                       typeFlags |= module.GenericParam.FindFirstByOwner(this.MetadataToken) == -1
-                                               ? TypeFlags.NotGenericTypeDefinition
-                                               : TypeFlags.IsGenericTypeDefinition;
-                               }
-                               return (typeFlags & TypeFlags.IsGenericTypeDefinition) != 0;
-                       }
-               }
-
-               public override Type GetGenericTypeDefinition()
-               {
-                       if (IsGenericTypeDefinition)
-                       {
-                               return this;
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               public override string ToString()
-               {
-                       StringBuilder sb = new StringBuilder(this.FullName);
-                       string sep = "[";
-                       foreach (Type arg in GetGenericArguments())
-                       {
-                               sb.Append(sep);
-                               sb.Append(arg);
-                               sep = ",";
-                       }
-                       if (sep != "[")
-                       {
-                               sb.Append(']');
-                       }
-                       return sb.ToString();
-               }
-
-               internal bool IsNestedByFlags
-               {
-                       get { return (this.Attributes & TypeAttributes.VisibilityMask & ~TypeAttributes.Public) != 0; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get
-                       {
-                               // note that we cannot use Type.IsNested for this, because that calls DeclaringType
-                               if (!IsNestedByFlags)
-                               {
-                                       return null;
-                               }
-                               foreach (int i in module.NestedClass.Filter(this.MetadataToken))
-                               {
-                                       return module.ResolveType(module.NestedClass.records[i].EnclosingClass, null, null);
-                               }
-                               throw new InvalidOperationException();
-                       }
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute
-               {
-                       get
-                       {
-                               StructLayoutAttribute layout;
-                               switch (this.Attributes & TypeAttributes.LayoutMask)
-                               {
-                                       case TypeAttributes.AutoLayout:
-                                               layout = new StructLayoutAttribute(LayoutKind.Auto);
-                                               break;
-                                       case TypeAttributes.SequentialLayout:
-                                               layout = new StructLayoutAttribute(LayoutKind.Sequential);
-                                               break;
-                                       case TypeAttributes.ExplicitLayout:
-                                               layout = new StructLayoutAttribute(LayoutKind.Explicit);
-                                               break;
-                                       default:
-                                               throw new BadImageFormatException();
-                               }
-                               switch (this.Attributes & TypeAttributes.StringFormatMask)
-                               {
-                                       case TypeAttributes.AnsiClass:
-                                               layout.CharSet = CharSet.Ansi;
-                                               break;
-                                       case TypeAttributes.UnicodeClass:
-                                               layout.CharSet = CharSet.Unicode;
-                                               break;
-                                       case TypeAttributes.AutoClass:
-                                               layout.CharSet = CharSet.Auto;
-                                               break;
-                                       default:
-                                               layout.CharSet = CharSet.None;
-                                               break;
-                               }
-                               if (!__GetLayout(out layout.Pack, out layout.Size))
-                               {
-                                       // compatibility with System.Reflection
-                                       layout.Pack = 8;
-                               }
-                               return layout;
-                       }
-               }
-
-               public override bool __GetLayout(out int packingSize, out int typeSize)
-               {
-                       foreach (int i in module.ClassLayout.Filter(this.MetadataToken))
-                       {
-                               packingSize = module.ClassLayout.records[i].PackingSize;
-                               typeSize = module.ClassLayout.records[i].ClassSize;
-                               return true;
-                       }
-                       packingSize = 0;
-                       typeSize = 0;
-                       return false;
-               }
-
-               public override Module Module
-               {
-                       get { return module; }
-               }
-
-               internal override bool IsModulePseudoType
-               {
-                       get { return index == 0; }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Signature.cs b/mcs/class/IKVM.Reflection/Signature.cs
deleted file mode 100644 (file)
index 35c9a65..0000000
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Text;
-using CallingConvention = System.Runtime.InteropServices.CallingConvention;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Writer;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection
-{
-       abstract class Signature
-       {
-               internal const byte DEFAULT = 0x00;
-               internal const byte VARARG = 0x05;
-               internal const byte GENERIC = 0x10;
-               internal const byte HASTHIS = 0x20;
-               internal const byte EXPLICITTHIS = 0x40;
-               internal const byte FIELD = 0x06;
-               internal const byte LOCAL_SIG = 0x07;
-               internal const byte PROPERTY = 0x08;
-               internal const byte GENERICINST = 0x0A;
-               internal const byte SENTINEL = 0x41;
-               internal const byte ELEMENT_TYPE_VOID = 0x01;
-               internal const byte ELEMENT_TYPE_BOOLEAN = 0x02;
-               internal const byte ELEMENT_TYPE_CHAR = 0x03;
-               internal const byte ELEMENT_TYPE_I1 = 0x04;
-               internal const byte ELEMENT_TYPE_U1 = 0x05;
-               internal const byte ELEMENT_TYPE_I2 = 0x06;
-               internal const byte ELEMENT_TYPE_U2 = 0x07;
-               internal const byte ELEMENT_TYPE_I4 = 0x08;
-               internal const byte ELEMENT_TYPE_U4 = 0x09;
-               internal const byte ELEMENT_TYPE_I8 = 0x0a;
-               internal const byte ELEMENT_TYPE_U8 = 0x0b;
-               internal const byte ELEMENT_TYPE_R4 = 0x0c;
-               internal const byte ELEMENT_TYPE_R8 = 0x0d;
-               internal const byte ELEMENT_TYPE_STRING = 0x0e;
-               internal const byte ELEMENT_TYPE_PTR = 0x0f;
-               internal const byte ELEMENT_TYPE_BYREF = 0x10;
-               internal const byte ELEMENT_TYPE_VALUETYPE = 0x11;
-               internal const byte ELEMENT_TYPE_CLASS = 0x12;
-               internal const byte ELEMENT_TYPE_VAR = 0x13;
-               internal const byte ELEMENT_TYPE_ARRAY = 0x14;
-               internal const byte ELEMENT_TYPE_GENERICINST = 0x15;
-               internal const byte ELEMENT_TYPE_TYPEDBYREF = 0x16;
-               internal const byte ELEMENT_TYPE_I = 0x18;
-               internal const byte ELEMENT_TYPE_U = 0x19;
-               internal const byte ELEMENT_TYPE_FNPTR = 0x1b;
-               internal const byte ELEMENT_TYPE_OBJECT = 0x1c;
-               internal const byte ELEMENT_TYPE_SZARRAY = 0x1d;
-               internal const byte ELEMENT_TYPE_MVAR = 0x1e;
-               internal const byte ELEMENT_TYPE_CMOD_REQD = 0x1f;
-               internal const byte ELEMENT_TYPE_CMOD_OPT = 0x20;
-               internal const byte ELEMENT_TYPE_PINNED = 0x45;
-
-               internal abstract void WriteSig(ModuleBuilder module, ByteBuffer bb);
-
-               private static Type ReadGenericInst(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       Type type;
-                       switch (br.ReadByte())
-                       {
-                               case ELEMENT_TYPE_CLASS:
-                                       type = ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType();
-                                       break;
-                               case ELEMENT_TYPE_VALUETYPE:
-                                       type = ReadTypeDefOrRefEncoded(module, br, context).MarkValueType();
-                                       break;
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-                       if (!type.__IsMissing && !type.IsGenericTypeDefinition)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       int genArgCount = br.ReadCompressedUInt();
-                       Type[] args = new Type[genArgCount];
-                       CustomModifiers[] mods = null;
-                       for (int i = 0; i < genArgCount; i++)
-                       {
-                               // LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for genericinst, but C++ uses it, the verifier allows it and ildasm also supports it
-                               CustomModifiers cm = CustomModifiers.Read(module, br, context);
-                               if (!cm.IsEmpty)
-                               {
-                                       if (mods == null)
-                                       {
-                                               mods = new CustomModifiers[genArgCount];
-                                       }
-                                       mods[i] = cm;
-                               }
-                               args[i] = ReadType(module, br, context);
-                       }
-                       return GenericTypeInstance.Make(type, args, mods);
-               }
-
-               internal static Type ReadTypeSpec(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       // LAMESPEC a TypeSpec can contain custom modifiers (C++/CLI generates "newarr (TypeSpec with custom modifiers)")
-                       CustomModifiers.Skip(br);
-                       // LAMESPEC anything can be adorned by (useless) custom modifiers
-                       // also, VAR and MVAR are also used in TypeSpec (contrary to what the spec says)
-                       return ReadType(module, br, context);
-               }
-
-               private static Type ReadFunctionPointer(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       __StandAloneMethodSig sig = MethodSignature.ReadStandAloneMethodSig(module, br, context);
-                       if (module.universe.EnableFunctionPointers)
-                       {
-                               return FunctionPointerType.Make(module.universe, sig);
-                       }
-                       else
-                       {
-                               // by default, like .NET we return System.IntPtr here
-                               return module.universe.System_IntPtr;
-                       }
-               }
-
-               internal static Type[] ReadMethodSpec(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       if (br.ReadByte() != GENERICINST)
-                       {
-                               throw new BadImageFormatException();
-                       }
-                       Type[] args = new Type[br.ReadCompressedUInt()];
-                       for (int i = 0; i < args.Length; i++)
-                       {
-                               args[i] = ReadType(module, br, context);
-                       }
-                       return args;
-               }
-
-               private static int[] ReadArraySizes(ByteReader br)
-               {
-                       int num = br.ReadCompressedUInt();
-                       if (num == 0)
-                       {
-                               return null;
-                       }
-                       int[] arr = new int[num];
-                       for (int i = 0; i < num; i++)
-                       {
-                               arr[i] = br.ReadCompressedUInt();
-                       }
-                       return arr;
-               }
-
-               private static int[] ReadArrayBounds(ByteReader br)
-               {
-                       int num = br.ReadCompressedUInt();
-                       if (num == 0)
-                       {
-                               return null;
-                       }
-                       int[] arr = new int[num];
-                       for (int i = 0; i < num; i++)
-                       {
-                               arr[i] = br.ReadCompressedInt();
-                       }
-                       return arr;
-               }
-
-               private static Type ReadTypeOrVoid(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       if (br.PeekByte() == ELEMENT_TYPE_VOID)
-                       {
-                               br.ReadByte();
-                               return module.universe.System_Void;
-                       }
-                       else
-                       {
-                               return ReadType(module, br, context);
-                       }
-               }
-
-               // see ECMA 335 CLI spec June 2006 section 23.2.12 for this production
-               protected static Type ReadType(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       CustomModifiers mods;
-                       switch (br.ReadByte())
-                       {
-                               case ELEMENT_TYPE_CLASS:
-                                       return ReadTypeDefOrRefEncoded(module, br, context).MarkNotValueType();
-                               case ELEMENT_TYPE_VALUETYPE:
-                                       return ReadTypeDefOrRefEncoded(module, br, context).MarkValueType();
-                               case ELEMENT_TYPE_BOOLEAN:
-                                       return module.universe.System_Boolean;
-                               case ELEMENT_TYPE_CHAR:
-                                       return module.universe.System_Char;
-                               case ELEMENT_TYPE_I1:
-                                       return module.universe.System_SByte;
-                               case ELEMENT_TYPE_U1:
-                                       return module.universe.System_Byte;
-                               case ELEMENT_TYPE_I2:
-                                       return module.universe.System_Int16;
-                               case ELEMENT_TYPE_U2:
-                                       return module.universe.System_UInt16;
-                               case ELEMENT_TYPE_I4:
-                                       return module.universe.System_Int32;
-                               case ELEMENT_TYPE_U4:
-                                       return module.universe.System_UInt32;
-                               case ELEMENT_TYPE_I8:
-                                       return module.universe.System_Int64;
-                               case ELEMENT_TYPE_U8:
-                                       return module.universe.System_UInt64;
-                               case ELEMENT_TYPE_R4:
-                                       return module.universe.System_Single;
-                               case ELEMENT_TYPE_R8:
-                                       return module.universe.System_Double;
-                               case ELEMENT_TYPE_I:
-                                       return module.universe.System_IntPtr;
-                               case ELEMENT_TYPE_U:
-                                       return module.universe.System_UIntPtr;
-                               case ELEMENT_TYPE_STRING:
-                                       return module.universe.System_String;
-                               case ELEMENT_TYPE_OBJECT:
-                                       return module.universe.System_Object;
-                               case ELEMENT_TYPE_VAR:
-                                       return context.GetGenericTypeArgument(br.ReadCompressedUInt());
-                               case ELEMENT_TYPE_MVAR:
-                                       return context.GetGenericMethodArgument(br.ReadCompressedUInt());
-                               case ELEMENT_TYPE_GENERICINST:
-                                       return ReadGenericInst(module, br, context);
-                               case ELEMENT_TYPE_SZARRAY:
-                                       mods = CustomModifiers.Read(module, br, context);
-                                       return ReadType(module, br, context).__MakeArrayType(mods);
-                               case ELEMENT_TYPE_ARRAY:
-                                       mods = CustomModifiers.Read(module, br, context);
-                                       return ReadType(module, br, context).__MakeArrayType(br.ReadCompressedUInt(), ReadArraySizes(br), ReadArrayBounds(br), mods);
-                               case ELEMENT_TYPE_PTR:
-                                       mods = CustomModifiers.Read(module, br, context);
-                                       return ReadTypeOrVoid(module, br, context).__MakePointerType(mods);
-                               case ELEMENT_TYPE_FNPTR:
-                                       return ReadFunctionPointer(module, br, context);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal static void ReadLocalVarSig(ModuleReader module, ByteReader br, IGenericContext context, List<LocalVariableInfo> list)
-               {
-                       if (br.Length < 2 || br.ReadByte() != LOCAL_SIG)
-                       {
-                               throw new BadImageFormatException("Invalid local variable signature");
-                       }
-                       int count = br.ReadCompressedUInt();
-                       for (int i = 0; i < count; i++)
-                       {
-                               if (br.PeekByte() == ELEMENT_TYPE_TYPEDBYREF)
-                               {
-                                       br.ReadByte();
-                                       list.Add(new LocalVariableInfo(i, module.universe.System_TypedReference, false, new CustomModifiers()));
-                               }
-                               else
-                               {
-                                       CustomModifiers mods1 = CustomModifiers.Read(module, br, context);
-                                       bool pinned = false;
-                                       if (br.PeekByte() == ELEMENT_TYPE_PINNED)
-                                       {
-                                               br.ReadByte();
-                                               pinned = true;
-                                       }
-                                       CustomModifiers mods2 = CustomModifiers.Read(module, br, context);
-                                       Type type = ReadTypeOrByRef(module, br, context);
-                                       list.Add(new LocalVariableInfo(i, type, pinned, CustomModifiers.Combine(mods1, mods2)));
-                               }
-                       }
-               }
-
-               private static Type ReadTypeOrByRef(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       if (br.PeekByte() == ELEMENT_TYPE_BYREF)
-                       {
-                               br.ReadByte();
-                               // LAMESPEC it is allowed (by C++/CLI, ilasm and peverify) to have custom modifiers after the BYREF
-                               // (which makes sense, as it is analogous to pointers)
-                               CustomModifiers mods = CustomModifiers.Read(module, br, context);
-                               // C++/CLI generates void& local variables, so we need to use ReadTypeOrVoid here
-                               return ReadTypeOrVoid(module, br, context).__MakeByRefType(mods);
-                       }
-                       else
-                       {
-                               return ReadType(module, br, context);
-                       }
-               }
-
-               protected static Type ReadRetType(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       switch (br.PeekByte())
-                       {
-                               case ELEMENT_TYPE_VOID:
-                                       br.ReadByte();
-                                       return module.universe.System_Void;
-                               case ELEMENT_TYPE_TYPEDBYREF:
-                                       br.ReadByte();
-                                       return module.universe.System_TypedReference;
-                               default:
-                                       return ReadTypeOrByRef(module, br, context);
-                       }
-               }
-
-               protected static Type ReadParam(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       switch (br.PeekByte())
-                       {
-                               case ELEMENT_TYPE_TYPEDBYREF:
-                                       br.ReadByte();
-                                       return module.universe.System_TypedReference;
-                               default:
-                                       return ReadTypeOrByRef(module, br, context);
-                       }
-               }
-
-               protected static void WriteType(ModuleBuilder module, ByteBuffer bb, Type type)
-               {
-                       while (type.HasElementType)
-                       {
-                               if (type.__IsVector)
-                               {
-                                       bb.Write(ELEMENT_TYPE_SZARRAY);
-                               }
-                               else if (type.IsArray)
-                               {
-                                       int rank = type.GetArrayRank();
-                                       bb.Write(ELEMENT_TYPE_ARRAY);
-                                       // LAMESPEC the Type production (23.2.12) doesn't include CustomMod* for arrays, but the verifier allows it and ildasm also supports it
-                                       WriteCustomModifiers(module, bb, type.__GetCustomModifiers());
-                                       WriteType(module, bb, type.GetElementType());
-                                       bb.WriteCompressedUInt(rank);
-                                       int[] sizes = type.__GetArraySizes();
-                                       bb.WriteCompressedUInt(sizes.Length);
-                                       for (int i = 0; i < sizes.Length; i++)
-                                       {
-                                               bb.WriteCompressedUInt(sizes[i]);
-                                       }
-                                       int[] lobounds = type.__GetArrayLowerBounds();
-                                       bb.WriteCompressedUInt(lobounds.Length);
-                                       for (int i = 0; i < lobounds.Length; i++)
-                                       {
-                                               bb.WriteCompressedInt(lobounds[i]);
-                                       }
-                                       return;
-                               }
-                               else if (type.IsByRef)
-                               {
-                                       bb.Write(ELEMENT_TYPE_BYREF);
-                               }
-                               else if (type.IsPointer)
-                               {
-                                       bb.Write(ELEMENT_TYPE_PTR);
-                               }
-                               WriteCustomModifiers(module, bb, type.__GetCustomModifiers());
-                               type = type.GetElementType();
-                       }
-                       Universe u = module.universe;
-                       if (type == u.System_Void)
-                       {
-                               bb.Write(ELEMENT_TYPE_VOID);
-                       }
-                       else if (type == u.System_Int32)
-                       {
-                               bb.Write(ELEMENT_TYPE_I4);
-                       }
-                       else if (type == u.System_Boolean)
-                       {
-                               bb.Write(ELEMENT_TYPE_BOOLEAN);
-                       }
-                       else if (type == u.System_String)
-                       {
-                               bb.Write(ELEMENT_TYPE_STRING);
-                       }
-                       else if (type == u.System_Char)
-                       {
-                               bb.Write(ELEMENT_TYPE_CHAR);
-                       }
-                       else if (type == u.System_SByte)
-                       {
-                               bb.Write(ELEMENT_TYPE_I1);
-                       }
-                       else if (type == u.System_Byte)
-                       {
-                               bb.Write(ELEMENT_TYPE_U1);
-                       }
-                       else if (type == u.System_Int16)
-                       {
-                               bb.Write(ELEMENT_TYPE_I2);
-                       }
-                       else if (type == u.System_UInt16)
-                       {
-                               bb.Write(ELEMENT_TYPE_U2);
-                       }
-                       else if (type == u.System_UInt32)
-                       {
-                               bb.Write(ELEMENT_TYPE_U4);
-                       }
-                       else if (type == u.System_Int64)
-                       {
-                               bb.Write(ELEMENT_TYPE_I8);
-                       }
-                       else if (type == u.System_UInt64)
-                       {
-                               bb.Write(ELEMENT_TYPE_U8);
-                       }
-                       else if (type == u.System_Single)
-                       {
-                               bb.Write(ELEMENT_TYPE_R4);
-                       }
-                       else if (type == u.System_Double)
-                       {
-                               bb.Write(ELEMENT_TYPE_R8);
-                       }
-                       else if (type == u.System_IntPtr)
-                       {
-                               bb.Write(ELEMENT_TYPE_I);
-                       }
-                       else if (type == u.System_UIntPtr)
-                       {
-                               bb.Write(ELEMENT_TYPE_U);
-                       }
-                       else if (type == u.System_TypedReference)
-                       {
-                               bb.Write(ELEMENT_TYPE_TYPEDBYREF);
-                       }
-                       else if (type == u.System_Object)
-                       {
-                               bb.Write(ELEMENT_TYPE_OBJECT);
-                       }
-                       else if (type.IsGenericParameter)
-                       {
-                               if (type is UnboundGenericMethodParameter || type.DeclaringMethod != null)
-                               {
-                                       bb.Write(ELEMENT_TYPE_MVAR);
-                               }
-                               else
-                               {
-                                       bb.Write(ELEMENT_TYPE_VAR);
-                               }
-                               bb.WriteCompressedUInt(type.GenericParameterPosition);
-                       }
-                       else if (!type.__IsMissing && type.IsGenericType)
-                       {
-                               WriteGenericSignature(module, bb, type);
-                       }
-                       else if (type.__IsFunctionPointer)
-                       {
-                               bb.Write(ELEMENT_TYPE_FNPTR);
-                               WriteStandAloneMethodSig(module, bb, type.__MethodSignature);
-                       }
-                       else
-                       {
-                               if (type.IsValueType)
-                               {
-                                       bb.Write(ELEMENT_TYPE_VALUETYPE);
-                               }
-                               else
-                               {
-                                       bb.Write(ELEMENT_TYPE_CLASS);
-                               }
-                               bb.WriteTypeDefOrRefEncoded(module.GetTypeToken(type).Token);
-                       }
-               }
-
-               private static void WriteGenericSignature(ModuleBuilder module, ByteBuffer bb, Type type)
-               {
-                       Type[] typeArguments = type.GetGenericArguments();
-                       CustomModifiers[] customModifiers = type.__GetGenericArgumentsCustomModifiers();
-                       if (!type.IsGenericTypeDefinition)
-                       {
-                               type = type.GetGenericTypeDefinition();
-                       }
-                       bb.Write(ELEMENT_TYPE_GENERICINST);
-                       if (type.IsValueType)
-                       {
-                               bb.Write(ELEMENT_TYPE_VALUETYPE);
-                       }
-                       else
-                       {
-                               bb.Write(ELEMENT_TYPE_CLASS);
-                       }
-                       bb.WriteTypeDefOrRefEncoded(module.GetTypeToken(type).Token);
-                       bb.WriteCompressedUInt(typeArguments.Length);
-                       for (int i = 0; i < typeArguments.Length; i++)
-                       {
-                               WriteCustomModifiers(module, bb, customModifiers[i]);
-                               WriteType(module, bb, typeArguments[i]);
-                       }
-               }
-
-               protected static void WriteCustomModifiers(ModuleBuilder module, ByteBuffer bb, CustomModifiers modifiers)
-               {
-                       foreach (CustomModifiers.Entry entry in modifiers)
-                       {
-                               bb.Write(entry.IsRequired ? ELEMENT_TYPE_CMOD_REQD : ELEMENT_TYPE_CMOD_OPT);
-                               bb.WriteTypeDefOrRefEncoded(module.GetTypeTokenForMemberRef(entry.Type));
-                       }
-               }
-
-               internal static Type ReadTypeDefOrRefEncoded(ModuleReader module, ByteReader br, IGenericContext context)
-               {
-                       int encoded = br.ReadCompressedUInt();
-                       switch (encoded & 3)
-                       {
-                               case 0:
-                                       return module.ResolveType((TypeDefTable.Index << 24) + (encoded >> 2), null, null);
-                               case 1:
-                                       return module.ResolveType((TypeRefTable.Index << 24) + (encoded >> 2), null, null);
-                               case 2:
-                                       return module.ResolveType((TypeSpecTable.Index << 24) + (encoded >> 2), context);
-                               default:
-                                       throw new BadImageFormatException();
-                       }
-               }
-
-               internal static void WriteStandAloneMethodSig(ModuleBuilder module, ByteBuffer bb, __StandAloneMethodSig sig)
-               {
-                       if (sig.IsUnmanaged)
-                       {
-                               switch (sig.UnmanagedCallingConvention)
-                               {
-                                       case CallingConvention.Cdecl:
-                                               bb.Write((byte)0x01);   // C
-                                               break;
-                                       case CallingConvention.StdCall:
-                                       case CallingConvention.Winapi:
-                                               bb.Write((byte)0x02);   // STDCALL
-                                               break;
-                                       case CallingConvention.ThisCall:
-                                               bb.Write((byte)0x03);   // THISCALL
-                                               break;
-                                       case CallingConvention.FastCall:
-                                               bb.Write((byte)0x04);   // FASTCALL
-                                               break;
-                                       default:
-                                               throw new ArgumentOutOfRangeException("callingConvention");
-                               }
-                       }
-                       else
-                       {
-                               CallingConventions callingConvention = sig.CallingConvention;
-                               byte flags = 0;
-                               if ((callingConvention & CallingConventions.HasThis) != 0)
-                               {
-                                       flags |= HASTHIS;
-                               }
-                               if ((callingConvention & CallingConventions.ExplicitThis) != 0)
-                               {
-                                       flags |= EXPLICITTHIS;
-                               }
-                               if ((callingConvention & CallingConventions.VarArgs) != 0)
-                               {
-                                       flags |= VARARG;
-                               }
-                               bb.Write(flags);
-                       }
-                       Type[] parameterTypes = sig.ParameterTypes;
-                       Type[] optionalParameterTypes = sig.OptionalParameterTypes;
-                       bb.WriteCompressedUInt(parameterTypes.Length + optionalParameterTypes.Length);
-                       WriteCustomModifiers(module, bb, sig.GetReturnTypeCustomModifiers());
-                       WriteType(module, bb, sig.ReturnType);
-                       int index = 0;
-                       foreach (Type t in parameterTypes)
-                       {
-                               WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
-                               WriteType(module, bb, t);
-                       }
-                       // note that optional parameters are only allowed for managed signatures (but we don't enforce that)
-                       if (optionalParameterTypes.Length > 0)
-                       {
-                               bb.Write(SENTINEL);
-                               foreach (Type t in optionalParameterTypes)
-                               {
-                                       WriteCustomModifiers(module, bb, sig.GetParameterCustomModifiers(index++));
-                                       WriteType(module, bb, t);
-                               }
-                       }
-               }
-
-               internal static void WriteTypeSpec(ModuleBuilder module, ByteBuffer bb, Type type)
-               {
-                       WriteType(module, bb, type);
-               }
-
-               internal static void WriteMethodSpec(ModuleBuilder module, ByteBuffer bb, Type[] genArgs)
-               {
-                       bb.Write(GENERICINST);
-                       bb.WriteCompressedUInt(genArgs.Length);
-                       foreach (Type arg in genArgs)
-                       {
-                               WriteType(module, bb, arg);
-                       }
-               }
-
-               // this reads just the optional parameter types, from a MethodRefSig
-               internal static Type[] ReadOptionalParameterTypes(ModuleReader module, ByteReader br, IGenericContext context, out CustomModifiers[] customModifiers)
-               {
-                       br.ReadByte();
-                       int paramCount = br.ReadCompressedUInt();
-                       CustomModifiers.Skip(br);
-                       ReadRetType(module, br, context);
-                       for (int i = 0; i < paramCount; i++)
-                       {
-                               if (br.PeekByte() == SENTINEL)
-                               {
-                                       br.ReadByte();
-                                       Type[] types = new Type[paramCount - i];
-                                       customModifiers = new CustomModifiers[types.Length];
-                                       for (int j = 0; j < types.Length; j++)
-                                       {
-                                               customModifiers[j] = CustomModifiers.Read(module, br, context);
-                                               types[j] = ReadType(module, br, context);
-                                       }
-                                       return types;
-                               }
-                               CustomModifiers.Skip(br);
-                               ReadType(module, br, context);
-                       }
-                       customModifiers = Empty<CustomModifiers>.Array;
-                       return Type.EmptyTypes;
-               }
-
-               protected static Type[] BindTypeParameters(IGenericBinder binder, Type[] types)
-               {
-                       if (types == null || types.Length == 0)
-                       {
-                               return Type.EmptyTypes;
-                       }
-                       Type[] expanded = new Type[types.Length];
-                       for (int i = 0; i < types.Length; i++)
-                       {
-                               expanded[i] = types[i].BindTypeParameters(binder);
-                       }
-                       return expanded;
-               }
-
-               internal static void WriteSignatureHelper(ModuleBuilder module, ByteBuffer bb, byte flags, ushort paramCount, List<Type> args)
-               {
-                       bb.Write(flags);
-                       if (flags != FIELD)
-                       {
-                               bb.WriteCompressedUInt(paramCount);
-                       }
-                       foreach (Type type in args)
-                       {
-                               if (type == MarkerType.ModOpt)
-                               {
-                                       bb.Write(ELEMENT_TYPE_CMOD_OPT);
-                               }
-                               else if (type == MarkerType.ModReq)
-                               {
-                                       bb.Write(ELEMENT_TYPE_CMOD_REQD);
-                               }
-                               else if (type == MarkerType.Sentinel)
-                               {
-                                       bb.Write(SENTINEL);
-                               }
-                               else if (type == MarkerType.Pinned)
-                               {
-                                       bb.Write(ELEMENT_TYPE_PINNED);
-                               }
-                               else if (type == null)
-                               {
-                                       bb.Write(ELEMENT_TYPE_VOID);
-                               }
-                               else
-                               {
-                                       WriteType(module, bb, type);
-                               }
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/StandAloneMethodSig.cs b/mcs/class/IKVM.Reflection/StandAloneMethodSig.cs
deleted file mode 100644 (file)
index 1d9425d..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
-  Copyright (C) 2010 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.InteropServices;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection
-{
-       public sealed class __StandAloneMethodSig
-       {
-               private readonly bool unmanaged;
-               private readonly CallingConvention unmanagedCallingConvention;
-               private readonly CallingConventions callingConvention;
-               private readonly Type returnType;
-               private readonly Type[] parameterTypes;
-               private readonly Type[] optionalParameterTypes;
-               private readonly PackedCustomModifiers customModifiers;
-
-               internal __StandAloneMethodSig(bool unmanaged, CallingConvention unmanagedCallingConvention, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, Type[] optionalParameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       this.unmanaged = unmanaged;
-                       this.unmanagedCallingConvention = unmanagedCallingConvention;
-                       this.callingConvention = callingConvention;
-                       this.returnType = returnType;
-                       this.parameterTypes = parameterTypes;
-                       this.optionalParameterTypes = optionalParameterTypes;
-                       this.customModifiers = customModifiers;
-               }
-
-               public bool Equals(__StandAloneMethodSig other)
-               {
-                       return other != null
-                               && other.unmanaged == unmanaged
-                               && other.unmanagedCallingConvention == unmanagedCallingConvention
-                               && other.callingConvention == callingConvention
-                               && other.returnType == returnType
-                               && Util.ArrayEquals(other.parameterTypes, parameterTypes)
-                               && Util.ArrayEquals(other.optionalParameterTypes, optionalParameterTypes)
-                               && other.customModifiers.Equals(customModifiers);
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return Equals(obj as __StandAloneMethodSig);
-               }
-
-               public override int GetHashCode()
-               {
-                       return returnType.GetHashCode()
-                               ^ Util.GetHashCode(parameterTypes);
-               }
-
-               public bool IsUnmanaged
-               {
-                       get { return unmanaged; }
-               }
-
-               public CallingConventions CallingConvention
-               {
-                       get { return callingConvention; }
-               }
-
-               public CallingConvention UnmanagedCallingConvention
-               {
-                       get { return unmanagedCallingConvention; }
-               }
-
-               public Type ReturnType
-               {
-                       get { return returnType; }
-               }
-
-               public CustomModifiers GetReturnTypeCustomModifiers()
-               {
-                       return customModifiers.GetReturnTypeCustomModifiers();
-               }
-
-               public Type[] ParameterTypes
-               {
-                       get { return Util.Copy(parameterTypes); }
-               }
-
-               public Type[] OptionalParameterTypes
-               {
-                       get { return Util.Copy(optionalParameterTypes); }
-               }
-
-               public CustomModifiers GetParameterCustomModifiers(int index)
-               {
-                       return customModifiers.GetParameterCustomModifiers(index);
-               }
-
-               internal int ParameterCount
-               {
-                       get { return parameterTypes.Length + optionalParameterTypes.Length; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/StrongNameKeyPair.cs b/mcs/class/IKVM.Reflection/StrongNameKeyPair.cs
deleted file mode 100644 (file)
index 7d35447..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using System.Security.Cryptography;
-
-namespace IKVM.Reflection
-{
-       public sealed class StrongNameKeyPair
-       {
-               private readonly byte[] keyPairArray;
-               private readonly string keyPairContainer;
-
-               public StrongNameKeyPair(string keyPairContainer)
-               {
-                       if (keyPairContainer == null)
-                       {
-                               throw new ArgumentNullException("keyPairContainer");
-                       }
-                       if (Universe.MonoRuntime && Environment.OSVersion.Platform == PlatformID.Win32NT)
-                       {
-                               throw new NotSupportedException("IKVM.Reflection does not support key containers when running on Mono");
-                       }
-                       this.keyPairContainer = keyPairContainer;
-               }
-
-               public StrongNameKeyPair(byte[] keyPairArray)
-               {
-                       if (keyPairArray == null)
-                       {
-                               throw new ArgumentNullException("keyPairArray");
-                       }
-                       this.keyPairArray = (byte[])keyPairArray.Clone();
-               }
-
-               public StrongNameKeyPair(FileStream keyPairFile)
-                       : this(ReadAllBytes(keyPairFile))
-               {
-               }
-
-               private static byte[] ReadAllBytes(FileStream keyPairFile)
-               {
-                       if (keyPairFile == null)
-                       {
-                               throw new ArgumentNullException("keyPairFile");
-                       }
-                       byte[] buf = new byte[keyPairFile.Length - keyPairFile.Position];
-                       keyPairFile.Read(buf, 0, buf.Length);
-                       return buf;
-               }
-
-               public byte[] PublicKey
-               {
-                       get
-                       {
-                               if (Universe.MonoRuntime)
-                               {
-                                       // MONOBUG workaround for https://bugzilla.xamarin.com/show_bug.cgi?id=5299
-                                       return MonoGetPublicKey();
-                               }
-                               using (RSACryptoServiceProvider rsa = CreateRSA())
-                               {
-                                       byte[] cspBlob = rsa.ExportCspBlob(false);
-                                       byte[] publicKey = new byte[12 + cspBlob.Length];
-                                       Buffer.BlockCopy(cspBlob, 0, publicKey, 12, cspBlob.Length);
-                                       publicKey[1] = 36;
-                                       publicKey[4] = 4;
-                                       publicKey[5] = 128;
-                                       publicKey[8] = (byte)(cspBlob.Length >> 0);
-                                       publicKey[9] = (byte)(cspBlob.Length >> 8);
-                                       publicKey[10] = (byte)(cspBlob.Length >> 16);
-                                       publicKey[11] = (byte)(cspBlob.Length >> 24);
-                                       return publicKey;
-                               }
-                       }
-               }
-
-               internal RSACryptoServiceProvider CreateRSA()
-               {
-                       try
-                       {
-                               if (keyPairArray != null)
-                               {
-                                       RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
-                                       rsa.ImportCspBlob(keyPairArray);
-                                       return rsa;
-                               }
-                               else
-                               {
-                                       CspParameters parm = new CspParameters();
-                                       parm.KeyContainerName = keyPairContainer;
-                                       // MONOBUG Mono doesn't like it when Flags or KeyNumber are set
-                                       if (!Universe.MonoRuntime)
-                                       {
-                                               parm.Flags = CspProviderFlags.UseMachineKeyStore | CspProviderFlags.UseExistingKey;
-                                               parm.KeyNumber = 2;     // Signature
-                                       }
-                                       return new RSACryptoServiceProvider(parm);
-                               }
-                       }
-                       catch
-                       {
-                               throw new ArgumentException("Unable to obtain public key for StrongNameKeyPair.");
-                       }
-               }
-
-               [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
-               private byte[] MonoGetPublicKey()
-               {
-                       return keyPairArray != null
-                               ? new System.Reflection.StrongNameKeyPair(keyPairArray).PublicKey
-                               : new System.Reflection.StrongNameKeyPair(keyPairContainer).PublicKey;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Type.cs b/mcs/class/IKVM.Reflection/Type.cs
deleted file mode 100644 (file)
index 6b9852a..0000000
+++ /dev/null
@@ -1,3087 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-using System.Collections.Generic;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection
-{
-       interface IGenericContext
-       {
-               Type GetGenericTypeArgument(int index);
-               Type GetGenericMethodArgument(int index);
-       }
-
-       interface IGenericBinder
-       {
-               Type BindTypeParameter(Type type);
-               Type BindMethodParameter(Type type);
-       }
-
-       public abstract class Type : MemberInfo, IGenericContext, IGenericBinder
-       {
-               public static readonly Type[] EmptyTypes = Empty<Type>.Array;
-               protected readonly Type underlyingType;
-               protected TypeFlags typeFlags;
-
-               [Flags]
-               protected enum TypeFlags
-               {
-                       // for use by TypeBuilder or TypeDefImpl
-                       IsGenericTypeDefinition = 1,
-
-                       // for use by TypeBuilder
-                       HasNestedTypes = 2,
-                       Baked = 4,
-
-                       // for use by MissingType
-                       ValueType = 8,
-                       NotValueType = 16,
-
-                       // for use by TypeDefImpl, TypeBuilder or MissingType
-                       PotentialEnumOrValueType = 32,
-                       EnumOrValueType = 64,
-
-                       // for use by TypeDefImpl
-                       NotGenericTypeDefinition = 128,
-               }
-
-               // prevent subclassing by outsiders
-               internal Type()
-               {
-                       this.underlyingType = this;
-               }
-
-               internal Type(Type underlyingType)
-               {
-                       System.Diagnostics.Debug.Assert(underlyingType.underlyingType == underlyingType);
-                       this.underlyingType = underlyingType;
-                       this.typeFlags = underlyingType.typeFlags;
-               }
-
-               public static Binder DefaultBinder
-               {
-                       get { return new DefaultBinder(); }
-               }
-
-               public sealed override MemberTypes MemberType
-               {
-                       get { return IsNested ? MemberTypes.NestedType : MemberTypes.TypeInfo; }
-               }
-
-               public virtual string AssemblyQualifiedName
-               {
-                       // NOTE the assembly name is not escaped here, only when used in a generic type instantiation
-                       get { return this.FullName + ", " + this.Assembly.FullName; }
-               }
-
-               public abstract Type BaseType
-               {
-                       get;
-               }
-
-               public abstract TypeAttributes Attributes
-               {
-                       get;
-               }
-
-               public virtual Type GetElementType()
-               {
-                       return null;
-               }
-
-               internal virtual void CheckBaked()
-               {
-               }
-
-               public virtual Type[] __GetDeclaredTypes()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public virtual Type[] __GetDeclaredInterfaces()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public virtual MethodBase[] __GetDeclaredMethods()
-               {
-                       return Empty<MethodBase>.Array;
-               }
-
-               public virtual __MethodImplMap __GetMethodImplMap()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual FieldInfo[] __GetDeclaredFields()
-               {
-                       return Empty<FieldInfo>.Array;
-               }
-
-               public virtual EventInfo[] __GetDeclaredEvents()
-               {
-                       return Empty<EventInfo>.Array;
-               }
-
-               public virtual PropertyInfo[] __GetDeclaredProperties()
-               {
-                       return Empty<PropertyInfo>.Array;
-               }
-
-               public virtual CustomModifiers __GetCustomModifiers()
-               {
-                       return new CustomModifiers();
-               }
-
-               [Obsolete("Please use __GetCustomModifiers() instead.")]
-               public Type[] __GetRequiredCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetRequired();
-               }
-
-               [Obsolete("Please use __GetCustomModifiers() instead.")]
-               public Type[] __GetOptionalCustomModifiers()
-               {
-                       return __GetCustomModifiers().GetOptional();
-               }
-
-               public virtual __StandAloneMethodSig __MethodSignature
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public virtual bool HasElementType
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsArray
-               {
-                       get { return false; }
-               }
-
-               public virtual bool __IsVector
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsByRef
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsPointer
-               {
-                       get { return false; }
-               }
-
-               public virtual bool __IsFunctionPointer
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsValueType
-               {
-                       get
-                       {
-                               Type baseType = this.BaseType;
-                               return baseType != null
-                                       && baseType.IsEnumOrValueType
-                                       && !this.IsEnumOrValueType;
-                       }
-               }
-
-               public virtual bool IsGenericParameter
-               {
-                       get { return false; }
-               }
-
-               public virtual int GenericParameterPosition
-               {
-                       get { throw new NotSupportedException(); }
-               }
-
-               public virtual MethodBase DeclaringMethod
-               {
-                       get { return null; }
-               }
-
-               public Type UnderlyingSystemType
-               {
-                       get { return underlyingType; }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return null; }
-               }
-
-               public virtual string __Name
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public virtual string __Namespace
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public abstract override string Name
-               {
-                       get;
-               }
-
-               public virtual string Namespace
-               {
-                       get
-                       {
-                               if (IsNested)
-                               {
-                                       return DeclaringType.Namespace;
-                               }
-                               return __Namespace;
-                       }
-               }
-
-               internal virtual int GetModuleBuilderToken()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public static bool operator ==(Type t1, Type t2)
-               {
-                       // Casting to object results in smaller code than calling ReferenceEquals and makes
-                       // this method more likely to be inlined.
-                       // On CLR v2 x86, microbenchmarks show this to be faster than calling ReferenceEquals.
-                       return (object)t1 == (object)t2
-                               || ((object)t1 != null && (object)t2 != null && (object)t1.underlyingType == (object)t2.underlyingType);
-               }
-
-               public static bool operator !=(Type t1, Type t2)
-               {
-                       return !(t1 == t2);
-               }
-
-               public bool Equals(Type type)
-               {
-                       return this == type;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       return Equals(obj as Type);
-               }
-
-               public override int GetHashCode()
-               {
-                       Type type = this.UnderlyingSystemType;
-                       return ReferenceEquals(type, this) ? base.GetHashCode() : type.GetHashCode();
-               }
-
-               public Type[] GenericTypeArguments
-               {
-                       get { return IsConstructedGenericType ? GetGenericArguments() : Type.EmptyTypes; }
-               }
-
-               public virtual Type[] GetGenericArguments()
-               {
-                       return Type.EmptyTypes;
-               }
-
-               public virtual CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       return Empty<CustomModifiers>.Array;
-               }
-
-               [Obsolete("Please use __GetGenericArgumentsCustomModifiers() instead")]
-               public Type[][] __GetGenericArgumentsRequiredCustomModifiers()
-               {
-                       CustomModifiers[] customModifiers = __GetGenericArgumentsCustomModifiers();
-                       Type[][] array = new Type[customModifiers.Length][];
-                       for (int i = 0; i < array.Length; i++)
-                       {
-                               array[i] = customModifiers[i].GetRequired();
-                       }
-                       return array;
-               }
-
-               [Obsolete("Please use __GetGenericArgumentsCustomModifiers() instead")]
-               public Type[][] __GetGenericArgumentsOptionalCustomModifiers()
-               {
-                       CustomModifiers[] customModifiers = __GetGenericArgumentsCustomModifiers();
-                       Type[][] array = new Type[customModifiers.Length][];
-                       for (int i = 0; i < array.Length; i++)
-                       {
-                               array[i] = customModifiers[i].GetOptional();
-                       }
-                       return array;
-               }
-
-               public virtual Type GetGenericTypeDefinition()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public virtual StructLayoutAttribute StructLayoutAttribute
-               {
-                       get { return null; }
-               }
-
-               public virtual bool __GetLayout(out int packingSize, out int typeSize)
-               {
-                       packingSize = 0;
-                       typeSize = 0;
-                       return false;
-               }
-
-               public virtual bool IsGenericType
-               {
-                       get { return false; }
-               }
-
-               public virtual bool IsGenericTypeDefinition
-               {
-                       get { return false; }
-               }
-
-               // .NET 4.5 API
-               public virtual bool IsConstructedGenericType
-               {
-                       get { return false; }
-               }
-
-               public virtual bool ContainsGenericParameters
-               {
-                       get
-                       {
-                               if (this.IsGenericParameter)
-                               {
-                                       return true;
-                               }
-                               foreach (Type arg in this.GetGenericArguments())
-                               {
-                                       if (arg.ContainsGenericParameters)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               public virtual Type[] GetGenericParameterConstraints()
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public virtual GenericParameterAttributes GenericParameterAttributes
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public virtual int GetArrayRank()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual int[] __GetArraySizes()
-               {
-                       throw new NotSupportedException();
-               }
-
-               public virtual int[] __GetArrayLowerBounds()
-               {
-                       throw new NotSupportedException();
-               }
-
-               // .NET 4.0 API
-               public virtual Type GetEnumUnderlyingType()
-               {
-                       if (!this.IsEnum)
-                       {
-                               throw new ArgumentException();
-                       }
-                       CheckBaked();
-                       return GetEnumUnderlyingTypeImpl();
-               }
-
-               internal Type GetEnumUnderlyingTypeImpl()
-               {
-                       foreach (FieldInfo field in __GetDeclaredFields())
-                       {
-                               if (!field.IsStatic)
-                               {
-                                       // the CLR assumes that an enum has only one instance field, so we can do the same
-                                       return field.FieldType;
-                               }
-                       }
-                       throw new InvalidOperationException();
-               }
-
-               public string[] GetEnumNames()
-               {
-                       if (!IsEnum)
-                       {
-                               throw new ArgumentException();
-                       }
-                       List<string> names = new List<string>();
-                       foreach (FieldInfo field in __GetDeclaredFields())
-                       {
-                               if (field.IsLiteral)
-                               {
-                                       names.Add(field.Name);
-                               }
-                       }
-                       return names.ToArray();
-               }
-
-               public string GetEnumName(object value)
-               {
-                       if (!IsEnum)
-                       {
-                               throw new ArgumentException();
-                       }
-                       if (value == null)
-                       {
-                               throw new ArgumentNullException();
-                       }
-                       try
-                       {
-                               value = Convert.ChangeType(value, GetTypeCode(GetEnumUnderlyingType()));
-                       }
-                       catch (FormatException)
-                       {
-                               throw new ArgumentException();
-                       }
-                       catch (OverflowException)
-                       {
-                               return null;
-                       }
-                       catch (InvalidCastException)
-                       {
-                               return null;
-                       }
-                       foreach (FieldInfo field in __GetDeclaredFields())
-                       {
-                               if (field.IsLiteral && field.GetRawConstantValue().Equals(value))
-                               {
-                                       return field.Name;
-                               }
-                       }
-                       return null;
-               }
-
-               public bool IsEnumDefined(object value)
-               {
-                       if (value is string)
-                       {
-                               return Array.IndexOf(GetEnumNames(), value) != -1;
-                       }
-                       if (!IsEnum)
-                       {
-                               throw new ArgumentException();
-                       }
-                       if (value == null)
-                       {
-                               throw new ArgumentNullException();
-                       }
-                       if (System.Type.GetTypeCode(value.GetType()) != GetTypeCode(GetEnumUnderlyingType()))
-                       {
-                               throw new ArgumentException();
-                       }
-                       foreach (FieldInfo field in __GetDeclaredFields())
-                       {
-                               if (field.IsLiteral && field.GetRawConstantValue().Equals(value))
-                               {
-                                       return true;
-                               }
-                       }
-                       return false;
-               }
-
-               public override string ToString()
-               {
-                       return FullName;
-               }
-
-               public abstract string FullName
-               {
-                       get;
-               }
-
-               protected string GetFullName()
-               {
-                       string ns = TypeNameParser.Escape(this.__Namespace);
-                       Type decl = this.DeclaringType;
-                       if (decl == null)
-                       {
-                               if (ns == null)
-                               {
-                                       return this.Name;
-                               }
-                               else
-                               {
-                                       return ns + "." + this.Name;
-                               }
-                       }
-                       else
-                       {
-                               if (ns == null)
-                               {
-                                       return decl.FullName + "+" + this.Name;
-                               }
-                               else
-                               {
-                                       return decl.FullName + "+" + ns + "." + this.Name;
-                               }
-                       }
-               }
-
-               internal virtual bool IsModulePseudoType
-               {
-                       get { return false; }
-               }
-
-               internal virtual Type GetGenericTypeArgument(int index)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               public MemberInfo[] GetDefaultMembers()
-               {
-                       Type defaultMemberAttribute = this.Module.universe.Import(typeof(System.Reflection.DefaultMemberAttribute));
-                       foreach (CustomAttributeData cad in CustomAttributeData.GetCustomAttributes(this))
-                       {
-                               if (cad.Constructor.DeclaringType.Equals(defaultMemberAttribute))
-                               {
-                                       return GetMember((string)cad.ConstructorArguments[0].Value);
-                               }
-                       }
-                       return Empty<MemberInfo>.Array;
-               }
-
-               public MemberInfo[] GetMember(string name)
-               {
-                       return GetMember(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public MemberInfo[] GetMember(string name, BindingFlags bindingAttr)
-               {
-                       return GetMember(name, MemberTypes.All, bindingAttr);
-               }
-
-               public MemberInfo[] GetMembers()
-               {
-                       return GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public MemberInfo[] GetMembers(BindingFlags bindingAttr)
-               {
-                       List<MemberInfo> members = new List<MemberInfo>();
-                       members.AddRange(GetConstructors(bindingAttr));
-                       members.AddRange(GetMethods(bindingAttr));
-                       members.AddRange(GetFields(bindingAttr));
-                       members.AddRange(GetProperties(bindingAttr));
-                       members.AddRange(GetEvents(bindingAttr));
-                       members.AddRange(GetNestedTypes(bindingAttr));
-                       return members.ToArray();
-               }
-
-               public MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
-               {
-                       MemberFilter filter;
-                       if ((bindingAttr & BindingFlags.IgnoreCase) != 0)
-                       {
-                               name = name.ToLowerInvariant();
-                               filter = delegate(MemberInfo member, object filterCriteria) { return member.Name.ToLowerInvariant().Equals(filterCriteria); };
-                       }
-                       else
-                       {
-                               filter = delegate(MemberInfo member, object filterCriteria) { return member.Name.Equals(filterCriteria); };
-                       }
-                       return FindMembers(type, bindingAttr, filter, name);
-               }
-
-               private static void AddMembers(List<MemberInfo> list, MemberFilter filter, object filterCriteria, MemberInfo[] members)
-               {
-                       foreach (MemberInfo member in members)
-                       {
-                               if (filter == null || filter(member, filterCriteria))
-                               {
-                                       list.Add(member);
-                               }
-                       }
-               }
-
-               public MemberInfo[] FindMembers(MemberTypes memberType, BindingFlags bindingAttr, MemberFilter filter, object filterCriteria)
-               {
-                       List<MemberInfo> members = new List<MemberInfo>();
-                       if ((memberType & MemberTypes.Constructor) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetConstructors(bindingAttr));
-                       }
-                       if ((memberType & MemberTypes.Method) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetMethods(bindingAttr));
-                       }
-                       if ((memberType & MemberTypes.Field) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetFields(bindingAttr));
-                       }
-                       if ((memberType & MemberTypes.Property) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetProperties(bindingAttr));
-                       }
-                       if ((memberType & MemberTypes.Event) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetEvents(bindingAttr));
-                       }
-                       if ((memberType & MemberTypes.NestedType) != 0)
-                       {
-                               AddMembers(members, filter, filterCriteria, GetNestedTypes(bindingAttr));
-                       }
-                       return members.ToArray();
-               }
-
-               private MemberInfo[] GetMembers<T>()
-               {
-                       if (typeof(T) == typeof(ConstructorInfo) || typeof(T) == typeof(MethodInfo))
-                       {
-                               return __GetDeclaredMethods();
-                       }
-                       else if (typeof(T) == typeof(FieldInfo))
-                       {
-                               return __GetDeclaredFields();
-                       }
-                       else if (typeof(T) == typeof(PropertyInfo))
-                       {
-                               return __GetDeclaredProperties();
-                       }
-                       else if (typeof(T) == typeof(EventInfo))
-                       {
-                               return __GetDeclaredEvents();
-                       }
-                       else if (typeof(T) == typeof(Type))
-                       {
-                               return __GetDeclaredTypes();
-                       }
-                       else
-                       {
-                               throw new InvalidOperationException();
-                       }
-               }
-
-               private T[] GetMembers<T>(BindingFlags flags)
-                       where T : MemberInfo
-               {
-                       CheckBaked();
-                       List<T> list = new List<T>();
-                       foreach (MemberInfo member in GetMembers<T>())
-                       {
-                               if (member is T && member.BindingFlagsMatch(flags))
-                               {
-                                       list.Add((T)member);
-                               }
-                       }
-                       if ((flags & BindingFlags.DeclaredOnly) == 0)
-                       {
-                               for (Type type = this.BaseType; type != null; type = type.BaseType)
-                               {
-                                       type.CheckBaked();
-                                       foreach (MemberInfo member in type.GetMembers<T>())
-                                       {
-                                               if (member is T && member.BindingFlagsMatchInherited(flags))
-                                               {
-                                                       list.Add((T)member.SetReflectedType(this));
-                                               }
-                                       }
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               private T GetMemberByName<T>(string name, BindingFlags flags, Predicate<T> filter)
-                       where T : MemberInfo
-               {
-                       CheckBaked();
-                       if ((flags & BindingFlags.IgnoreCase) != 0)
-                       {
-                               name = name.ToLowerInvariant();
-                       }
-                       T found = null;
-                       foreach (MemberInfo member in GetMembers<T>())
-                       {
-                               if (member is T && member.BindingFlagsMatch(flags))
-                               {
-                                       string memberName = member.Name;
-                                       if ((flags & BindingFlags.IgnoreCase) != 0)
-                                       {
-                                               memberName = memberName.ToLowerInvariant();
-                                       }
-                                       if (memberName == name && (filter == null || filter((T)member)))
-                                       {
-                                               if (found != null)
-                                               {
-                                                       throw new AmbiguousMatchException();
-                                               }
-                                               found = (T)member;
-                                       }
-                               }
-                       }
-                       if ((flags & BindingFlags.DeclaredOnly) == 0)
-                       {
-                               for (Type type = this.BaseType; (found == null || typeof(T) == typeof(MethodInfo)) && type != null; type = type.BaseType)
-                               {
-                                       type.CheckBaked();
-                                       foreach (MemberInfo member in type.GetMembers<T>())
-                                       {
-                                               if (member is T && member.BindingFlagsMatchInherited(flags))
-                                               {
-                                                       string memberName = member.Name;
-                                                       if ((flags & BindingFlags.IgnoreCase) != 0)
-                                                       {
-                                                               memberName = memberName.ToLowerInvariant();
-                                                       }
-                                                       if (memberName == name && (filter == null || filter((T)member)))
-                                                       {
-                                                               if (found != null)
-                                                               {
-                                                                       MethodInfo mi;
-                                                                       // TODO does this depend on HideBySig vs HideByName?
-                                                                       if ((mi = found as MethodInfo) != null
-                                                                               && mi.MethodSignature.MatchParameterTypes(((MethodBase)member).MethodSignature))
-                                                                       {
-                                                                               continue;
-                                                                       }
-                                                                       throw new AmbiguousMatchException();
-                                                               }
-                                                               found = (T)member.SetReflectedType(this);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-                       return found;
-               }
-
-               private T GetMemberByName<T>(string name, BindingFlags flags)
-                       where T : MemberInfo
-               {
-                       return GetMemberByName<T>(name, flags, null);
-               }
-
-               public EventInfo GetEvent(string name)
-               {
-                       return GetEvent(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public EventInfo GetEvent(string name, BindingFlags bindingAttr)
-               {
-                       return GetMemberByName<EventInfo>(name, bindingAttr);
-               }
-
-               public EventInfo[] GetEvents()
-               {
-                       return GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public EventInfo[] GetEvents(BindingFlags bindingAttr)
-               {
-                       return GetMembers<EventInfo>(bindingAttr);
-               }
-
-               public FieldInfo GetField(string name)
-               {
-                       return GetField(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public FieldInfo GetField(string name, BindingFlags bindingAttr)
-               {
-                       return GetMemberByName<FieldInfo>(name, bindingAttr);
-               }
-
-               public FieldInfo[] GetFields()
-               {
-                       return GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
-               }
-
-               public FieldInfo[] GetFields(BindingFlags bindingAttr)
-               {
-                       return GetMembers<FieldInfo>(bindingAttr);
-               }
-
-               public Type[] GetInterfaces()
-               {
-                       List<Type> list = new List<Type>();
-                       for (Type type = this; type != null; type = type.BaseType)
-                       {
-                               AddInterfaces(list, type);
-                       }
-                       return list.ToArray();
-               }
-
-               private static void AddInterfaces(List<Type> list, Type type)
-               {
-                       foreach (Type iface in type.__GetDeclaredInterfaces())
-                       {
-                               if (!list.Contains(iface))
-                               {
-                                       list.Add(iface);
-                                       AddInterfaces(list, iface);
-                               }
-                       }
-               }
-
-               public MethodInfo[] GetMethods(BindingFlags bindingAttr)
-               {
-                       CheckBaked();
-                       List<MethodInfo> list = new List<MethodInfo>();
-                       foreach (MethodBase mb in __GetDeclaredMethods())
-                       {
-                               MethodInfo mi = mb as MethodInfo;
-                               if (mi != null && mi.BindingFlagsMatch(bindingAttr))
-                               {
-                                       list.Add(mi);
-                               }
-                       }
-                       if ((bindingAttr & BindingFlags.DeclaredOnly) == 0)
-                       {
-                               List<MethodInfo> baseMethods = new List<MethodInfo>();
-                               foreach (MethodInfo mi in list)
-                               {
-                                       if (mi.IsVirtual)
-                                       {
-                                               baseMethods.Add(mi.GetBaseDefinition());
-                                       }
-                               }
-                               for (Type type = this.BaseType; type != null; type = type.BaseType)
-                               {
-                                       type.CheckBaked();
-                                       foreach (MethodBase mb in type.__GetDeclaredMethods())
-                                       {
-                                               MethodInfo mi = mb as MethodInfo;
-                                               if (mi != null && mi.BindingFlagsMatchInherited(bindingAttr))
-                                               {
-                                                       if (mi.IsVirtual)
-                                                       {
-                                                               if (baseMethods == null)
-                                                               {
-                                                                       baseMethods = new List<MethodInfo>();
-                                                               }
-                                                               else if (baseMethods.Contains(mi.GetBaseDefinition()))
-                                                               {
-                                                                       continue;
-                                                               }
-                                                               baseMethods.Add(mi.GetBaseDefinition());
-                                                       }
-                                                       list.Add((MethodInfo)mi.SetReflectedType(this));
-                                               }
-                                       }
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public MethodInfo[] GetMethods()
-               {
-                       return GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
-               }
-
-               public MethodInfo GetMethod(string name)
-               {
-                       return GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
-               }
-
-               public MethodInfo GetMethod(string name, BindingFlags bindingAttr)
-               {
-                       return GetMemberByName<MethodInfo>(name, bindingAttr);
-               }
-
-               public MethodInfo GetMethod(string name, Type[] types)
-               {
-                       return GetMethod(name, types, null);
-               }
-
-               public MethodInfo GetMethod(string name, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetMethod(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, types, modifiers);
-               }
-
-               public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
-               {
-                       // first we try an exact match and only if that fails we fall back to using the binder
-                       return GetMemberByName<MethodInfo>(name, bindingAttr,
-                               delegate(MethodInfo method) { return method.MethodSignature.MatchParameterTypes(types); })
-                               ?? GetMethodWithBinder<MethodInfo>(name, bindingAttr, binder ?? DefaultBinder, types, modifiers);
-               }
-
-               private T GetMethodWithBinder<T>(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
-                       where T : MethodBase
-               {
-                       List<MethodBase> list = new List<MethodBase>();
-                       GetMemberByName<T>(name, bindingAttr, delegate(T method) {
-                               list.Add(method);
-                               return false;
-                       });
-                       return (T)binder.SelectMethod(bindingAttr, list.ToArray(), types, modifiers);
-               }
-
-               public MethodInfo GetMethod(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       // FXBUG callConvention seems to be ignored
-                       return GetMethod(name, bindingAttr, binder, types, modifiers);
-               }
-
-               public ConstructorInfo[] GetConstructors()
-               {
-                       return GetConstructors(BindingFlags.Public | BindingFlags.Instance);
-               }
-
-               public ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
-               {
-                       return GetMembers<ConstructorInfo>(bindingAttr | BindingFlags.DeclaredOnly);
-               }
-
-               public ConstructorInfo GetConstructor(Type[] types)
-               {
-                       return GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, CallingConventions.Standard, types, null);
-               }
-
-               public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
-               {
-                       ConstructorInfo ci1 = null;
-                       if ((bindingAttr & BindingFlags.Instance) != 0)
-                       {
-                               ci1 = GetConstructorImpl(ConstructorInfo.ConstructorName, bindingAttr, binder, types, modifiers);
-                       }
-                       if ((bindingAttr & BindingFlags.Static) != 0)
-                       {
-                               ConstructorInfo ci2 = GetConstructorImpl(ConstructorInfo.TypeConstructorName, bindingAttr, binder, types, modifiers);
-                               if (ci2 != null)
-                               {
-                                       if (ci1 != null)
-                                       {
-                                               throw new AmbiguousMatchException();
-                                       }
-                                       return ci2;
-                               }
-                       }
-                       return ci1;
-               }
-
-               private ConstructorInfo GetConstructorImpl(string name, BindingFlags bindingAttr, Binder binder, Type[] types, ParameterModifier[] modifiers)
-               {
-                       // first we try an exact match and only if that fails we fall back to using the binder
-                       return GetMemberByName<ConstructorInfo>(name, bindingAttr | BindingFlags.DeclaredOnly,
-                               delegate(ConstructorInfo ctor) { return ctor.MethodSignature.MatchParameterTypes(types); })
-                               ?? GetMethodWithBinder<ConstructorInfo>(name, bindingAttr, binder ?? DefaultBinder, types, modifiers);
-               }
-
-               public ConstructorInfo GetConstructor(BindingFlags bindingAttr, Binder binder, CallingConventions callingConvention, Type[] types, ParameterModifier[] modifiers)
-               {
-                       // FXBUG callConvention seems to be ignored
-                       return GetConstructor(bindingAttr, binder, types, modifiers);
-               }
-
-               internal Type ResolveNestedType(TypeName typeName)
-               {
-                       return FindNestedType(typeName) ?? Module.universe.GetMissingTypeOrThrow(Module, this, typeName);
-               }
-
-               // unlike the public API, this takes the namespace and name into account
-               internal virtual Type FindNestedType(TypeName name)
-               {
-                       foreach (Type type in __GetDeclaredTypes())
-                       {
-                               if (type.__Namespace == name.Namespace && type.__Name == name.Name)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               internal virtual Type FindNestedTypeIgnoreCase(TypeName lowerCaseName)
-               {
-                       foreach (Type type in __GetDeclaredTypes())
-                       {
-                               if (new TypeName(type.__Namespace, type.__Name).ToLowerInvariant() == lowerCaseName)
-                               {
-                                       return type;
-                               }
-                       }
-                       return null;
-               }
-
-               public Type GetNestedType(string name)
-               {
-                       return GetNestedType(name, BindingFlags.Public);
-               }
-
-               public Type GetNestedType(string name, BindingFlags bindingAttr)
-               {
-                       // FXBUG the namespace is ignored, so we can use GetMemberByName
-                       return GetMemberByName<Type>(name, bindingAttr | BindingFlags.DeclaredOnly);
-               }
-
-               public Type[] GetNestedTypes()
-               {
-                       return GetNestedTypes(BindingFlags.Public);
-               }
-
-               public Type[] GetNestedTypes(BindingFlags bindingAttr)
-               {
-                       // FXBUG the namespace is ignored, so we can use GetMember
-                       return GetMembers<Type>(bindingAttr | BindingFlags.DeclaredOnly);
-               }
-
-               public PropertyInfo[] GetProperties()
-               {
-                       return GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public PropertyInfo[] GetProperties(BindingFlags bindingAttr)
-               {
-                       return GetMembers<PropertyInfo>(bindingAttr);
-               }
-
-               public PropertyInfo GetProperty(string name)
-               {
-                       return GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
-               }
-
-               public PropertyInfo GetProperty(string name, BindingFlags bindingAttr)
-               {
-                       return GetMemberByName<PropertyInfo>(name, bindingAttr);
-               }
-
-               public PropertyInfo GetProperty(string name, Type returnType)
-               {
-                       const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
-                       return GetMemberByName<PropertyInfo>(name, flags, delegate(PropertyInfo prop) { return prop.PropertyType.Equals(returnType); })
-                               ?? GetPropertyWithBinder(name, flags, DefaultBinder, returnType, null, null);
-               }
-
-               public PropertyInfo GetProperty(string name, Type[] types)
-               {
-                       const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static;
-                       return GetMemberByName<PropertyInfo>(name, flags, delegate(PropertyInfo prop) { return prop.PropertySignature.MatchParameterTypes(types); })
-                               ?? GetPropertyWithBinder(name, flags, DefaultBinder, null, types, null);
-               }
-
-               public PropertyInfo GetProperty(string name, Type returnType, Type[] types)
-               {
-                       return GetProperty(name, returnType, types, null);
-               }
-
-               public PropertyInfo GetProperty(string name, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetProperty(name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, null, returnType, types, modifiers);
-               }
-
-               public PropertyInfo GetProperty(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       return GetMemberByName<PropertyInfo>(name, bindingAttr,
-                               delegate(PropertyInfo prop) {
-                                       return prop.PropertyType.Equals(returnType) && prop.PropertySignature.MatchParameterTypes(types);
-                               })
-                               ?? GetPropertyWithBinder(name, bindingAttr, binder ?? DefaultBinder, returnType, types, modifiers);
-               }
-
-               private PropertyInfo GetPropertyWithBinder(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
-               {
-                       List<PropertyInfo> list = new List<PropertyInfo>();
-                       GetMemberByName<PropertyInfo>(name, bindingAttr, delegate(PropertyInfo property) {
-                               list.Add(property);
-                               return false;
-                       });
-                       return binder.SelectProperty(bindingAttr, list.ToArray(), returnType, types, modifiers);
-               }
-
-               public Type GetInterface(string name)
-               {
-                       return GetInterface(name, false);
-               }
-
-               public Type GetInterface(string name, bool ignoreCase)
-               {
-                       if (ignoreCase)
-                       {
-                               name = name.ToLowerInvariant();
-                       }
-                       Type found = null;
-                       foreach (Type type in GetInterfaces())
-                       {
-                               string typeName = type.FullName;
-                               if (ignoreCase)
-                               {
-                                       typeName = typeName.ToLowerInvariant();
-                               }
-                               if (typeName == name)
-                               {
-                                       if (found != null)
-                                       {
-                                               throw new AmbiguousMatchException();
-                                       }
-                                       found = type;
-                               }
-                       }
-                       return found;
-               }
-
-               public Type[] FindInterfaces(TypeFilter filter, object filterCriteria)
-               {
-                       List<Type> list = new List<Type>();
-                       foreach (Type type in GetInterfaces())
-                       {
-                               if (filter(type, filterCriteria))
-                               {
-                                       list.Add(type);
-                               }
-                       }
-                       return list.ToArray();
-               }
-
-               public ConstructorInfo TypeInitializer
-               {
-                       get { return GetConstructor(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); }
-               }
-
-               public bool IsPrimitive
-               {
-                       get
-                       {
-                               Universe u = this.Universe;
-                               return this == u.System_Boolean
-                                       || this == u.System_Byte
-                                       || this == u.System_SByte
-                                       || this == u.System_Int16
-                                       || this == u.System_UInt16
-                                       || this == u.System_Int32
-                                       || this == u.System_UInt32
-                                       || this == u.System_Int64
-                                       || this == u.System_UInt64
-                                       || this == u.System_IntPtr
-                                       || this == u.System_UIntPtr
-                                       || this == u.System_Char
-                                       || this == u.System_Double
-                                       || this == u.System_Single
-                                       ;
-                       }
-               }
-
-               public bool IsEnum
-               {
-                       get
-                       {
-                               Type baseType = this.BaseType;
-                               return baseType != null
-                                       && baseType.IsEnumOrValueType
-                                       && baseType.__Name[0] == 'E';
-                       }
-               }
-
-               public bool IsSealed
-               {
-                       get { return (Attributes & TypeAttributes.Sealed) != 0; }
-               }
-
-               public bool IsAbstract
-               {
-                       get { return (Attributes & TypeAttributes.Abstract) != 0; }
-               }
-
-               private bool CheckVisibility(TypeAttributes access)
-               {
-                       return (Attributes & TypeAttributes.VisibilityMask) == access;
-               }
-
-               public bool IsPublic
-               {
-                       get { return CheckVisibility(TypeAttributes.Public); }
-               }
-
-               public bool IsNestedPublic
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedPublic); }
-               }
-
-               public bool IsNestedPrivate
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedPrivate); }
-               }
-
-               public bool IsNestedFamily
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedFamily); }
-               }
-
-               public bool IsNestedAssembly
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedAssembly); }
-               }
-
-               public bool IsNestedFamANDAssem
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedFamANDAssem); }
-               }
-
-               public bool IsNestedFamORAssem
-               {
-                       get { return CheckVisibility(TypeAttributes.NestedFamORAssem); }
-               }
-
-               public bool IsNotPublic
-               {
-                       get { return CheckVisibility(TypeAttributes.NotPublic); }
-               }
-
-               public bool IsImport
-               {
-                       get { return (Attributes & TypeAttributes.Import) != 0; }
-               }
-
-               public bool IsCOMObject
-               {
-                       get { return IsClass && IsImport; }
-               }
-
-               public bool IsContextful
-               {
-                       get { return IsSubclassOf(this.Module.universe.Import(typeof(ContextBoundObject))); }
-               }
-
-               public bool IsMarshalByRef
-               {
-                       get { return IsSubclassOf(this.Module.universe.Import(typeof(MarshalByRefObject))); }
-               }
-
-               public virtual bool IsVisible
-               {
-                       get { return IsPublic || (IsNestedPublic && this.DeclaringType.IsVisible); }
-               }
-
-               public bool IsAnsiClass
-               {
-                       get { return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AnsiClass; }
-               }
-
-               public bool IsUnicodeClass
-               {
-                       get { return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.UnicodeClass; }
-               }
-
-               public bool IsAutoClass
-               {
-                       get { return (Attributes & TypeAttributes.StringFormatMask) == TypeAttributes.AutoClass; }
-               }
-
-               public bool IsAutoLayout
-               {
-                       get { return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.AutoLayout; }
-               }
-
-               public bool IsLayoutSequential
-               {
-                       get { return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.SequentialLayout; }
-               }
-
-               public bool IsExplicitLayout
-               {
-                       get { return (Attributes & TypeAttributes.LayoutMask) == TypeAttributes.ExplicitLayout; }
-               }
-
-               public bool IsSpecialName
-               {
-                       get { return (Attributes & TypeAttributes.SpecialName) != 0; }
-               }
-
-               public bool IsSerializable
-               {
-                       get { return (Attributes & TypeAttributes.Serializable) != 0; }
-               }
-
-               public bool IsClass
-               {
-                       get { return !IsInterface && !IsValueType; }
-               }
-
-               public bool IsInterface
-               {
-                       get { return (Attributes & TypeAttributes.Interface) != 0; }
-               }
-
-               public bool IsNested
-               {
-                       // FXBUG we check the declaring type (like .NET) and this results
-                       // in IsNested returning true for a generic type parameter
-                       get { return this.DeclaringType != null; }
-               }
-
-               public virtual bool __ContainsMissingType
-               {
-                       get
-                       {
-                               if (this.__IsMissing)
-                               {
-                                       return true;
-                               }
-                               foreach (Type arg in this.GetGenericArguments())
-                               {
-                                       if (arg.__ContainsMissingType)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               public Type MakeArrayType()
-               {
-                       return ArrayType.Make(this, new CustomModifiers());
-               }
-
-               public Type __MakeArrayType(CustomModifiers customModifiers)
-               {
-                       return ArrayType.Make(this, customModifiers);
-               }
-
-               [Obsolete("Please use __MakeArrayType(CustomModifiers) instead.")]
-               public Type __MakeArrayType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __MakeArrayType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public Type MakeArrayType(int rank)
-               {
-                       return __MakeArrayType(rank, new CustomModifiers());
-               }
-
-               public Type __MakeArrayType(int rank, CustomModifiers customModifiers)
-               {
-                       return MultiArrayType.Make(this, rank, Empty<int>.Array, new int[rank], customModifiers);
-               }
-
-               [Obsolete("Please use __MakeArrayType(int, CustomModifiers) instead.")]
-               public Type __MakeArrayType(int rank, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __MakeArrayType(rank, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public Type __MakeArrayType(int rank, int[] sizes, int[] lobounds, CustomModifiers customModifiers)
-               {
-                       return MultiArrayType.Make(this, rank, sizes ?? Empty<int>.Array, lobounds ?? Empty<int>.Array, customModifiers);
-               }
-
-               [Obsolete("Please use __MakeArrayType(int, int[], int[], CustomModifiers) instead.")]
-               public Type __MakeArrayType(int rank, int[] sizes, int[] lobounds, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __MakeArrayType(rank, sizes, lobounds, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public Type MakeByRefType()
-               {
-                       return ByRefType.Make(this, new CustomModifiers());
-               }
-
-               public Type __MakeByRefType(CustomModifiers customModifiers)
-               {
-                       return ByRefType.Make(this, customModifiers);
-               }
-
-               [Obsolete("Please use __MakeByRefType(CustomModifiers) instead.")]
-               public Type __MakeByRefType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __MakeByRefType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public Type MakePointerType()
-               {
-                       return PointerType.Make(this, new CustomModifiers());
-               }
-
-               public Type __MakePointerType(CustomModifiers customModifiers)
-               {
-                       return PointerType.Make(this, customModifiers);
-               }
-
-               [Obsolete("Please use __MakeByRefType(CustomModifiers) instead.")]
-               public Type __MakePointerType(Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __MakePointerType(CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public Type MakeGenericType(params Type[] typeArguments)
-               {
-                       return __MakeGenericType(typeArguments, null);
-               }
-
-               public Type __MakeGenericType(Type[] typeArguments, CustomModifiers[] customModifiers)
-               {
-                       if (!this.__IsMissing && !this.IsGenericTypeDefinition)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       return GenericTypeInstance.Make(this, Util.Copy(typeArguments), customModifiers == null ? null : (CustomModifiers[])customModifiers.Clone());
-               }
-
-               [Obsolete("Please use __MakeGenericType(Type[], CustomModifiers[]) instead.")]
-               public Type __MakeGenericType(Type[] typeArguments, Type[][] requiredCustomModifiers, Type[][] optionalCustomModifiers)
-               {
-                       if (!this.__IsMissing && !this.IsGenericTypeDefinition)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       CustomModifiers[] mods = null;
-                       if (requiredCustomModifiers != null || optionalCustomModifiers != null)
-                       {
-                               mods = new CustomModifiers[typeArguments.Length];
-                               for (int i = 0; i < mods.Length; i++)
-                               {
-                                       mods[i] = CustomModifiers.FromReqOpt(Util.NullSafeElementAt(requiredCustomModifiers, i), Util.NullSafeElementAt(optionalCustomModifiers, i));
-                               }
-                       }
-                       return GenericTypeInstance.Make(this, Util.Copy(typeArguments), mods);
-               }
-
-               public static System.Type __GetSystemType(TypeCode typeCode)
-               {
-                       switch (typeCode)
-                       {
-                               case TypeCode.Boolean:
-                                       return typeof(System.Boolean);
-                               case TypeCode.Byte:
-                                       return typeof(System.Byte);
-                               case TypeCode.Char:
-                                       return typeof(System.Char);
-                               case TypeCode.DBNull:
-                                       return typeof(System.DBNull);
-                               case TypeCode.DateTime:
-                                       return typeof(System.DateTime);
-                               case TypeCode.Decimal:
-                                       return typeof(System.Decimal);
-                               case TypeCode.Double:
-                                       return typeof(System.Double);
-                               case TypeCode.Empty:
-                                       return null;
-                               case TypeCode.Int16:
-                                       return typeof(System.Int16);
-                               case TypeCode.Int32:
-                                       return typeof(System.Int32);
-                               case TypeCode.Int64:
-                                       return typeof(System.Int64);
-                               case TypeCode.Object:
-                                       return typeof(System.Object);
-                               case TypeCode.SByte:
-                                       return typeof(System.SByte);
-                               case TypeCode.Single:
-                                       return typeof(System.Single);
-                               case TypeCode.String:
-                                       return typeof(System.String);
-                               case TypeCode.UInt16:
-                                       return typeof(System.UInt16);
-                               case TypeCode.UInt32:
-                                       return typeof(System.UInt32);
-                               case TypeCode.UInt64:
-                                       return typeof(System.UInt64);
-                               default:
-                                       throw new ArgumentOutOfRangeException();
-                       }
-               }
-
-               public static TypeCode GetTypeCode(Type type)
-               {
-                       if (type == null)
-                       {
-                               return TypeCode.Empty;
-                       }
-                       if (!type.__IsMissing && type.IsEnum)
-                       {
-                               type = type.GetEnumUnderlyingType();
-                       }
-                       Universe u = type.Module.universe;
-                       if (type == u.System_Boolean)
-                       {
-                               return TypeCode.Boolean;
-                       }
-                       else if (type == u.System_Char)
-                       {
-                               return TypeCode.Char;
-                       }
-                       else if (type == u.System_SByte)
-                       {
-                               return TypeCode.SByte;
-                       }
-                       else if (type == u.System_Byte)
-                       {
-                               return TypeCode.Byte;
-                       }
-                       else if (type == u.System_Int16)
-                       {
-                               return TypeCode.Int16;
-                       }
-                       else if (type == u.System_UInt16)
-                       {
-                               return TypeCode.UInt16;
-                       }
-                       else if (type == u.System_Int32)
-                       {
-                               return TypeCode.Int32;
-                       }
-                       else if (type == u.System_UInt32)
-                       {
-                               return TypeCode.UInt32;
-                       }
-                       else if (type == u.System_Int64)
-                       {
-                               return TypeCode.Int64;
-                       }
-                       else if (type == u.System_UInt64)
-                       {
-                               return TypeCode.UInt64;
-                       }
-                       else if (type == u.System_Single)
-                       {
-                               return TypeCode.Single;
-                       }
-                       else if (type == u.System_Double)
-                       {
-                               return TypeCode.Double;
-                       }
-                       else if (type == u.System_DateTime)
-                       {
-                               return TypeCode.DateTime;
-                       }
-                       else if (type == u.System_DBNull)
-                       {
-                               return TypeCode.DBNull;
-                       }
-                       else if (type == u.System_Decimal)
-                       {
-                               return TypeCode.Decimal;
-                       }
-                       else if (type == u.System_String)
-                       {
-                               return TypeCode.String;
-                       }
-                       else if (type.__IsMissing)
-                       {
-                               throw new MissingMemberException(type);
-                       }
-                       else
-                       {
-                               return TypeCode.Object;
-                       }
-               }
-
-               public Assembly Assembly
-               {
-                       get { return Module.Assembly; }
-               }
-
-               public bool IsAssignableFrom(Type type)
-               {
-                       if (this.Equals(type))
-                       {
-                               return true;
-                       }
-                       else if (type == null)
-                       {
-                               return false;
-                       }
-                       else if (this.IsArray && type.IsArray)
-                       {
-                               if (this.GetArrayRank() != type.GetArrayRank())
-                               {
-                                       return false;
-                               }
-                               else if (this.__IsVector && !type.__IsVector)
-                               {
-                                       return false;
-                               }
-                               Type e1 = this.GetElementType();
-                               Type e2 = type.GetElementType();
-                               return e1.IsValueType == e2.IsValueType && e1.IsAssignableFrom(e2);
-                       }
-                       else if (this.IsCovariant(type))
-                       {
-                               return true;
-                       }
-                       else if (this.IsSealed)
-                       {
-                               return false;
-                       }
-                       else if (this.IsInterface)
-                       {
-                               foreach (Type iface in type.GetInterfaces())
-                               {
-                                       if (this.Equals(iface) || this.IsCovariant(iface))
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-                       else if (type.IsInterface)
-                       {
-                               return this == this.Module.universe.System_Object;
-                       }
-                       else if (type.IsPointer)
-                       {
-                               return this == this.Module.universe.System_Object || this == this.Module.universe.System_ValueType;
-                       }
-                       else
-                       {
-                               return type.IsSubclassOf(this);
-                       }
-               }
-
-               private bool IsCovariant(Type other)
-               {
-                       if (this.IsConstructedGenericType
-                               && other.IsConstructedGenericType
-                               && this.GetGenericTypeDefinition() == other.GetGenericTypeDefinition())
-                       {
-                               Type[] typeParameters = GetGenericTypeDefinition().GetGenericArguments();
-                               for (int i = 0; i < typeParameters.Length; i++)
-                               {
-                                       Type t1 = this.GetGenericTypeArgument(i);
-                                       Type t2 = other.GetGenericTypeArgument(i);
-                                       if (t1.IsValueType != t2.IsValueType)
-                                       {
-                                               return false;
-                                       }
-                                       switch (typeParameters[i].GenericParameterAttributes & GenericParameterAttributes.VarianceMask)
-                                       {
-                                               case GenericParameterAttributes.Covariant:
-                                                       if (!t1.IsAssignableFrom(t2))
-                                                       {
-                                                               return false;
-                                                       }
-                                                       break;
-                                               case GenericParameterAttributes.Contravariant:
-                                                       if (!t2.IsAssignableFrom(t1))
-                                                       {
-                                                               return false;
-                                                       }
-                                                       break;
-                                               case GenericParameterAttributes.None:
-                                                       if (t1 != t2)
-                                                       {
-                                                               return false;
-                                                       }
-                                                       break;
-                                       }
-                               }
-                               return true;
-                       }
-                       return false;
-               }
-
-               public bool IsSubclassOf(Type type)
-               {
-                       Type thisType = this.BaseType;
-                       while (thisType != null)
-                       {
-                               if (thisType.Equals(type))
-                               {
-                                       return true;
-                               }
-                               thisType = thisType.BaseType;
-                       }
-                       return false;
-               }
-
-               // This returns true if this type directly (i.e. not inherited from the base class) implements the interface.
-               // Note that a complicating factor is that the interface itself can be implemented by an interface that extends it.
-               private bool IsDirectlyImplementedInterface(Type interfaceType)
-               {
-                       foreach (Type iface in __GetDeclaredInterfaces())
-                       {
-                               if (interfaceType.IsAssignableFrom(iface))
-                               {
-                                       return true;
-                               }
-                       }
-                       return false;
-               }
-
-               public InterfaceMapping GetInterfaceMap(Type interfaceType)
-               {
-                       CheckBaked();
-                       InterfaceMapping map = new InterfaceMapping();
-                       if (!IsDirectlyImplementedInterface(interfaceType))
-                       {
-                               Type baseType = this.BaseType;
-                               if (baseType == null)
-                               {
-                                       throw new ArgumentException();
-                               }
-                               else
-                               {
-                                       map = baseType.GetInterfaceMap(interfaceType);
-                               }
-                       }
-                       else
-                       {
-                               map.InterfaceMethods = interfaceType.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
-                               map.InterfaceType = interfaceType;
-                               map.TargetMethods = new MethodInfo[map.InterfaceMethods.Length];
-                               FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
-                               MethodInfo[] methods = GetMethods(BindingFlags.Instance | BindingFlags.Public);
-                               for (int i = 0; i < map.TargetMethods.Length; i++)
-                               {
-                                       if (map.TargetMethods[i] == null)
-                                       {
-                                               // TODO use proper method resolution (also take into account that no implicit base class implementation is used across assembly boundaries)
-                                               for (int j = 0; j < methods.Length; j++)
-                                               {
-                                                       if (methods[j].Name == map.InterfaceMethods[i].Name
-                                                               && methods[j].MethodSignature.Equals(map.InterfaceMethods[i].MethodSignature))
-                                                       {
-                                                               map.TargetMethods[i] = methods[j];
-                                                       }
-                                               }
-                                       }
-                               }
-                               for (Type baseType = this.BaseType; baseType != null && interfaceType.IsAssignableFrom(baseType); baseType = baseType.BaseType)
-                               {
-                                       baseType.FillInExplicitInterfaceMethods(map.InterfaceMethods, map.TargetMethods);
-                               }
-                       }
-                       map.TargetType = this;
-                       return map;
-               }
-
-               internal void FillInExplicitInterfaceMethods(MethodInfo[] interfaceMethods, MethodInfo[] targetMethods)
-               {
-                       __MethodImplMap impl = __GetMethodImplMap();
-                       for (int i = 0; i < impl.MethodDeclarations.Length; i++)
-                       {
-                               for (int j = 0; j < impl.MethodDeclarations[i].Length; j++)
-                               {
-                                       int index = Array.IndexOf(interfaceMethods, impl.MethodDeclarations[i][j]);
-                                       if (index != -1 && targetMethods[index] == null)
-                                       {
-                                               targetMethods[index] = impl.MethodBodies[i];
-                                       }
-                               }
-                       }
-               }
-
-               Type IGenericContext.GetGenericTypeArgument(int index)
-               {
-                       return GetGenericTypeArgument(index);
-               }
-
-               Type IGenericContext.GetGenericMethodArgument(int index)
-               {
-                       throw new BadImageFormatException();
-               }
-
-               Type IGenericBinder.BindTypeParameter(Type type)
-               {
-                       return GetGenericTypeArgument(type.GenericParameterPosition);
-               }
-
-               Type IGenericBinder.BindMethodParameter(Type type)
-               {
-                       throw new BadImageFormatException();
-               }
-
-               internal virtual Type BindTypeParameters(IGenericBinder binder)
-               {
-                       if (IsGenericTypeDefinition)
-                       {
-                               Type[] args = GetGenericArguments();
-                               Type.InplaceBindTypeParameters(binder, args);
-                               return GenericTypeInstance.Make(this, args, null);
-                       }
-                       else
-                       {
-                               return this;
-                       }
-               }
-
-               private static void InplaceBindTypeParameters(IGenericBinder binder, Type[] types)
-               {
-                       for (int i = 0; i < types.Length; i++)
-                       {
-                               types[i] = types[i].BindTypeParameters(binder);
-                       }
-               }
-
-               internal virtual MethodBase FindMethod(string name, MethodSignature signature)
-               {
-                       foreach (MethodBase method in __GetDeclaredMethods())
-                       {
-                               if (method.Name == name && method.MethodSignature.Equals(signature))
-                               {
-                                       return method;
-                               }
-                       }
-                       return null;
-               }
-
-               internal virtual FieldInfo FindField(string name, FieldSignature signature)
-               {
-                       foreach (FieldInfo field in __GetDeclaredFields())
-                       {
-                               if (field.Name == name && field.FieldSignature.Equals(signature))
-                               {
-                                       return field;
-                               }
-                       }
-                       return null;
-               }
-
-               internal bool IsAllowMultipleCustomAttribute
-               {
-                       get
-                       {
-                               IList<CustomAttributeData> cad = CustomAttributeData.__GetCustomAttributes(this, this.Module.universe.System_AttributeUsageAttribute, false);
-                               if (cad.Count == 1)
-                               {
-                                       foreach (CustomAttributeNamedArgument arg in cad[0].NamedArguments)
-                                       {
-                                               if (arg.MemberInfo.Name == "AllowMultiple")
-                                               {
-                                                       return (bool)arg.TypedValue.Value;
-                                               }
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               internal bool IsPseudoCustomAttribute
-               {
-                       get
-                       {
-                               Universe u = this.Module.universe;
-                               return this == u.System_NonSerializedAttribute
-                                       || this == u.System_SerializableAttribute
-                                       || this == u.System_Runtime_InteropServices_DllImportAttribute
-                                       || this == u.System_Runtime_InteropServices_FieldOffsetAttribute
-                                       || this == u.System_Runtime_InteropServices_InAttribute
-                                       || this == u.System_Runtime_InteropServices_MarshalAsAttribute
-                                       || this == u.System_Runtime_InteropServices_OutAttribute
-                                       || this == u.System_Runtime_InteropServices_StructLayoutAttribute
-                                       || this == u.System_Runtime_InteropServices_OptionalAttribute
-                                       || this == u.System_Runtime_InteropServices_PreserveSigAttribute
-                                       || this == u.System_Runtime_InteropServices_ComImportAttribute
-                                       || this == u.System_Runtime_CompilerServices_SpecialNameAttribute
-                                       || this == u.System_Runtime_CompilerServices_MethodImplAttribute
-                                       ;
-                       }
-               }
-
-               internal Type MarkNotValueType()
-               {
-                       typeFlags |= TypeFlags.NotValueType;
-                       return this;
-               }
-
-               internal Type MarkValueType()
-               {
-                       typeFlags |= TypeFlags.ValueType;
-                       return this;
-               }
-
-               internal ConstructorInfo GetPseudoCustomAttributeConstructor(params Type[] parameterTypes)
-               {
-                       Universe u = this.Module.universe;
-                       MethodSignature methodSig = MethodSignature.MakeFromBuilder(u.System_Void, parameterTypes, new PackedCustomModifiers(), CallingConventions.Standard | CallingConventions.HasThis, 0);
-                       MethodBase mb =
-                               FindMethod(".ctor", methodSig) ??
-                               u.GetMissingMethodOrThrow(this, ".ctor", methodSig);
-                       return (ConstructorInfo)mb;
-               }
-
-               public MethodBase __CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, parameterTypes.Length));
-               }
-
-               private MethodBase CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, Type[] parameterTypes, PackedCustomModifiers customModifiers)
-               {
-                       MethodSignature sig = new MethodSignature(
-                               returnType ?? this.Module.universe.System_Void,
-                               Util.Copy(parameterTypes),
-                               customModifiers,
-                               callingConvention,
-                               0);
-                       MethodInfo method = new MissingMethod(this, name, sig);
-                       if (name == ".ctor" || name == ".cctor")
-                       {
-                               return new ConstructorInfoImpl(method);
-                       }
-                       return method;
-               }
-
-               [Obsolete("Please use __CreateMissingMethod(string, CallingConventions, Type, CustomModifiers, Type[], CustomModifiers[]) instead")]
-               public MethodBase __CreateMissingMethod(string name, CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
-               {
-                       return CreateMissingMethod(name, callingConvention, returnType, parameterTypes, PackedCustomModifiers.CreateFromExternal(returnTypeOptionalCustomModifiers, returnTypeRequiredCustomModifiers, parameterTypeOptionalCustomModifiers, parameterTypeRequiredCustomModifiers, parameterTypes.Length));
-               }
-
-               public FieldInfo __CreateMissingField(string name, Type fieldType, CustomModifiers customModifiers)
-               {
-                       return new MissingField(this, name, FieldSignature.Create(fieldType, customModifiers));
-               }
-
-               [Obsolete("Please use __CreateMissingField(string, Type, CustomModifiers) instead")]
-               public FieldInfo __CreateMissingField(string name, Type fieldType, Type[] requiredCustomModifiers, Type[] optionalCustomModifiers)
-               {
-                       return __CreateMissingField(name, fieldType, CustomModifiers.FromReqOpt(requiredCustomModifiers, optionalCustomModifiers));
-               }
-
-               public PropertyInfo __CreateMissingProperty(string name, CallingConventions callingConvention, Type propertyType, CustomModifiers propertyTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       PropertySignature sig = PropertySignature.Create(callingConvention,
-                               propertyType,
-                               parameterTypes,
-                               PackedCustomModifiers.CreateFromExternal(propertyTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
-                       return new MissingProperty(this, name, sig);
-               }
-
-               internal virtual Type SetMetadataTokenForMissing(int token, int flags)
-               {
-                       return this;
-               }
-
-               protected void MarkEnumOrValueType(string typeNamespace, string typeName)
-               {
-                       // we assume that mscorlib won't have nested types with these names,
-                       // so we don't check that we're not a nested type
-                       if (typeNamespace == "System"
-                               && (typeName == "Enum" || typeName == "ValueType"))
-                       {
-                               typeFlags |= TypeFlags.PotentialEnumOrValueType;
-                       }
-               }
-
-               private bool ResolvePotentialEnumOrValueType()
-               {
-                       if (this.Assembly == this.Universe.Mscorlib
-                               || this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase)
-                               // check if mscorlib forwards the type (.NETCore profile reference mscorlib forwards System.Enum and System.ValueType to System.Runtime.dll)
-                               || this.Universe.Mscorlib.FindType(new TypeName(__Namespace, __Name)) == this)
-                       {
-                               typeFlags = (typeFlags & ~TypeFlags.PotentialEnumOrValueType) | TypeFlags.EnumOrValueType;
-                               return true;
-                       }
-                       else
-                       {
-                               typeFlags &= ~TypeFlags.PotentialEnumOrValueType;
-                               return false;
-                       }
-               }
-
-               private bool IsEnumOrValueType
-               {
-                       get
-                       {
-                               return (typeFlags & (TypeFlags.EnumOrValueType | TypeFlags.PotentialEnumOrValueType)) != 0
-                                       && ((typeFlags & TypeFlags.EnumOrValueType) != 0 || ResolvePotentialEnumOrValueType());
-                       }
-               }
-
-               internal virtual Universe Universe
-               {
-                       get { return Module.universe; }
-               }
-
-               internal sealed override bool BindingFlagsMatch(BindingFlags flags)
-               {
-                       return BindingFlagsMatch(IsNestedPublic, flags, BindingFlags.Public, BindingFlags.NonPublic);
-               }
-
-               internal sealed override MemberInfo SetReflectedType(Type type)
-               {
-                       throw new InvalidOperationException();
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return this.MetadataToken;
-               }
-
-               internal sealed override List<CustomAttributeData> GetPseudoCustomAttributes(Type attributeType)
-               {
-                       // types don't have pseudo custom attributes
-                       return null;
-               }
-
-               // in .NET this is an extension method, but we target .NET 2.0, so we have an instance method
-               public TypeInfo GetTypeInfo()
-               {
-                       TypeInfo type = this as TypeInfo;
-                       if (type == null)
-                       {
-                               throw new MissingMemberException(this);
-                       }
-                       return type;
-               }
-
-               public virtual bool __IsTypeForwarder
-               {
-                       get { return false; }
-               }
-       }
-
-       abstract class ElementHolderType : TypeInfo
-       {
-               protected readonly Type elementType;
-               private int token;
-               private readonly CustomModifiers mods;
-
-               protected ElementHolderType(Type elementType, CustomModifiers mods)
-               {
-                       this.elementType = elementType;
-                       this.mods = mods;
-               }
-
-               protected bool EqualsHelper(ElementHolderType other)
-               {
-                       return other != null
-                               && other.elementType.Equals(elementType)
-                               && other.mods.Equals(mods);
-               }
-
-               public override CustomModifiers __GetCustomModifiers()
-               {
-                       return mods;
-               }
-
-               public sealed override string Name
-               {
-                       get { return elementType.Name + GetSuffix(); }
-               }
-
-               public sealed override string Namespace
-               {
-                       get { return elementType.Namespace; }
-               }
-
-               public sealed override string FullName
-               {
-                       get { return elementType.FullName + GetSuffix(); }
-               }
-
-               public sealed override string ToString()
-               {
-                       return elementType.ToString() + GetSuffix();
-               }
-
-               public sealed override Type GetElementType()
-               {
-                       return elementType;
-               }
-
-               public sealed override bool HasElementType
-               {
-                       get { return true; }
-               }
-
-               public sealed override Module Module
-               {
-                       get { return elementType.Module; }
-               }
-
-               internal sealed override int GetModuleBuilderToken()
-               {
-                       if (token == 0)
-                       {
-                               token = ((ModuleBuilder)elementType.Module).ImportType(this);
-                       }
-                       return token;
-               }
-
-               public sealed override bool ContainsGenericParameters
-               {
-                       get
-                       {
-                               Type type = elementType;
-                               while (type.HasElementType)
-                               {
-                                       type = type.GetElementType();
-                               }
-                               return type.ContainsGenericParameters;
-                       }
-               }
-
-               public sealed override bool __ContainsMissingType
-               {
-                       get
-                       {
-                               Type type = elementType;
-                               while (type.HasElementType)
-                               {
-                                       type = type.GetElementType();
-                               }
-                               return type.__ContainsMissingType;
-                       }
-               }
-
-               internal sealed override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       Type type = elementType.BindTypeParameters(binder);
-                       CustomModifiers mods = this.mods.Bind(binder);
-                       if (ReferenceEquals(type, elementType)
-                               && mods.Equals(this.mods))
-                       {
-                               return this;
-                       }
-                       return Wrap(type, mods);
-               }
-
-               internal override void CheckBaked()
-               {
-                       elementType.CheckBaked();
-               }
-
-               internal sealed override Universe Universe
-               {
-                       get { return elementType.Universe; }
-               }
-
-               internal sealed override bool IsBaked
-               {
-                       get { return elementType.IsBaked; }
-               }
-
-               internal sealed override int GetCurrentToken()
-               {
-                       // we don't have a token, so we return 0 (which is never a valid token)
-                       return 0;
-               }
-
-               internal abstract string GetSuffix();
-
-               protected abstract Type Wrap(Type type, CustomModifiers mods);
-       }
-
-       sealed class ArrayType : ElementHolderType
-       {
-               internal static Type Make(Type type, CustomModifiers mods)
-               {
-                       return type.Universe.CanonicalizeType(new ArrayType(type, mods));
-               }
-
-               private ArrayType(Type type, CustomModifiers mods)
-                       : base(type, mods)
-               {
-               }
-
-               public override Type BaseType
-               {
-                       get { return elementType.Module.universe.System_Array; }
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       return new Type[] {
-                               this.Module.universe.Import(typeof(IList<>)).MakeGenericType(elementType),
-                               this.Module.universe.Import(typeof(ICollection<>)).MakeGenericType(elementType),
-                               this.Module.universe.Import(typeof(IEnumerable<>)).MakeGenericType(elementType)
-                       };
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       Type[] int32 = new Type[] { this.Module.universe.System_Int32 };
-                       List<MethodBase> list = new List<MethodBase>();
-                       list.Add(new BuiltinArrayMethod(this.Module, this, "Set", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, new Type[] { this.Module.universe.System_Int32, elementType }));
-                       list.Add(new BuiltinArrayMethod(this.Module, this, "Address", CallingConventions.Standard | CallingConventions.HasThis, elementType.MakeByRefType(), int32));
-                       list.Add(new BuiltinArrayMethod(this.Module, this, "Get", CallingConventions.Standard | CallingConventions.HasThis, elementType, int32));
-                       list.Add(new ConstructorInfoImpl(new BuiltinArrayMethod(this.Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, int32)));
-                       for (Type type = elementType; type.__IsVector; type = type.GetElementType())
-                       {
-                               Array.Resize(ref int32, int32.Length + 1);
-                               int32[int32.Length - 1] = int32[0];
-                               list.Add(new ConstructorInfoImpl(new BuiltinArrayMethod(this.Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, int32)));
-                       }
-                       return list.ToArray();
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Serializable; }
-               }
-
-               public override bool IsArray
-               {
-                       get { return true; }
-               }
-
-               public override bool __IsVector
-               {
-                       get { return true; }
-               }
-
-               public override int GetArrayRank()
-               {
-                       return 1;
-               }
-
-               public override bool Equals(object o)
-               {
-                       return EqualsHelper(o as ArrayType);
-               }
-
-               public override int GetHashCode()
-               {
-                       return elementType.GetHashCode() * 5;
-               }
-
-               internal override string GetSuffix()
-               {
-                       return "[]";
-               }
-
-               protected override Type Wrap(Type type, CustomModifiers mods)
-               {
-                       return Make(type, mods);
-               }
-       }
-
-       sealed class MultiArrayType : ElementHolderType
-       {
-               private readonly int rank;
-               private readonly int[] sizes;
-               private readonly int[] lobounds;
-
-               internal static Type Make(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods)
-               {
-                       return type.Universe.CanonicalizeType(new MultiArrayType(type, rank, sizes, lobounds, mods));
-               }
-
-               private MultiArrayType(Type type, int rank, int[] sizes, int[] lobounds, CustomModifiers mods)
-                       : base(type, mods)
-               {
-                       this.rank = rank;
-                       this.sizes = sizes;
-                       this.lobounds = lobounds;
-               }
-
-               public override Type BaseType
-               {
-                       get { return elementType.Module.universe.System_Array; }
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       Type int32 = this.Module.universe.System_Int32;
-                       Type[] setArgs = new Type[rank + 1];
-                       Type[] getArgs = new Type[rank];
-                       Type[] ctorArgs = new Type[rank * 2];
-                       for (int i = 0; i < rank; i++)
-                       {
-                               setArgs[i] = int32;
-                               getArgs[i] = int32;
-                               ctorArgs[i * 2 + 0] = int32;
-                               ctorArgs[i * 2 + 1] = int32;
-                       }
-                       setArgs[rank] = elementType;
-                       return new MethodBase[] {
-                               new ConstructorInfoImpl(new BuiltinArrayMethod(this.Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, getArgs)),
-                               new ConstructorInfoImpl(new BuiltinArrayMethod(this.Module, this, ".ctor", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, ctorArgs)),
-                               new BuiltinArrayMethod(this.Module, this, "Set", CallingConventions.Standard | CallingConventions.HasThis, this.Module.universe.System_Void, setArgs),
-                               new BuiltinArrayMethod(this.Module, this, "Address", CallingConventions.Standard | CallingConventions.HasThis, elementType.MakeByRefType(), getArgs),
-                               new BuiltinArrayMethod(this.Module, this, "Get", CallingConventions.Standard | CallingConventions.HasThis, elementType, getArgs),
-                       };
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Serializable; }
-               }
-
-               public override bool IsArray
-               {
-                       get { return true; }
-               }
-
-               public override int GetArrayRank()
-               {
-                       return rank;
-               }
-
-               public override int[] __GetArraySizes()
-               {
-                       return Util.Copy(sizes);
-               }
-
-               public override int[] __GetArrayLowerBounds()
-               {
-                       return Util.Copy(lobounds);
-               }
-
-               public override bool Equals(object o)
-               {
-                       MultiArrayType at = o as MultiArrayType;
-                       return EqualsHelper(at)
-                               && at.rank == rank
-                               && ArrayEquals(at.sizes, sizes)
-                               && ArrayEquals(at.lobounds, lobounds);
-               }
-
-               private static bool ArrayEquals(int[] i1, int[] i2)
-               {
-                       if (i1.Length == i2.Length)
-                       {
-                               for (int i = 0; i < i1.Length; i++)
-                               {
-                                       if (i1[i] != i2[i])
-                                       {
-                                               return false;
-                                       }
-                               }
-                               return true;
-                       }
-                       return false;
-               }
-
-               public override int GetHashCode()
-               {
-                       return elementType.GetHashCode() * 9 + rank;
-               }
-
-               internal override string GetSuffix()
-               {
-                       if (rank == 1)
-                       {
-                               return "[*]";
-                       }
-                       else
-                       {
-                               return "[" + new String(',', rank - 1) + "]";
-                       }
-               }
-
-               protected override Type Wrap(Type type, CustomModifiers mods)
-               {
-                       return Make(type, rank, sizes, lobounds, mods);
-               }
-       }
-
-       sealed class BuiltinArrayMethod : ArrayMethod
-       {
-               internal BuiltinArrayMethod(Module module, Type arrayClass, string methodName, CallingConventions callingConvention, Type returnType, Type[] parameterTypes)
-                       : base(module, arrayClass, methodName, callingConvention, returnType, parameterTypes)
-               {
-               }
-
-               public override MethodAttributes Attributes
-               {
-                       get { return this.Name == ".ctor" ? MethodAttributes.RTSpecialName | MethodAttributes.Public : MethodAttributes.Public; }
-               }
-
-               public override MethodImplAttributes GetMethodImplementationFlags()
-               {
-                       return MethodImplAttributes.IL;
-               }
-
-               public override int MetadataToken
-               {
-                       get { return 0x06000000; }
-               }
-
-               public override MethodBody GetMethodBody()
-               {
-                       return null;
-               }
-
-               public override ParameterInfo[] GetParameters()
-               {
-                       ParameterInfo[] parameterInfos = new ParameterInfo[parameterTypes.Length];
-                       for (int i = 0; i < parameterInfos.Length; i++)
-                       {
-                               parameterInfos[i] = new ParameterInfoImpl(this, parameterTypes[i], i);
-                       }
-                       return parameterInfos;
-               }
-
-               public override ParameterInfo ReturnParameter
-               {
-                       get { return new ParameterInfoImpl(this, this.ReturnType, -1); }
-               }
-
-               private sealed class ParameterInfoImpl : ParameterInfo
-               {
-                       private readonly MethodInfo method;
-                       private readonly Type type;
-                       private readonly int pos;
-
-                       internal ParameterInfoImpl(MethodInfo method, Type type, int pos)
-                       {
-                               this.method = method;
-                               this.type = type;
-                               this.pos = pos;
-                       }
-
-                       public override Type ParameterType
-                       {
-                               get { return type; }
-                       }
-
-                       public override string Name
-                       {
-                               get { return null; }
-                       }
-
-                       public override ParameterAttributes Attributes
-                       {
-                               get { return ParameterAttributes.None; }
-                       }
-
-                       public override int Position
-                       {
-                               get { return pos; }
-                       }
-
-                       public override object RawDefaultValue
-                       {
-                               get { return null; }
-                       }
-
-                       public override CustomModifiers __GetCustomModifiers()
-                       {
-                               return new CustomModifiers();
-                       }
-
-                       public override bool __TryGetFieldMarshal(out FieldMarshal fieldMarshal)
-                       {
-                               fieldMarshal = new FieldMarshal();
-                               return false;
-                       }
-
-                       public override MemberInfo Member
-                       {
-                               get { return method.IsConstructor ? (MethodBase)new ConstructorInfoImpl(method) : method; }
-                       }
-
-                       public override int MetadataToken
-                       {
-                               get { return 0x08000000; }
-                       }
-
-                       internal override Module Module
-                       {
-                               get { return method.Module; }
-                       }
-               }
-       }
-
-       sealed class ByRefType : ElementHolderType
-       {
-               internal static Type Make(Type type, CustomModifiers mods)
-               {
-                       return type.Universe.CanonicalizeType(new ByRefType(type, mods));
-               }
-
-               private ByRefType(Type type, CustomModifiers mods)
-                       : base(type, mods)
-               {
-               }
-
-               public override bool Equals(object o)
-               {
-                       return EqualsHelper(o as ByRefType);
-               }
-
-               public override int GetHashCode()
-               {
-                       return elementType.GetHashCode() * 3;
-               }
-
-               public override Type BaseType
-               {
-                       get { return null; }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return 0; }
-               }
-
-               public override bool IsByRef
-               {
-                       get { return true; }
-               }
-
-               internal override string GetSuffix()
-               {
-                       return "&";
-               }
-
-               protected override Type Wrap(Type type, CustomModifiers mods)
-               {
-                       return Make(type, mods);
-               }
-       }
-
-       sealed class PointerType : ElementHolderType
-       {
-               internal static Type Make(Type type, CustomModifiers mods)
-               {
-                       return type.Universe.CanonicalizeType(new PointerType(type, mods));
-               }
-
-               private PointerType(Type type, CustomModifiers mods)
-                       : base(type, mods)
-               {
-               }
-
-               public override bool Equals(object o)
-               {
-                       return EqualsHelper(o as PointerType);
-               }
-
-               public override int GetHashCode()
-               {
-                       return elementType.GetHashCode() * 7;
-               }
-
-               public override Type BaseType
-               {
-                       get { return null; }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return 0; }
-               }
-
-               public override bool IsPointer
-               {
-                       get { return true; }
-               }
-
-               internal override string GetSuffix()
-               {
-                       return "*";
-               }
-
-               protected override Type Wrap(Type type, CustomModifiers mods)
-               {
-                       return Make(type, mods);
-               }
-       }
-
-       sealed class GenericTypeInstance : TypeInfo
-       {
-               private readonly Type type;
-               private readonly Type[] args;
-               private readonly CustomModifiers[] mods;
-               private Type baseType;
-               private int token;
-
-               internal static Type Make(Type type, Type[] typeArguments, CustomModifiers[] mods)
-               {
-                       bool identity = true;
-                       if (type is TypeBuilder || type is BakedType || type.__IsMissing)
-                       {
-                               // a TypeBuiler identity must be instantiated
-                               identity = false;
-                       }
-                       else
-                       {
-                               // we must not instantiate the identity instance, because typeof(Foo<>).MakeGenericType(typeof(Foo<>).GetGenericArguments()) == typeof(Foo<>)
-                               for (int i = 0; i < typeArguments.Length; i++)
-                               {
-                                       if (typeArguments[i] != type.GetGenericTypeArgument(i)
-                                               || !IsEmpty(mods, i))
-                                       {
-                                               identity = false;
-                                               break;
-                                       }
-                               }
-                       }
-                       if (identity)
-                       {
-                               return type;
-                       }
-                       else
-                       {
-                               return type.Universe.CanonicalizeType(new GenericTypeInstance(type, typeArguments, mods));
-                       }
-               }
-
-               private static bool IsEmpty(CustomModifiers[] mods, int i)
-               {
-                       // we need to be extra careful, because mods doesn't not need to be in canonical format
-                       // (Signature.ReadGenericInst() calls Make() directly, without copying the modifier arrays)
-                       return mods == null || mods[i].IsEmpty;
-               }
-
-               private GenericTypeInstance(Type type, Type[] args, CustomModifiers[] mods)
-               {
-                       this.type = type;
-                       this.args = args;
-                       this.mods = mods;
-               }
-
-               public override bool Equals(object o)
-               {
-                       GenericTypeInstance gt = o as GenericTypeInstance;
-                       return gt != null && gt.type.Equals(type) && Util.ArrayEquals(gt.args, args)
-                               && Util.ArrayEquals(gt.mods, mods);
-               }
-
-               public override int GetHashCode()
-               {
-                       return type.GetHashCode() * 3 ^ Util.GetHashCode(args);
-               }
-
-               public override string AssemblyQualifiedName
-               {
-                       get
-                       {
-                               string fn = FullName;
-                               return fn == null ? null : fn + ", " + type.Assembly.FullName;
-                       }
-               }
-
-               public override Type BaseType
-               {
-                       get
-                       {
-                               if (baseType == null)
-                               {
-                                       Type rawBaseType = type.BaseType;
-                                       if (rawBaseType == null)
-                                       {
-                                               baseType = rawBaseType;
-                                       }
-                                       else
-                                       {
-                                               baseType = rawBaseType.BindTypeParameters(this);
-                                       }
-                               }
-                               return baseType;
-                       }
-               }
-
-               public override bool IsValueType
-               {
-                       get { return type.IsValueType; }
-               }
-
-               public override bool IsVisible
-               {
-                       get
-                       {
-                               if (base.IsVisible)
-                               {
-                                       foreach (Type arg in args)
-                                       {
-                                               if (!arg.IsVisible)
-                                               {
-                                                       return false;
-                                               }
-                                       }
-                                       return true;
-                               }
-                               return false;
-                       }
-               }
-
-               public override Type DeclaringType
-               {
-                       get { return type.DeclaringType; }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return type.Attributes; }
-               }
-
-               internal override void CheckBaked()
-               {
-                       type.CheckBaked();
-               }
-
-               public override FieldInfo[] __GetDeclaredFields()
-               {
-                       FieldInfo[] fields = type.__GetDeclaredFields();
-                       for (int i = 0; i < fields.Length; i++)
-                       {
-                               fields[i] = fields[i].BindTypeParameters(this);
-                       }
-                       return fields;
-               }
-
-               public override Type[] __GetDeclaredInterfaces()
-               {
-                       Type[] interfaces = type.__GetDeclaredInterfaces();
-                       for (int i = 0; i < interfaces.Length; i++)
-                       {
-                               interfaces[i] = interfaces[i].BindTypeParameters(this);
-                       }
-                       return interfaces;
-               }
-
-               public override MethodBase[] __GetDeclaredMethods()
-               {
-                       MethodBase[] methods = type.__GetDeclaredMethods();
-                       for (int i = 0; i < methods.Length; i++)
-                       {
-                               methods[i] = methods[i].BindTypeParameters(this);
-                       }
-                       return methods;
-               }
-
-               public override Type[] __GetDeclaredTypes()
-               {
-                       return type.__GetDeclaredTypes();
-               }
-
-               public override EventInfo[] __GetDeclaredEvents()
-               {
-                       EventInfo[] events = type.__GetDeclaredEvents();
-                       for (int i = 0; i < events.Length; i++)
-                       {
-                               events[i] = events[i].BindTypeParameters(this);
-                       }
-                       return events;
-               }
-
-               public override PropertyInfo[] __GetDeclaredProperties()
-               {
-                       PropertyInfo[] properties = type.__GetDeclaredProperties();
-                       for (int i = 0; i < properties.Length; i++)
-                       {
-                               properties[i] = properties[i].BindTypeParameters(this);
-                       }
-                       return properties;
-               }
-
-               public override __MethodImplMap __GetMethodImplMap()
-               {
-                       __MethodImplMap map = type.__GetMethodImplMap();
-                       map.TargetType = this;
-                       for (int i = 0; i < map.MethodBodies.Length; i++)
-                       {
-                               map.MethodBodies[i] = (MethodInfo)map.MethodBodies[i].BindTypeParameters(this);
-                               for (int j = 0; j < map.MethodDeclarations[i].Length; j++)
-                               {
-                                       Type interfaceType = map.MethodDeclarations[i][j].DeclaringType;
-                                       if (interfaceType.IsGenericType)
-                                       {
-                                               map.MethodDeclarations[i][j] = (MethodInfo)map.MethodDeclarations[i][j].BindTypeParameters(this);
-                                       }
-                               }
-                       }
-                       return map;
-               }
-
-               public override string Namespace
-               {
-                       get { return type.Namespace; }
-               }
-
-               public override string Name
-               {
-                       get { return type.Name; }
-               }
-
-               public override string FullName
-               {
-                       get
-                       {
-                               if (!this.__ContainsMissingType && this.ContainsGenericParameters)
-                               {
-                                       return null;
-                               }
-                               StringBuilder sb = new StringBuilder(this.type.FullName);
-                               sb.Append('[');
-                               string sep = "";
-                               foreach (Type type in args)
-                               {
-                                       sb.Append(sep).Append('[').Append(type.FullName).Append(", ").Append(type.Assembly.FullName.Replace("]", "\\]")).Append(']');
-                                       sep = ",";
-                               }
-                               sb.Append(']');
-                               return sb.ToString();
-                       }
-               }
-
-               public override string ToString()
-               {
-                       StringBuilder sb = new StringBuilder(type.FullName);
-                       sb.Append('[');
-                       string sep = "";
-                       foreach (Type arg in args)
-                       {
-                               sb.Append(sep);
-                               sb.Append(arg);
-                               sep = ",";
-                       }
-                       sb.Append(']');
-                       return sb.ToString();
-               }
-
-               public override Module Module
-               {
-                       get { return type.Module; }
-               }
-
-               public override bool IsGenericType
-               {
-                       get { return true; }
-               }
-
-               public override bool IsConstructedGenericType
-               {
-                       get { return true; }
-               }
-
-               public override Type GetGenericTypeDefinition()
-               {
-                       return type;
-               }
-
-               public override Type[] GetGenericArguments()
-               {
-                       return Util.Copy(args);
-               }
-
-               public override CustomModifiers[] __GetGenericArgumentsCustomModifiers()
-               {
-                       return mods != null ? (CustomModifiers[])mods.Clone() : new CustomModifiers[args.Length];
-               }
-
-               internal override Type GetGenericTypeArgument(int index)
-               {
-                       return args[index];
-               }
-
-               public override bool ContainsGenericParameters
-               {
-                       get
-                       {
-                               foreach (Type type in args)
-                               {
-                                       if (type.ContainsGenericParameters)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return false;
-                       }
-               }
-
-               public override bool __ContainsMissingType
-               {
-                       get
-                       {
-                               foreach (Type type in args)
-                               {
-                                       if (type.__ContainsMissingType)
-                                       {
-                                               return true;
-                                       }
-                               }
-                               return this.type.__IsMissing;
-                       }
-               }
-
-               public override StructLayoutAttribute StructLayoutAttribute
-               {
-                       get { return type.StructLayoutAttribute; }
-               }
-
-               internal override int GetModuleBuilderToken()
-               {
-                       if (token == 0)
-                       {
-                               token = ((ModuleBuilder)type.Module).ImportType(this);
-                       }
-                       return token;
-               }
-
-               internal override Type BindTypeParameters(IGenericBinder binder)
-               {
-                       for (int i = 0; i < args.Length; i++)
-                       {
-                               Type xarg = args[i].BindTypeParameters(binder);
-                               if (!ReferenceEquals(xarg, args[i]))
-                               {
-                                       Type[] xargs = new Type[args.Length];
-                                       Array.Copy(args, xargs, i);
-                                       xargs[i++] = xarg;
-                                       for (; i < args.Length; i++)
-                                       {
-                                               xargs[i] = args[i].BindTypeParameters(binder);
-                                       }
-                                       return Make(type, xargs, null);
-                               }
-                       }
-                       return this;
-               }
-
-               internal override int GetCurrentToken()
-               {
-                       return type.GetCurrentToken();
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return type.IsBaked; }
-               }
-       }
-
-       sealed class FunctionPointerType : TypeInfo
-       {
-               private readonly Universe universe;
-               private readonly __StandAloneMethodSig sig;
-
-               internal static Type Make(Universe universe, __StandAloneMethodSig sig)
-               {
-                       return universe.CanonicalizeType(new FunctionPointerType(universe, sig));
-               }
-
-               private FunctionPointerType(Universe universe, __StandAloneMethodSig sig)
-               {
-                       this.universe = universe;
-                       this.sig = sig;
-               }
-
-               public override bool Equals(object obj)
-               {
-                       FunctionPointerType other = obj as FunctionPointerType;
-                       return other != null
-                               && other.universe == universe
-                               && other.sig.Equals(sig);
-               }
-
-               public override int GetHashCode()
-               {
-                       return sig.GetHashCode();
-               }
-
-               public override bool __IsFunctionPointer
-               {
-                       get { return true; }
-               }
-
-               public override __StandAloneMethodSig __MethodSignature
-               {
-                       get { return sig; }
-               }
-
-               public override Type BaseType
-               {
-                       get { return null; }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { return 0; }
-               }
-
-               public override string Name
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override string FullName
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override Module Module
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               internal override Universe Universe
-               {
-                       get { return universe; }
-               }
-
-               public override string ToString()
-               {
-                       return "<FunctionPtr>";
-               }
-
-               internal override bool IsBaked
-               {
-                       get { return true; }
-               }
-       }
-
-       sealed class MarkerType : Type
-       {
-               // used by CustomModifiers and SignatureHelper
-               internal static readonly Type ModOpt = new MarkerType();
-               internal static readonly Type ModReq = new MarkerType();
-               // used by SignatureHelper
-               internal static readonly Type Sentinel = new MarkerType();
-               internal static readonly Type Pinned = new MarkerType();
-
-               private MarkerType() { }
-
-               public override Type BaseType
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override TypeAttributes Attributes
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override string Name
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override string FullName
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override Module Module
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               internal override bool IsBaked
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-
-               public override bool __IsMissing
-               {
-                       get { throw new InvalidOperationException(); }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/TypeInfo.cs b/mcs/class/IKVM.Reflection/TypeInfo.cs
deleted file mode 100644 (file)
index cd1c1e1..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
-  Copyright (C) 2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-
-namespace IKVM.Reflection
-{
-       public interface IReflectableType
-       {
-               TypeInfo GetTypeInfo();
-       }
-
-       public static class IntrospectionExtensions
-       {
-               // we target .NET 2.0 so we can't define an extension method
-               public static TypeInfo GetTypeInfo(/*this*/ Type type)
-               {
-                       return type.GetTypeInfo();
-               }
-       }
-
-       public abstract class TypeInfo : Type, IReflectableType
-       {
-               private const BindingFlags Flags = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
-
-               internal TypeInfo()
-               {
-               }
-
-               internal TypeInfo(Type underlyingType)
-                       : base(underlyingType)
-               {
-               }
-
-               public IEnumerable<ConstructorInfo> DeclaredConstructors
-               {
-                       get { return GetConstructors(Flags); }
-               }
-
-               public IEnumerable<EventInfo> DeclaredEvents
-               {
-                       get { return GetEvents(Flags); }
-               }
-
-               public IEnumerable<FieldInfo> DeclaredFields
-               {
-                       get { return GetFields(Flags); }
-               }
-
-               public IEnumerable<MemberInfo> DeclaredMembers
-               {
-                       get { return GetMembers(Flags); }
-               }
-
-               public IEnumerable<MethodInfo> DeclaredMethods
-               {
-                       get { return GetMethods(Flags); }
-               }
-
-               public IEnumerable<TypeInfo> DeclaredNestedTypes
-               {
-                       get
-                       {
-                               Type[] types = GetNestedTypes(Flags);
-                               TypeInfo[] typeInfos = new TypeInfo[types.Length];
-                               for (int i = 0; i < types.Length; i++)
-                               {
-                                       typeInfos[i] = types[i].GetTypeInfo();
-                               }
-                               return typeInfos;
-                       }
-               }
-
-               public IEnumerable<PropertyInfo> DeclaredProperties
-               {
-                       get { return GetProperties(Flags); }
-               }
-
-               public Type[] GenericTypeParameters
-               {
-                       get { return IsGenericTypeDefinition ? GetGenericArguments() : Type.EmptyTypes; }
-               }
-
-               public IEnumerable<Type> ImplementedInterfaces
-               {
-                       get { return __GetDeclaredInterfaces(); }
-               }
-
-               public Type AsType()
-               {
-                       return this;
-               }
-
-               public EventInfo GetDeclaredEvent(string name)
-               {
-                       return GetEvent(name, Flags);
-               }
-
-               public FieldInfo GetDeclaredField(string name)
-               {
-                       return GetField(name, Flags);
-               }
-
-               public MethodInfo GetDeclaredMethod(string name)
-               {
-                       return GetMethod(name, Flags);
-               }
-
-               public IEnumerable<MethodInfo> GetDeclaredMethods(string name)
-               {
-                       List<MethodInfo> methods = new List<MethodInfo>();
-                       foreach (MethodInfo method in GetMethods(Flags))
-                       {
-                               if (method.Name == name)
-                               {
-                                       methods.Add(method);
-                               }
-                       }
-                       return methods;
-               }
-
-               public TypeInfo GetDeclaredNestedType(string name)
-               {
-                       return GetNestedType(name, Flags).GetTypeInfo();
-               }
-
-               public PropertyInfo GetDeclaredProperty(string name)
-               {
-                       return GetProperty(name, Flags);
-               }
-
-               public bool IsAssignableFrom(TypeInfo typeInfo)
-               {
-                       return base.IsAssignableFrom(typeInfo);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/TypeNameParser.cs b/mcs/class/IKVM.Reflection/TypeNameParser.cs
deleted file mode 100644 (file)
index 781fe1b..0000000
+++ /dev/null
@@ -1,610 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Text;
-
-namespace IKVM.Reflection
-{
-       // this respresents a type name as in metadata:
-       // - ns will be null for empty the namespace (never the empty string)
-       // - the strings are not escaped
-       struct TypeName : IEquatable<TypeName>
-       {
-               private readonly string ns;
-               private readonly string name;
-
-               internal TypeName(string ns, string name)
-               {
-                       if (name == null)
-                       {
-                               throw new ArgumentNullException("name");
-                       }
-                       this.ns = ns;
-                       this.name = name;
-               }
-
-               internal string Name
-               {
-                       get { return name; }
-               }
-
-               internal string Namespace
-               {
-                       get { return ns; }
-               }
-
-               public static bool operator ==(TypeName o1, TypeName o2)
-               {
-                       return o1.ns == o2.ns && o1.name == o2.name;
-               }
-
-               public static bool operator !=(TypeName o1, TypeName o2)
-               {
-                       return o1.ns != o2.ns || o1.name != o2.name;
-               }
-
-               public override int GetHashCode()
-               {
-                       return ns == null ? name.GetHashCode() : ns.GetHashCode() * 37 + name.GetHashCode();
-               }
-
-               public override bool Equals(object obj)
-               {
-                       TypeName? other = obj as TypeName?;
-                       return other != null && other.Value == this;
-               }
-
-               public override string ToString()
-               {
-                       return ns == null ? name : ns + "." + name;
-               }
-
-               bool IEquatable<TypeName>.Equals(TypeName other)
-               {
-                       return this == other;
-               }
-
-               internal TypeName ToLowerInvariant()
-               {
-                       return new TypeName(ns == null ? null : ns.ToLowerInvariant(), name.ToLowerInvariant());
-               }
-
-               internal static TypeName Split(string name)
-               {
-                       int dot = name.LastIndexOf('.');
-                       if (dot == -1)
-                       {
-                               return new TypeName(null, name);
-                       }
-                       else
-                       {
-                               return new TypeName(name.Substring(0, dot), name.Substring(dot + 1));
-                       }
-               }
-       }
-
-       struct TypeNameParser
-       {
-               private const string SpecialChars = "\\+,[]*&";
-               private const short SZARRAY = -1;
-               private const short BYREF = -2;
-               private const short POINTER = -3;
-               private readonly string name;
-               private readonly string[] nested;
-               private readonly string assemblyName;
-               private readonly short[] modifiers;
-               private readonly TypeNameParser[] genericParameters;
-
-               internal static string Escape(string name)
-               {
-                       if (name == null)
-                       {
-                               return null;
-                       }
-                       StringBuilder sb = null;
-                       for (int pos = 0; pos < name.Length; pos++)
-                       {
-                               char c = name[pos];
-                               switch (c)
-                               {
-                                       case '\\':
-                                       case '+':
-                                       case ',':
-                                       case '[':
-                                       case ']':
-                                       case '*':
-                                       case '&':
-                                               if (sb == null)
-                                               {
-                                                       sb = new StringBuilder(name, 0, pos, name.Length + 3);
-                                               }
-                                               sb.Append("\\").Append(c);
-                                               break;
-                                       default:
-                                               if (sb != null)
-                                               {
-                                                       sb.Append(c);
-                                               }
-                                               break;
-                               }
-                       }
-                       return sb != null ? sb.ToString() : name;
-               }
-
-               internal static string Unescape(string name)
-               {
-                       int pos = name.IndexOf('\\');
-                       if (pos == -1)
-                       {
-                               return name;
-                       }
-                       StringBuilder sb = new StringBuilder(name, 0, pos, name.Length - 1);
-                       for (; pos < name.Length; pos++)
-                       {
-                               char c = name[pos];
-                               if (c == '\\')
-                               {
-                                       c = name[++pos];
-                               }
-                               sb.Append(c);
-                       }
-                       return sb.ToString();
-               }
-
-               internal static TypeNameParser Parse(string typeName, bool throwOnError)
-               {
-                       if (throwOnError)
-                       {
-                               Parser parser = new Parser(typeName);
-                               return new TypeNameParser(ref parser, true);
-                       }
-                       else
-                       {
-                               try
-                               {
-                                       Parser parser = new Parser(typeName);
-                                       return new TypeNameParser(ref parser, true);
-                               }
-                               catch (ArgumentException)
-                               {
-                                       return new TypeNameParser();
-                               }
-                       }
-               }
-
-               private TypeNameParser(ref Parser parser, bool withAssemblyName)
-               {
-                       bool genericParameter = parser.pos != 0;
-                       name = parser.NextNamePart();
-                       nested = null;
-                       parser.ParseNested(ref nested);
-                       genericParameters = null;
-                       parser.ParseGenericParameters(ref genericParameters);
-                       modifiers = null;
-                       parser.ParseModifiers(ref modifiers);
-                       assemblyName = null;
-                       if (withAssemblyName)
-                       {
-                               parser.ParseAssemblyName(genericParameter, ref assemblyName);
-                       }
-               }
-
-               internal bool Error
-               {
-                       get { return name == null; }
-               }
-
-               internal string FirstNamePart
-               {
-                       get { return name; }
-               }
-
-               internal string AssemblyName
-               {
-                       get { return assemblyName; }
-               }
-
-               private struct Parser
-               {
-                       private readonly string typeName;
-                       internal int pos;
-
-                       internal Parser(string typeName)
-                       {
-                               this.typeName = typeName;
-                               this.pos = 0;
-                       }
-
-                       private void Check(bool condition)
-                       {
-                               if (!condition)
-                               {
-                                       throw new ArgumentException("Invalid type name '" + typeName + "'");
-                               }
-                       }
-
-                       private void Consume(char c)
-                       {
-                               Check(pos < typeName.Length && typeName[pos++] == c);
-                       }
-
-                       private bool TryConsume(char c)
-                       {
-                               if (pos < typeName.Length && typeName[pos] == c)
-                               {
-                                       pos++;
-                                       return true;
-                               }
-                               else
-                               {
-                                       return false;
-                               }
-                       }
-
-                       internal string NextNamePart()
-                       {
-                               SkipWhiteSpace();
-                               int start = pos;
-                               for (; pos < typeName.Length; pos++)
-                               {
-                                       char c = typeName[pos];
-                                       if (c == '\\')
-                                       {
-                                               pos++;
-                                               Check(pos < typeName.Length && SpecialChars.IndexOf(typeName[pos]) != -1);
-                                       }
-                                       else if (SpecialChars.IndexOf(c) != -1)
-                                       {
-                                               break;
-                                       }
-                               }
-                               Check(pos - start != 0);
-                               if (start == 0 && pos == typeName.Length)
-                               {
-                                       return typeName;
-                               }
-                               else
-                               {
-                                       return typeName.Substring(start, pos - start);
-                               }
-                       }
-
-                       internal void ParseNested(ref string[] nested)
-                       {
-                               while (TryConsume('+'))
-                               {
-                                       Add(ref nested, NextNamePart());
-                               }
-                       }
-
-                       internal void ParseGenericParameters(ref TypeNameParser[] genericParameters)
-                       {
-                               int saved = pos;
-                               if (TryConsume('['))
-                               {
-                                       SkipWhiteSpace();
-                                       if (TryConsume(']') || TryConsume('*') || TryConsume(','))
-                                       {
-                                               // it's not a generic parameter list, but an array instead
-                                               pos = saved;
-                                               return;
-                                       }
-                                       do
-                                       {
-                                               SkipWhiteSpace();
-                                               if (TryConsume('['))
-                                               {
-                                                       Add(ref genericParameters, new TypeNameParser(ref this, true));
-                                                       Consume(']');
-                                               }
-                                               else
-                                               {
-                                                       Add(ref genericParameters, new TypeNameParser(ref this, false));
-                                               }
-                                       }
-                                       while (TryConsume(','));
-                                       Consume(']');
-                                       SkipWhiteSpace();
-                               }
-                       }
-
-                       internal void ParseModifiers(ref short[] modifiers)
-                       {
-                               while (pos < typeName.Length)
-                               {
-                                       switch (typeName[pos])
-                                       {
-                                               case '*':
-                                                       pos++;
-                                                       Add(ref modifiers, POINTER);
-                                                       break;
-                                               case '&':
-                                                       pos++;
-                                                       Add(ref modifiers, BYREF);
-                                                       break;
-                                               case '[':
-                                                       pos++;
-                                                       Add(ref modifiers, ParseArray());
-                                                       Consume(']');
-                                                       break;
-                                               default:
-                                                       return;
-                                       }
-                                       SkipWhiteSpace();
-                               }
-                       }
-
-                       internal void ParseAssemblyName(bool genericParameter, ref string assemblyName)
-                       {
-                               if (pos < typeName.Length)
-                               {
-                                       if (typeName[pos] == ']' && genericParameter)
-                                       {
-                                               // ok
-                                       }
-                                       else
-                                       {
-                                               Consume(',');
-                                               SkipWhiteSpace();
-                                               if (genericParameter)
-                                               {
-                                                       int start = pos;
-                                                       while (pos < typeName.Length)
-                                                       {
-                                                               char c = typeName[pos];
-                                                               if (c == '\\')
-                                                               {
-                                                                       pos++;
-                                                                       // a backslash itself is not legal in an assembly name, so we don't need to check for an escaped backslash
-                                                                       Check(pos < typeName.Length && typeName[pos++] == ']');
-                                                               }
-                                                               else if (c == ']')
-                                                               {
-                                                                       break;
-                                                               }
-                                                               else
-                                                               {
-                                                                       pos++;
-                                                               }
-                                                       }
-                                                       Check(pos < typeName.Length && typeName[pos] == ']');
-                                                       assemblyName = typeName.Substring(start, pos - start).Replace("\\]", "]");
-                                               }
-                                               else
-                                               {
-                                                       // only when an assembly name is used in a generic type parameter, will it be escaped
-                                                       assemblyName = typeName.Substring(pos);
-                                               }
-                                               Check(assemblyName.Length != 0);
-                                       }
-                               }
-                               else
-                               {
-                                       Check(!genericParameter);
-                               }
-                       }
-
-                       private short ParseArray()
-                       {
-                               SkipWhiteSpace();
-                               Check(pos < typeName.Length);
-                               char c = typeName[pos];
-                               if (c == ']')
-                               {
-                                       return SZARRAY;
-                               }
-                               else if (c == '*')
-                               {
-                                       pos++;
-                                       SkipWhiteSpace();
-                                       return 1;
-                               }
-                               else
-                               {
-                                       short rank = 1;
-                                       while (TryConsume(','))
-                                       {
-                                               Check(rank < short.MaxValue);
-                                               rank++;
-                                               SkipWhiteSpace();
-                                       }
-                                       return rank;
-                               }
-                       }
-
-                       private void SkipWhiteSpace()
-                       {
-                               while (pos < typeName.Length && Char.IsWhiteSpace(typeName[pos]))
-                               {
-                                       pos++;
-                               }
-                       }
-
-                       private static void Add<T>(ref T[] array, T elem)
-                       {
-                               if (array == null)
-                               {
-                                       array = new T[] { elem };
-                                       return;
-                               }
-                               Array.Resize(ref array, array.Length + 1);
-                               array[array.Length - 1] = elem;
-                       }
-               }
-
-               internal Type GetType(Universe universe, Assembly context, bool throwOnError, string originalName, bool resolve, bool ignoreCase)
-               {
-                       Debug.Assert(!resolve || !ignoreCase);
-                       TypeName name = TypeName.Split(this.name);
-                       Type type;
-                       if (assemblyName != null)
-                       {
-                               Assembly asm = universe.Load(assemblyName, context, throwOnError);
-                               if (asm == null)
-                               {
-                                       return null;
-                               }
-                               if (resolve)
-                               {
-                                       type = asm.ResolveType(name);
-                               }
-                               else if (ignoreCase)
-                               {
-                                       type = asm.FindTypeIgnoreCase(name.ToLowerInvariant());
-                               }
-                               else
-                               {
-                                       type = asm.FindType(name);
-                               }
-                       }
-                       else if (context == null)
-                       {
-                               if (resolve)
-                               {
-                                       type = universe.Mscorlib.ResolveType(name);
-                               }
-                               else if (ignoreCase)
-                               {
-                                       type = universe.Mscorlib.FindTypeIgnoreCase(name.ToLowerInvariant());
-                               }
-                               else
-                               {
-                                       type = universe.Mscorlib.FindType(name);
-                               }
-                       }
-                       else
-                       {
-                               if (ignoreCase)
-                               {
-                                       name = name.ToLowerInvariant();
-                                       type = context.FindTypeIgnoreCase(name);
-                               }
-                               else
-                               {
-                                       type = context.FindType(name);
-                               }
-                               if (type == null && context != universe.Mscorlib)
-                               {
-                                       if (ignoreCase)
-                                       {
-                                               type = universe.Mscorlib.FindTypeIgnoreCase(name);
-                                       }
-                                       else
-                                       {
-                                               type = universe.Mscorlib.FindType(name);
-                                       }
-                               }
-                               if (type == null && resolve)
-                               {
-                                       if (universe.Mscorlib.__IsMissing && !context.__IsMissing)
-                                       {
-                                               type = universe.Mscorlib.ResolveType(name);
-                                       }
-                                       else
-                                       {
-                                               type = context.ResolveType(name);
-                                       }
-                               }
-                       }
-                       return Expand(type, context, throwOnError, originalName, resolve, ignoreCase);
-               }
-
-               internal Type Expand(Type type, Assembly context, bool throwOnError, string originalName, bool resolve, bool ignoreCase)
-               {
-                       Debug.Assert(!resolve || !ignoreCase);
-                       if (type == null)
-                       {
-                               if (throwOnError)
-                               {
-                                       throw new TypeLoadException(originalName);
-                               }
-                               return null;
-                       }
-                       if (nested != null)
-                       {
-                               Type outer;
-                               foreach (string nest in nested)
-                               {
-                                       outer = type;
-                                       TypeName name = TypeName.Split(TypeNameParser.Unescape(nest));
-                                       type = ignoreCase
-                                               ? outer.FindNestedTypeIgnoreCase(name.ToLowerInvariant())
-                                               : outer.FindNestedType(name);
-                                       if (type == null)
-                                       {
-                                               if (resolve)
-                                               {
-                                                       type = outer.Module.universe.GetMissingTypeOrThrow(outer.Module, outer, name);
-                                               }
-                                               else if (throwOnError)
-                                               {
-                                                       throw new TypeLoadException(originalName);
-                                               }
-                                               else
-                                               {
-                                                       return null;
-                                               }
-                                       }
-                               }
-                       }
-                       if (genericParameters != null)
-                       {
-                               Type[] typeArgs = new Type[genericParameters.Length];
-                               for (int i = 0; i < typeArgs.Length; i++)
-                               {
-                                       typeArgs[i] = genericParameters[i].GetType(type.Assembly.universe, context, throwOnError, originalName, resolve, ignoreCase);
-                                       if (typeArgs[i] == null)
-                                       {
-                                               return null;
-                                       }
-                               }
-                               type = type.MakeGenericType(typeArgs);
-                       }
-                       if (modifiers != null)
-                       {
-                               foreach (short modifier in modifiers)
-                               {
-                                       switch (modifier)
-                                       {
-                                               case SZARRAY:
-                                                       type = type.MakeArrayType();
-                                                       break;
-                                               case BYREF:
-                                                       type = type.MakeByRefType();
-                                                       break;
-                                               case POINTER:
-                                                       type = type.MakePointerType();
-                                                       break;
-                                               default:
-                                                       type = type.MakeArrayType(modifier);
-                                                       break;
-                                       }
-                               }
-                       }
-                       return type;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Universe.cs b/mcs/class/IKVM.Reflection/Universe.cs
deleted file mode 100644 (file)
index aa3b992..0000000
+++ /dev/null
@@ -1,1110 +0,0 @@
-/*
-  Copyright (C) 2009-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Security;
-using System.Text;
-using System.Diagnostics;
-using IKVM.Reflection.Reader;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection
-{
-       public sealed class ResolveEventArgs : EventArgs
-       {
-               private readonly string name;
-               private readonly Assembly requestingAssembly;
-
-               public ResolveEventArgs(string name)
-                       : this(name, null)
-               {
-               }
-
-               public ResolveEventArgs(string name, Assembly requestingAssembly)
-               {
-                       this.name = name;
-                       this.requestingAssembly = requestingAssembly;
-               }
-
-               public string Name
-               {
-                       get { return name; }
-               }
-
-               public Assembly RequestingAssembly
-               {
-                       get { return requestingAssembly; }
-               }
-       }
-
-       public enum AssemblyComparisonResult
-       {
-               Unknown = 0,
-               EquivalentFullMatch = 1,
-               EquivalentWeakNamed = 2,
-               EquivalentFXUnified = 3,
-               EquivalentUnified = 4,
-               NonEquivalentVersion = 5,
-               NonEquivalent = 6,
-               EquivalentPartialMatch = 7,
-               EquivalentPartialWeakNamed = 8,
-               EquivalentPartialUnified = 9,
-               EquivalentPartialFXUnified = 10,
-               NonEquivalentPartialVersion = 11,
-       }
-
-       public delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args);
-
-       [Flags]
-       public enum UniverseOptions
-       {
-               None = 0,
-               EnableFunctionPointers = 1,
-               DisableFusion = 2,
-               DisablePseudoCustomAttributeRetrieval = 4,
-               DontProvideAutomaticDefaultConstructor = 8,
-       }
-
-       public sealed class Universe : IDisposable
-       {
-               internal static readonly bool MonoRuntime = System.Type.GetType("Mono.Runtime") != null;
-               private readonly Dictionary<Type, Type> canonicalizedTypes = new Dictionary<Type, Type>();
-               private readonly List<AssemblyReader> assemblies = new List<AssemblyReader>();
-               private readonly List<AssemblyBuilder> dynamicAssemblies = new List<AssemblyBuilder>();
-               private readonly Dictionary<string, Assembly> assembliesByName = new Dictionary<string, Assembly>();
-               private readonly Dictionary<System.Type, Type> importedTypes = new Dictionary<System.Type, Type>();
-               private Dictionary<ScopedTypeName, Type> missingTypes;
-               private bool resolveMissingMembers;
-               private readonly bool enableFunctionPointers;
-               private readonly bool useNativeFusion;
-               private readonly bool returnPseudoCustomAttributes;
-               private readonly bool automaticallyProvideDefaultConstructor;
-               private Type typeof_System_Object;
-               private Type typeof_System_ValueType;
-               private Type typeof_System_Enum;
-               private Type typeof_System_Void;
-               private Type typeof_System_Boolean;
-               private Type typeof_System_Char;
-               private Type typeof_System_SByte;
-               private Type typeof_System_Byte;
-               private Type typeof_System_Int16;
-               private Type typeof_System_UInt16;
-               private Type typeof_System_Int32;
-               private Type typeof_System_UInt32;
-               private Type typeof_System_Int64;
-               private Type typeof_System_UInt64;
-               private Type typeof_System_Single;
-               private Type typeof_System_Double;
-               private Type typeof_System_String;
-               private Type typeof_System_IntPtr;
-               private Type typeof_System_UIntPtr;
-               private Type typeof_System_TypedReference;
-               private Type typeof_System_Type;
-               private Type typeof_System_Array;
-               private Type typeof_System_DateTime;
-               private Type typeof_System_DBNull;
-               private Type typeof_System_Decimal;
-               private Type typeof_System_NonSerializedAttribute;
-               private Type typeof_System_SerializableAttribute;
-               private Type typeof_System_AttributeUsageAttribute;
-               private Type typeof_System_Runtime_InteropServices_DllImportAttribute;
-               private Type typeof_System_Runtime_InteropServices_FieldOffsetAttribute;
-               private Type typeof_System_Runtime_InteropServices_InAttribute;
-               private Type typeof_System_Runtime_InteropServices_MarshalAsAttribute;
-               private Type typeof_System_Runtime_InteropServices_UnmanagedType;
-               private Type typeof_System_Runtime_InteropServices_VarEnum;
-               private Type typeof_System_Runtime_InteropServices_OutAttribute;
-               private Type typeof_System_Runtime_InteropServices_StructLayoutAttribute;
-               private Type typeof_System_Runtime_InteropServices_OptionalAttribute;
-               private Type typeof_System_Runtime_InteropServices_PreserveSigAttribute;
-               private Type typeof_System_Runtime_InteropServices_CallingConvention;
-               private Type typeof_System_Runtime_InteropServices_CharSet;
-               private Type typeof_System_Runtime_InteropServices_ComImportAttribute;
-               private Type typeof_System_Runtime_CompilerServices_DecimalConstantAttribute;
-               private Type typeof_System_Runtime_CompilerServices_SpecialNameAttribute;
-               private Type typeof_System_Runtime_CompilerServices_MethodImplAttribute;
-               private Type typeof_System_Security_SuppressUnmanagedCodeSecurityAttribute;
-               private Type typeof_System_Reflection_AssemblyCopyrightAttribute;
-               private Type typeof_System_Reflection_AssemblyTrademarkAttribute;
-               private Type typeof_System_Reflection_AssemblyProductAttribute;
-               private Type typeof_System_Reflection_AssemblyCompanyAttribute;
-               private Type typeof_System_Reflection_AssemblyDescriptionAttribute;
-               private Type typeof_System_Reflection_AssemblyTitleAttribute;
-               private Type typeof_System_Reflection_AssemblyInformationalVersionAttribute;
-               private Type typeof_System_Reflection_AssemblyFileVersionAttribute;
-               private Type typeof_System_Security_Permissions_CodeAccessSecurityAttribute;
-               private Type typeof_System_Security_Permissions_PermissionSetAttribute;
-               private Type typeof_System_Security_Permissions_SecurityAction;
-               private List<ResolveEventHandler> resolvers = new List<ResolveEventHandler>();
-               private Predicate<Type> missingTypeIsValueType;
-
-               public Universe()
-                       : this(UniverseOptions.None)
-               {
-               }
-
-               public Universe(UniverseOptions options)
-               {
-                       enableFunctionPointers = (options & UniverseOptions.EnableFunctionPointers) != 0;
-                       useNativeFusion = (options & UniverseOptions.DisableFusion) == 0 && GetUseNativeFusion();
-                       returnPseudoCustomAttributes = (options & UniverseOptions.DisablePseudoCustomAttributeRetrieval) == 0;
-                       automaticallyProvideDefaultConstructor = (options & UniverseOptions.DontProvideAutomaticDefaultConstructor) == 0;
-               }
-
-               private static bool GetUseNativeFusion()
-               {
-                       try
-                       {
-                               return Environment.OSVersion.Platform == PlatformID.Win32NT
-                                       && !MonoRuntime
-                                       && Environment.GetEnvironmentVariable("IKVM_DISABLE_FUSION") == null;
-                       }
-                       catch (System.Security.SecurityException)
-                       {
-                               return false;
-                       }
-               }
-
-               internal Assembly Mscorlib
-               {
-                       get { return Load("mscorlib"); }
-               }
-
-               private Type ImportMscorlibType(System.Type type)
-               {
-                       if (Mscorlib.__IsMissing)
-                       {
-                               return Mscorlib.ResolveType(new TypeName(type.Namespace, type.Name));
-                       }
-                       // We use FindType instead of ResolveType here, because on some versions of mscorlib some of
-                       // the special types we use/support are missing and the type properties are defined to
-                       // return null in that case.
-                       // Note that we don't have to unescape type.Name here, because none of the names contain special characters.
-                       return Mscorlib.FindType(new TypeName(type.Namespace, type.Name));
-               }
-
-               private Type ResolvePrimitive(string name)
-               {
-                       // Primitive here means that these types have a special metadata encoding, which means that
-                       // there can be references to them without referring to them by name explicitly.
-                       // We want these types to be usable even when they don't exist in mscorlib or there is no mscorlib loaded.
-                       return Mscorlib.FindType(new TypeName("System", name)) ?? GetMissingType(Mscorlib.ManifestModule, null, new TypeName("System", name));
-               }
-
-               internal Type System_Object
-               {
-                       get { return typeof_System_Object ?? (typeof_System_Object = ResolvePrimitive("Object")); }
-               }
-
-               internal Type System_ValueType
-               {
-                       // System.ValueType is not a primitive, but generic type parameters can have a ValueType constraint
-                       // (we also don't want to return null here)
-                       get { return typeof_System_ValueType ?? (typeof_System_ValueType = ResolvePrimitive("ValueType")); }
-               }
-
-               internal Type System_Enum
-               {
-                       // System.Enum is not a primitive, but we don't want to return null
-                       get { return typeof_System_Enum ?? (typeof_System_Enum = ResolvePrimitive("Enum")); }
-               }
-
-               internal Type System_Void
-               {
-                       get { return typeof_System_Void ?? (typeof_System_Void = ResolvePrimitive("Void")); }
-               }
-
-               internal Type System_Boolean
-               {
-                       get { return typeof_System_Boolean ?? (typeof_System_Boolean = ResolvePrimitive("Boolean")); }
-               }
-
-               internal Type System_Char
-               {
-                       get { return typeof_System_Char ?? (typeof_System_Char = ResolvePrimitive("Char")); }
-               }
-
-               internal Type System_SByte
-               {
-                       get { return typeof_System_SByte ?? (typeof_System_SByte = ResolvePrimitive("SByte")); }
-               }
-
-               internal Type System_Byte
-               {
-                       get { return typeof_System_Byte ?? (typeof_System_Byte = ResolvePrimitive("Byte")); }
-               }
-
-               internal Type System_Int16
-               {
-                       get { return typeof_System_Int16 ?? (typeof_System_Int16 = ResolvePrimitive("Int16")); }
-               }
-
-               internal Type System_UInt16
-               {
-                       get { return typeof_System_UInt16 ?? (typeof_System_UInt16 = ResolvePrimitive("UInt16")); }
-               }
-
-               internal Type System_Int32
-               {
-                       get { return typeof_System_Int32 ?? (typeof_System_Int32 = ResolvePrimitive("Int32")); }
-               }
-
-               internal Type System_UInt32
-               {
-                       get { return typeof_System_UInt32 ?? (typeof_System_UInt32 = ResolvePrimitive("UInt32")); }
-               }
-
-               internal Type System_Int64
-               {
-                       get { return typeof_System_Int64 ?? (typeof_System_Int64 = ResolvePrimitive("Int64")); }
-               }
-
-               internal Type System_UInt64
-               {
-                       get { return typeof_System_UInt64 ?? (typeof_System_UInt64 = ResolvePrimitive("UInt64")); }
-               }
-
-               internal Type System_Single
-               {
-                       get { return typeof_System_Single ?? (typeof_System_Single = ResolvePrimitive("Single")); }
-               }
-
-               internal Type System_Double
-               {
-                       get { return typeof_System_Double ?? (typeof_System_Double = ResolvePrimitive("Double")); }
-               }
-
-               internal Type System_String
-               {
-                       get { return typeof_System_String ?? (typeof_System_String = ResolvePrimitive("String")); }
-               }
-
-               internal Type System_IntPtr
-               {
-                       get { return typeof_System_IntPtr ?? (typeof_System_IntPtr = ResolvePrimitive("IntPtr")); }
-               }
-
-               internal Type System_UIntPtr
-               {
-                       get { return typeof_System_UIntPtr ?? (typeof_System_UIntPtr = ResolvePrimitive("UIntPtr")); }
-               }
-
-               internal Type System_TypedReference
-               {
-                       get { return typeof_System_TypedReference ?? (typeof_System_TypedReference = ResolvePrimitive("TypedReference")); }
-               }
-
-               internal Type System_Type
-               {
-                       // System.Type is not a primitive, but it does have a special encoding in custom attributes
-                       get { return typeof_System_Type ?? (typeof_System_Type = ResolvePrimitive("Type")); }
-               }
-
-               internal Type System_Array
-               {
-                       // System.Array is not a primitive, but it used as a base type for array types (that are primitives)
-                       get { return typeof_System_Array ?? (typeof_System_Array = ResolvePrimitive("Array")); }
-               }
-
-               internal Type System_DateTime
-               {
-                       get { return typeof_System_DateTime ?? (typeof_System_DateTime = ImportMscorlibType(typeof(System.DateTime))); }
-               }
-
-               internal Type System_DBNull
-               {
-                       get { return typeof_System_DBNull ?? (typeof_System_DBNull = ImportMscorlibType(typeof(System.DBNull))); }
-               }
-
-               internal Type System_Decimal
-               {
-                       get { return typeof_System_Decimal ?? (typeof_System_Decimal = ImportMscorlibType(typeof(System.Decimal))); }
-               }
-
-               internal Type System_NonSerializedAttribute
-               {
-                       get { return typeof_System_NonSerializedAttribute ?? (typeof_System_NonSerializedAttribute = ImportMscorlibType(typeof(System.NonSerializedAttribute))); }
-               }
-
-               internal Type System_SerializableAttribute
-               {
-                       get { return typeof_System_SerializableAttribute ?? (typeof_System_SerializableAttribute = ImportMscorlibType(typeof(System.SerializableAttribute))); }
-               }
-
-               internal Type System_AttributeUsageAttribute
-               {
-                       get { return typeof_System_AttributeUsageAttribute ?? (typeof_System_AttributeUsageAttribute = ImportMscorlibType(typeof(System.AttributeUsageAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_DllImportAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_DllImportAttribute ?? (typeof_System_Runtime_InteropServices_DllImportAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.DllImportAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_FieldOffsetAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_FieldOffsetAttribute ?? (typeof_System_Runtime_InteropServices_FieldOffsetAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.FieldOffsetAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_InAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_InAttribute ?? (typeof_System_Runtime_InteropServices_InAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.InAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_MarshalAsAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_MarshalAsAttribute ?? (typeof_System_Runtime_InteropServices_MarshalAsAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.MarshalAsAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_UnmanagedType
-               {
-                       get { return typeof_System_Runtime_InteropServices_UnmanagedType ?? (typeof_System_Runtime_InteropServices_UnmanagedType = ImportMscorlibType(typeof(System.Runtime.InteropServices.UnmanagedType))); }
-               }
-
-               internal Type System_Runtime_InteropServices_VarEnum
-               {
-                       get { return typeof_System_Runtime_InteropServices_VarEnum ?? (typeof_System_Runtime_InteropServices_VarEnum = ImportMscorlibType(typeof(System.Runtime.InteropServices.VarEnum))); }
-               }
-
-               internal Type System_Runtime_InteropServices_OutAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_OutAttribute ?? (typeof_System_Runtime_InteropServices_OutAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.OutAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_StructLayoutAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_StructLayoutAttribute ?? (typeof_System_Runtime_InteropServices_StructLayoutAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.StructLayoutAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_OptionalAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_OptionalAttribute ?? (typeof_System_Runtime_InteropServices_OptionalAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.OptionalAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_PreserveSigAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_PreserveSigAttribute ?? (typeof_System_Runtime_InteropServices_PreserveSigAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.PreserveSigAttribute))); }
-               }
-
-               internal Type System_Runtime_InteropServices_CallingConvention
-               {
-                       get { return typeof_System_Runtime_InteropServices_CallingConvention ?? (typeof_System_Runtime_InteropServices_CallingConvention = ImportMscorlibType(typeof(System.Runtime.InteropServices.CallingConvention))); }
-               }
-
-               internal Type System_Runtime_InteropServices_CharSet
-               {
-                       get { return typeof_System_Runtime_InteropServices_CharSet ?? (typeof_System_Runtime_InteropServices_CharSet = ImportMscorlibType(typeof(System.Runtime.InteropServices.CharSet))); }
-               }
-
-               internal Type System_Runtime_InteropServices_ComImportAttribute
-               {
-                       get { return typeof_System_Runtime_InteropServices_ComImportAttribute ?? (typeof_System_Runtime_InteropServices_ComImportAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.ComImportAttribute))); }
-               }
-
-               internal Type System_Runtime_CompilerServices_DecimalConstantAttribute
-               {
-                       get { return typeof_System_Runtime_CompilerServices_DecimalConstantAttribute ?? (typeof_System_Runtime_CompilerServices_DecimalConstantAttribute = ImportMscorlibType(typeof(System.Runtime.CompilerServices.DecimalConstantAttribute))); }
-               }
-
-               internal Type System_Runtime_CompilerServices_SpecialNameAttribute
-               {
-                       get { return typeof_System_Runtime_CompilerServices_SpecialNameAttribute ?? (typeof_System_Runtime_CompilerServices_SpecialNameAttribute = ImportMscorlibType(typeof(System.Runtime.CompilerServices.SpecialNameAttribute))); }
-               }
-
-               internal Type System_Runtime_CompilerServices_MethodImplAttribute
-               {
-                       get { return typeof_System_Runtime_CompilerServices_MethodImplAttribute ?? (typeof_System_Runtime_CompilerServices_MethodImplAttribute = ImportMscorlibType(typeof(System.Runtime.CompilerServices.MethodImplAttribute))); }
-               }
-
-               internal Type System_Security_SuppressUnmanagedCodeSecurityAttribute
-               {
-                       get { return typeof_System_Security_SuppressUnmanagedCodeSecurityAttribute ?? (typeof_System_Security_SuppressUnmanagedCodeSecurityAttribute = ImportMscorlibType(typeof(System.Security.SuppressUnmanagedCodeSecurityAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyCopyrightAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyCopyrightAttribute ?? (typeof_System_Reflection_AssemblyCopyrightAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyCopyrightAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyTrademarkAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyTrademarkAttribute ?? (typeof_System_Reflection_AssemblyTrademarkAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyTrademarkAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyProductAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyProductAttribute ?? (typeof_System_Reflection_AssemblyProductAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyProductAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyCompanyAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyCompanyAttribute ?? (typeof_System_Reflection_AssemblyCompanyAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyCompanyAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyDescriptionAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyDescriptionAttribute ?? (typeof_System_Reflection_AssemblyDescriptionAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyDescriptionAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyTitleAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyTitleAttribute ?? (typeof_System_Reflection_AssemblyTitleAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyTitleAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyInformationalVersionAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyInformationalVersionAttribute ?? (typeof_System_Reflection_AssemblyInformationalVersionAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyInformationalVersionAttribute))); }
-               }
-
-               internal Type System_Reflection_AssemblyFileVersionAttribute
-               {
-                       get { return typeof_System_Reflection_AssemblyFileVersionAttribute ?? (typeof_System_Reflection_AssemblyFileVersionAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyFileVersionAttribute))); }
-               }
-
-               internal Type System_Security_Permissions_CodeAccessSecurityAttribute
-               {
-                       get { return typeof_System_Security_Permissions_CodeAccessSecurityAttribute ?? (typeof_System_Security_Permissions_CodeAccessSecurityAttribute = ImportMscorlibType(typeof(System.Security.Permissions.CodeAccessSecurityAttribute))); }
-               }
-
-               internal Type System_Security_Permissions_PermissionSetAttribute
-               {
-                       get { return typeof_System_Security_Permissions_PermissionSetAttribute ?? (typeof_System_Security_Permissions_PermissionSetAttribute = ImportMscorlibType(typeof(System.Security.Permissions.PermissionSetAttribute))); }
-               }
-
-               internal Type System_Security_Permissions_SecurityAction
-               {
-                       get { return typeof_System_Security_Permissions_SecurityAction ?? (typeof_System_Security_Permissions_SecurityAction = ImportMscorlibType(typeof(System.Security.Permissions.SecurityAction))); }
-               }
-
-               internal bool HasMscorlib
-               {
-                       get { return GetLoadedAssembly("mscorlib") != null; }
-               }
-
-               public event ResolveEventHandler AssemblyResolve
-               {
-                       add { resolvers.Add(value); }
-                       remove { resolvers.Remove(value); }
-               }
-
-               public Type Import(System.Type type)
-               {
-                       Type imported;
-                       if (!importedTypes.TryGetValue(type, out imported))
-                       {
-                               imported = ImportImpl(type);
-                               if (imported != null)
-                               {
-                                       importedTypes.Add(type, imported);
-                               }
-                       }
-                       return imported;
-               }
-
-               private Type ImportImpl(System.Type type)
-               {
-                       if (type.Assembly == typeof(IKVM.Reflection.Type).Assembly)
-                       {
-                               throw new ArgumentException("Did you really want to import " + type.FullName + "?");
-                       }
-                       if (type.HasElementType)
-                       {
-                               if (type.IsArray)
-                               {
-                                       if (type.Name.EndsWith("[]"))
-                                       {
-                                               return Import(type.GetElementType()).MakeArrayType();
-                                       }
-                                       else
-                                       {
-                                               return Import(type.GetElementType()).MakeArrayType(type.GetArrayRank());
-                                       }
-                               }
-                               else if (type.IsByRef)
-                               {
-                                       return Import(type.GetElementType()).MakeByRefType();
-                               }
-                               else if (type.IsPointer)
-                               {
-                                       return Import(type.GetElementType()).MakePointerType();
-                               }
-                               else
-                               {
-                                       throw new InvalidOperationException();
-                               }
-                       }
-                       else if (type.IsGenericParameter)
-                       {
-                               if (type.DeclaringMethod != null)
-                               {
-                                       throw new NotImplementedException();
-                               }
-                               else
-                               {
-                                       return Import(type.DeclaringType).GetGenericArguments()[type.GenericParameterPosition];
-                               }
-                       }
-                       else if (type.IsGenericType && !type.IsGenericTypeDefinition)
-                       {
-                               System.Type[] args = type.GetGenericArguments();
-                               Type[] importedArgs = new Type[args.Length];
-                               for (int i = 0; i < args.Length; i++)
-                               {
-                                       importedArgs[i] = Import(args[i]);
-                               }
-                               return Import(type.GetGenericTypeDefinition()).MakeGenericType(importedArgs);
-                       }
-                       else if (type.IsNested)
-                       {
-                               // note that we can't pass in the namespace here, because .NET's Type.Namespace implementation is broken for nested types
-                               // (it returns the namespace of the declaring type)
-                               return Import(type.DeclaringType).ResolveNestedType(new TypeName(null, type.Name));
-                       }
-                       else if (type.Assembly == typeof(object).Assembly)
-                       {
-                               // make sure mscorlib types always end up in our mscorlib
-                               return Mscorlib.ResolveType(new TypeName(type.Namespace, type.Name));
-                       }
-                       else
-                       {
-                               return Import(type.Assembly).ResolveType(new TypeName(type.Namespace, type.Name));
-                       }
-               }
-
-               private Assembly Import(System.Reflection.Assembly asm)
-               {
-                       return Load(asm.FullName);
-               }
-
-               public RawModule OpenRawModule(string path)
-               {
-                       path = Path.GetFullPath(path);
-                       return OpenRawModule(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read), path);
-               }
-
-               public RawModule OpenRawModule(Stream stream, string location)
-               {
-                       if (!stream.CanRead || !stream.CanSeek || stream.Position != 0)
-                       {
-                               throw new ArgumentException("Stream must support read/seek and current position must be zero.", "stream");
-                       }
-                       return new RawModule(new ModuleReader(null, this, stream, location));
-               }
-
-               public Assembly LoadAssembly(RawModule module)
-               {
-                       string refname = module.GetAssemblyName().FullName;
-                       Assembly asm = GetLoadedAssembly(refname);
-                       if (asm == null)
-                       {
-                               AssemblyReader asm1 = module.ToAssembly();
-                               assemblies.Add(asm1);
-                               asm = asm1;
-                       }
-                       return asm;
-               }
-
-               public Assembly LoadFile(string path)
-               {
-                       try
-                       {
-                               using (RawModule module = OpenRawModule(path))
-                               {
-                                       return LoadAssembly(module);
-                               }
-                       }
-                       catch (IOException x)
-                       {
-                               throw new FileNotFoundException(x.Message, x);
-                       }
-                       catch (UnauthorizedAccessException x)
-                       {
-                               throw new FileNotFoundException(x.Message, x);
-                       }
-               }
-
-               private static string GetSimpleAssemblyName(string refname)
-               {
-                       int pos;
-                       string name;
-                       if (Fusion.ParseAssemblySimpleName(refname, out pos, out name) != ParseAssemblyResult.OK)
-                       {
-                               throw new ArgumentException();
-                       }
-                       return name;
-               }
-
-               private Assembly GetLoadedAssembly(string refname)
-               {
-                       Assembly asm;
-                       if (!assembliesByName.TryGetValue(refname, out asm))
-                       {
-                               string simpleName = GetSimpleAssemblyName(refname);
-                               for (int i = 0; i < assemblies.Count; i++)
-                               {
-                                       AssemblyComparisonResult result;
-                                       if (simpleName.Equals(assemblies[i].Name, StringComparison.InvariantCultureIgnoreCase)
-                                               && CompareAssemblyIdentity(refname, false, assemblies[i].FullName, false, out result))
-                                       {
-                                               asm = assemblies[i];
-                                               assembliesByName.Add(refname, asm);
-                                               break;
-                                       }
-                               }
-                       }
-                       return asm;
-               }
-
-               private Assembly GetDynamicAssembly(string refname)
-               {
-                       string simpleName = GetSimpleAssemblyName(refname);
-                       foreach (AssemblyBuilder asm in dynamicAssemblies)
-                       {
-                               AssemblyComparisonResult result;
-                               if (simpleName.Equals(asm.Name, StringComparison.InvariantCultureIgnoreCase)
-                                       && CompareAssemblyIdentity(refname, false, asm.FullName, false, out result))
-                               {
-                                       return asm;
-                               }
-                       }
-                       return null;
-               }
-
-               public Assembly Load(string refname)
-               {
-                       return Load(refname, null, true);
-               }
-
-               internal Assembly Load(string refname, Assembly requestingAssembly, bool throwOnError)
-               {
-                       Assembly asm = GetLoadedAssembly(refname);
-                       if (asm != null)
-                       {
-                               return asm;
-                       }
-                       if (resolvers.Count == 0)
-                       {
-                               asm = DefaultResolver(refname, throwOnError);
-                       }
-                       else
-                       {
-                               ResolveEventArgs args = new ResolveEventArgs(refname, requestingAssembly);
-                               foreach (ResolveEventHandler evt in resolvers)
-                               {
-                                       asm = evt(this, args);
-                                       if (asm != null)
-                                       {
-                                               break;
-                                       }
-                               }
-                               if (asm == null)
-                               {
-                                       asm = GetDynamicAssembly(refname);
-                               }
-                       }
-                       if (asm != null)
-                       {
-                               string defname = asm.FullName;
-                               if (refname != defname)
-                               {
-                                       assembliesByName.Add(refname, asm);
-                               }
-                               return asm;
-                       }
-                       if (throwOnError)
-                       {
-                               throw new FileNotFoundException(refname);
-                       }
-                       return null;
-               }
-
-               private Assembly DefaultResolver(string refname, bool throwOnError)
-               {
-                       Assembly asm = GetDynamicAssembly(refname);
-                       if (asm != null)
-                       {
-                               return asm;
-                       }
-                       string fileName;
-                       if (throwOnError)
-                       {
-                               try
-                               {
-                                       fileName = System.Reflection.Assembly.ReflectionOnlyLoad(refname).Location;
-                               }
-                               catch (System.BadImageFormatException x)
-                               {
-                                       throw new BadImageFormatException(x.Message, x);
-                               }
-                       }
-                       else
-                       {
-                               try
-                               {
-                                       fileName = System.Reflection.Assembly.ReflectionOnlyLoad(refname).Location;
-                               }
-                               catch (System.BadImageFormatException x)
-                               {
-                                       throw new BadImageFormatException(x.Message, x);
-                               }
-                               catch (FileNotFoundException)
-                               {
-                                       // we intentionally only swallow the FileNotFoundException, if the file exists but isn't a valid assembly,
-                                       // we should throw an exception
-                                       return null;
-                               }
-                       }
-                       return LoadFile(fileName);
-               }
-
-               public Type GetType(string assemblyQualifiedTypeName)
-               {
-                       // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
-                       // import that assembly and pass it as the context, but implicitly importing is considered evil
-                       return GetType(null, assemblyQualifiedTypeName, false, false);
-               }
-
-               public Type GetType(string assemblyQualifiedTypeName, bool throwOnError)
-               {
-                       // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
-                       // import that assembly and pass it as the context, but implicitly importing is considered evil
-                       return GetType(null, assemblyQualifiedTypeName, throwOnError, false);
-               }
-
-               public Type GetType(string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
-               {
-                       // to be more compatible with Type.GetType(), we could call Assembly.GetCallingAssembly(),
-                       // import that assembly and pass it as the context, but implicitly importing is considered evil
-                       return GetType(null, assemblyQualifiedTypeName, throwOnError, ignoreCase);
-               }
-
-               // note that context is slightly different from the calling assembly (System.Type.GetType),
-               // because context is passed to the AssemblyResolve event as the RequestingAssembly
-               public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError)
-               {
-                       return GetType(context, assemblyQualifiedTypeName, throwOnError, false);
-               }
-
-               // note that context is slightly different from the calling assembly (System.Type.GetType),
-               // because context is passed to the AssemblyResolve event as the RequestingAssembly
-               public Type GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError, bool ignoreCase)
-               {
-                       TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, throwOnError);
-                       if (parser.Error)
-                       {
-                               return null;
-                       }
-                       return parser.GetType(this, context, throwOnError, assemblyQualifiedTypeName, false, ignoreCase);
-               }
-
-               // this is similar to GetType(Assembly context, string assemblyQualifiedTypeName, bool throwOnError),
-               // but instead it assumes that the type must exist (i.e. if EnableMissingMemberResolution is enabled
-               // it will create a missing type)
-               public Type ResolveType(Assembly context, string assemblyQualifiedTypeName)
-               {
-                       TypeNameParser parser = TypeNameParser.Parse(assemblyQualifiedTypeName, false);
-                       if (parser.Error)
-                       {
-                               return null;
-                       }
-                       return parser.GetType(this, context, false, assemblyQualifiedTypeName, true, false);
-               }
-
-               public Assembly[] GetAssemblies()
-               {
-                       Assembly[] array = new Assembly[assemblies.Count + dynamicAssemblies.Count];
-                       for (int i = 0; i < assemblies.Count; i++)
-                       {
-                               array[i] = assemblies[i];
-                       }
-                       for (int i = 0, j = assemblies.Count; j < array.Length; i++, j++)
-                       {
-                               array[j] = dynamicAssemblies[i];
-                       }
-                       return array;
-               }
-
-               // this is equivalent to the Fusion CompareAssemblyIdentity API
-               public bool CompareAssemblyIdentity(string assemblyIdentity1, bool unified1, string assemblyIdentity2, bool unified2, out AssemblyComparisonResult result)
-               {
-                       return useNativeFusion
-                               ? Fusion.CompareAssemblyIdentityNative(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result)
-                               : Fusion.CompareAssemblyIdentityPure(assemblyIdentity1, unified1, assemblyIdentity2, unified2, out result);
-               }
-
-               public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access)
-               {
-                       return DefineDynamicAssemblyImpl(name, access, null, null, null, null);
-               }
-
-               public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, IEnumerable<CustomAttributeBuilder> assemblyAttributes)
-               {
-                       AssemblyBuilder ab = DefineDynamicAssembly(name, access);
-                       foreach (CustomAttributeBuilder cab in assemblyAttributes)
-                       {
-                               ab.SetCustomAttribute(cab);
-                       }
-                       return ab;
-               }
-
-               public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir)
-               {
-                       return DefineDynamicAssemblyImpl(name, access, dir, null, null, null);
-               }
-
-#if NET_4_0
-               [Obsolete]
-#endif
-               public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
-               {
-                       return DefineDynamicAssemblyImpl(name, access, dir, requiredPermissions, optionalPermissions, refusedPermissions);
-               }
-
-               private AssemblyBuilder DefineDynamicAssemblyImpl(AssemblyName name, AssemblyBuilderAccess access, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions)
-               {
-                       AssemblyBuilder asm = new AssemblyBuilder(this, name, dir, requiredPermissions, optionalPermissions, refusedPermissions);
-                       dynamicAssemblies.Add(asm);
-                       return asm;
-               }
-
-               internal void RenameAssembly(Assembly assembly, AssemblyName oldName)
-               {
-                       List<string> remove = new List<string>();
-                       foreach (KeyValuePair<string, Assembly> kv in assembliesByName)
-                       {
-                               if (kv.Value == assembly)
-                               {
-                                       remove.Add(kv.Key);
-                               }
-                       }
-                       foreach (string key in remove)
-                       {
-                               assembliesByName.Remove(key);
-                       }
-               }
-
-               public void Dispose()
-               {
-                       foreach (Assembly asm in assemblies)
-                       {
-                               foreach (Module mod in asm.GetLoadedModules())
-                               {
-                                       mod.Dispose();
-                               }
-                       }
-                       foreach (AssemblyBuilder asm in dynamicAssemblies)
-                       {
-                               foreach (Module mod in asm.GetLoadedModules())
-                               {
-                                       mod.Dispose();
-                               }
-                       }
-               }
-
-               public Assembly CreateMissingAssembly(string assemblyName)
-               {
-                       Assembly asm = new MissingAssembly(this, assemblyName);
-                       string name = asm.FullName;
-                       if (!assembliesByName.ContainsKey(name))
-                       {
-                               assembliesByName.Add(name, asm);
-                       }
-                       return asm;
-               }
-
-               public void EnableMissingMemberResolution()
-               {
-                       resolveMissingMembers = true;
-               }
-
-               internal bool MissingMemberResolution
-               {
-                       get { return resolveMissingMembers; }
-               }
-
-               internal bool EnableFunctionPointers
-               {
-                       get { return enableFunctionPointers; }
-               }
-
-               private struct ScopedTypeName : IEquatable<ScopedTypeName>
-               {
-                       private readonly object scope;
-                       private readonly TypeName name;
-
-                       internal ScopedTypeName(object scope, TypeName name)
-                       {
-                               this.scope = scope;
-                               this.name = name;
-                       }
-
-                       public override bool Equals(object obj)
-                       {
-                               ScopedTypeName? other = obj as ScopedTypeName?;
-                               return other != null && ((IEquatable<ScopedTypeName>)other.Value).Equals(this);
-                       }
-
-                       public override int GetHashCode()
-                       {
-                               return scope.GetHashCode() * 7 + name.GetHashCode();
-                       }
-
-                       bool IEquatable<ScopedTypeName>.Equals(ScopedTypeName other)
-                       {
-                               return other.scope == scope && other.name == name;
-                       }
-               }
-
-               private Type GetMissingType(Module module, Type declaringType, TypeName typeName)
-               {
-                       if (missingTypes == null)
-                       {
-                               missingTypes = new Dictionary<ScopedTypeName, Type>();
-                       }
-                       ScopedTypeName stn = new ScopedTypeName(declaringType ?? (object)module, typeName);
-                       Type type;
-                       if (!missingTypes.TryGetValue(stn, out type))
-                       {
-                               type = new MissingType(module, declaringType, typeName.Namespace, typeName.Name);
-                               missingTypes.Add(stn, type);
-                       }
-                       return type;
-               }
-
-               internal Type GetMissingTypeOrThrow(Module module, Type declaringType, TypeName typeName)
-               {
-                       if (resolveMissingMembers || module.Assembly.__IsMissing)
-                       {
-                               return GetMissingType(module, declaringType, typeName);
-                       }
-                       string fullName = TypeNameParser.Escape(typeName.ToString());
-                       if (declaringType != null)
-                       {
-                               fullName = declaringType.FullName + "+" + fullName;
-                       }
-                       throw new TypeLoadException(String.Format("Type '{0}' not found in assembly '{1}'", fullName, module.Assembly.FullName));
-               }
-
-               internal MethodBase GetMissingMethodOrThrow(Type declaringType, string name, MethodSignature signature)
-               {
-                       if (resolveMissingMembers)
-                       {
-                               MethodInfo method = new MissingMethod(declaringType, name, signature);
-                               if (name == ".ctor")
-                               {
-                                       return new ConstructorInfoImpl(method);
-                               }
-                               return method;
-                       }
-                       throw new MissingMethodException(declaringType.ToString(), name);
-               }
-
-               internal FieldInfo GetMissingFieldOrThrow(Type declaringType, string name, FieldSignature signature)
-               {
-                       if (resolveMissingMembers)
-                       {
-                               return new MissingField(declaringType, name, signature);
-                       }
-                       throw new MissingFieldException(declaringType.ToString(), name);
-               }
-
-               internal PropertyInfo GetMissingPropertyOrThrow(Type declaringType, string name, PropertySignature propertySignature)
-               {
-                       // HACK we need to check __IsMissing here, because Type doesn't have a FindProperty API
-                       // since properties are never resolved, except by custom attributes
-                       if (resolveMissingMembers || declaringType.__IsMissing)
-                       {
-                               return new MissingProperty(declaringType, name, propertySignature);
-                       }
-                       throw new System.MissingMemberException(declaringType.ToString(), name);
-               }
-
-               internal Type CanonicalizeType(Type type)
-               {
-                       Type canon;
-                       if (!canonicalizedTypes.TryGetValue(type, out canon))
-                       {
-                               canon = type;
-                               canonicalizedTypes.Add(canon, canon);
-                       }
-                       return canon;
-               }
-
-               public Type MakeFunctionPointer(__StandAloneMethodSig sig)
-               {
-                       return FunctionPointerType.Make(this, sig);
-               }
-
-               public __StandAloneMethodSig MakeStandAloneMethodSig(System.Runtime.InteropServices.CallingConvention callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       return new __StandAloneMethodSig(true, callingConvention, 0, returnType ?? this.System_Void, Util.Copy(parameterTypes), Type.EmptyTypes,
-                               PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
-               }
-
-               public __StandAloneMethodSig MakeStandAloneMethodSig(CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, Type[] optionalParameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
-               {
-                       return new __StandAloneMethodSig(false, 0, callingConvention, returnType ?? this.System_Void, Util.Copy(parameterTypes), Util.Copy(optionalParameterTypes),
-                               PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes) + Util.NullSafeLength(optionalParameterTypes)));
-               }
-
-               public event Predicate<Type> MissingTypeIsValueType
-               {
-                       add
-                       {
-                               if (missingTypeIsValueType != null)
-                               {
-                                       throw new InvalidOperationException("Only a single MissingTypeIsValueType handler can be registered.");
-                               }
-                               missingTypeIsValueType = value;
-                       }
-                       remove
-                       {
-                               if (value.Equals(missingTypeIsValueType))
-                               {
-                                       missingTypeIsValueType = null;
-                               }
-                       }
-               }
-
-               internal bool ResolveMissingTypeIsValueType(MissingType missingType)
-               {
-                       if (missingTypeIsValueType != null)
-                       {
-                               return missingTypeIsValueType(missingType);
-                       }
-                       throw new MissingMemberException(missingType);
-               }
-
-               internal bool ReturnPseudoCustomAttributes
-               {
-                       get { return returnPseudoCustomAttributes; }
-               }
-
-               internal bool AutomaticallyProvideDefaultConstructor
-               {
-                       get { return automaticallyProvideDefaultConstructor; }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Util.cs b/mcs/class/IKVM.Reflection/Util.cs
deleted file mode 100644 (file)
index e05b5db..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Runtime.Serialization;
-
-namespace IKVM.Reflection
-{
-       public interface ICustomAttributeProvider
-       {
-               bool IsDefined(Type attributeType, bool inherit);
-               IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit);
-       }
-
-       [Serializable]
-       public sealed class FileFormatLimitationExceededException : InvalidOperationException
-       {
-               public const int META_E_STRINGSPACE_FULL = unchecked((int)0x80131198);
-
-               public FileFormatLimitationExceededException(string message, int hresult)
-                       : base(message)
-               {
-                       this.HResult = hresult;
-               }
-
-               private FileFormatLimitationExceededException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
-                       : base(info, context)
-               {
-               }
-
-               public int ErrorCode
-               {
-                       get { return this.HResult; }
-               }
-       }
-
-       [Serializable]
-       public sealed class Missing : ISerializable
-       {
-               public static readonly Missing Value = new Missing();
-
-               private Missing() { }
-
-               void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
-               {
-                       info.SetType(typeof(SingletonSerializationHelper));
-               }
-
-               [Serializable]
-               private sealed class SingletonSerializationHelper : IObjectReference
-               {
-                       public object GetRealObject(StreamingContext context)
-                       {
-                               return Value;
-                       }
-               }
-       }
-
-       static class Empty<T>
-       {
-               internal static readonly T[] Array = new T[0];
-       }
-
-       static class Util
-       {
-               internal static int[] Copy(int[] array)
-               {
-                       if (array == null || array.Length == 0)
-                       {
-                               return Empty<int>.Array;
-                       }
-                       int[] copy = new int[array.Length];
-                       Array.Copy(array, copy, array.Length);
-                       return copy;
-               }
-
-               internal static Type[] Copy(Type[] array)
-               {
-                       if (array == null || array.Length == 0)
-                       {
-                               return Type.EmptyTypes;
-                       }
-                       Type[] copy = new Type[array.Length];
-                       Array.Copy(array, copy, array.Length);
-                       return copy;
-               }
-
-               internal static T[] ToArray<T, V>(List<V> list, T[] empty) where V : T
-               {
-                       if (list == null || list.Count == 0)
-                       {
-                               return empty;
-                       }
-                       T[] array = new T[list.Count];
-                       for (int i = 0; i < array.Length; i++)
-                       {
-                               array[i] = list[i];
-                       }
-                       return array;
-               }
-
-               internal static T[] ToArray<T>(IEnumerable<T> values)
-               {
-                       return values == null
-                               ? Empty<T>.Array
-                               : new List<T>(values).ToArray();
-               }
-
-               // note that an empty array matches a null reference
-               internal static bool ArrayEquals(Type[] t1, Type[] t2)
-               {
-                       if (t1 == t2)
-                       {
-                               return true;
-                       }
-                       if (t1 == null)
-                       {
-                               return t2.Length == 0;
-                       }
-                       else if (t2 == null)
-                       {
-                               return t1.Length == 0;
-                       }
-                       if (t1.Length == t2.Length)
-                       {
-                               for (int i = 0; i < t1.Length; i++)
-                               {
-                                       if (!TypeEquals(t1[i], t2[i]))
-                                       {
-                                               return false;
-                                       }
-                               }
-                               return true;
-                       }
-                       return false;
-               }
-
-               internal static bool TypeEquals(Type t1, Type t2)
-               {
-                       if (t1 == t2)
-                       {
-                               return true;
-                       }
-                       if (t1 == null)
-                       {
-                               return false;
-                       }
-                       return t1.Equals(t2);
-               }
-
-               internal static int GetHashCode(Type[] types)
-               {
-                       if (types == null)
-                       {
-                               return 0;
-                       }
-                       int h = 0;
-                       foreach (Type t in types)
-                       {
-                               if (t != null)
-                               {
-                                       h *= 3;
-                                       h ^= t.GetHashCode();
-                               }
-                       }
-                       return h;
-               }
-
-               internal static bool ArrayEquals(CustomModifiers[] m1, CustomModifiers[] m2)
-               {
-                       if (m1 == null || m2 == null)
-                       {
-                               return m1 == m2;
-                       }
-                       if (m1.Length != m2.Length)
-                       {
-                               return false;
-                       }
-                       for (int i = 0; i < m1.Length; i++)
-                       {
-                               if (!m1[i].Equals(m2[i]))
-                               {
-                                       return false;
-                               }
-                       }
-                       return true;
-               }
-
-               internal static int GetHashCode(CustomModifiers[] mods)
-               {
-                       int h = 0;
-                       if (mods != null)
-                       {
-                               foreach (CustomModifiers mod in mods)
-                               {
-                                       h ^= mod.GetHashCode();
-                               }
-                       }
-                       return h;
-               }
-
-               internal static T NullSafeElementAt<T>(T[] array, int index)
-               {
-                       return array == null ? default(T) : array[index];
-               }
-
-               internal static int NullSafeLength<T>(T[] array)
-               {
-                       return array == null ? 0 : array.Length;
-               }
-       }
-
-       [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)]
-       struct SingleConverter
-       {
-               [System.Runtime.InteropServices.FieldOffset(0)]
-               private int i;
-               [System.Runtime.InteropServices.FieldOffset(0)]
-               private float f;
-
-               internal static int SingleToInt32Bits(float v)
-               {
-                       SingleConverter c = new SingleConverter();
-                       c.f = v;
-                       return c.i;
-               }
-
-               internal static float Int32BitsToSingle(int v)
-               {
-                       SingleConverter c = new SingleConverter();
-                       c.i = v;
-                       return c.f;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/ByteBuffer.cs b/mcs/class/IKVM.Reflection/Writer/ByteBuffer.cs
deleted file mode 100644 (file)
index d459263..0000000
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class ByteBuffer
-       {
-               private byte[] buffer;
-               private int pos;
-               private int __length;   // __length is only valid if > pos, otherwise pos is the current length
-
-               internal ByteBuffer(int initialCapacity)
-               {
-                       buffer = new byte[initialCapacity];
-               }
-
-               private ByteBuffer(byte[] wrap, int length)
-               {
-                       this.buffer = wrap;
-                       this.pos = length;
-               }
-
-               internal int Position
-               {
-                       get { return pos; }
-                       set
-                       {
-                               if (value > this.Length || value > buffer.Length)
-                                       throw new ArgumentOutOfRangeException();
-                               __length = Math.Max(__length, pos);
-                               pos = value;
-                       }
-               }
-
-               internal int Length
-               {
-                       get { return Math.Max(pos, __length); }
-               }
-
-               // insert count bytes at the current position (without advancing the current position)
-               internal void Insert(int count)
-               {
-                       if (count > 0)
-                       {
-                               int len = this.Length;
-                               int free = buffer.Length - len;
-                               if (free < count)
-                               {
-                                       Grow(count - free);
-                               }
-                               Buffer.BlockCopy(buffer, pos, buffer, pos + count, len - pos);
-                               __length = Math.Max(__length, pos) + count;
-                       }
-                       else if (count < 0)
-                       {
-                               throw new ArgumentOutOfRangeException("count");
-                       }
-               }
-
-               private void Grow(int minGrow)
-               {
-                       byte[] newbuf = new byte[Math.Max(buffer.Length + minGrow, buffer.Length * 2)];
-                       Buffer.BlockCopy(buffer, 0, newbuf, 0, buffer.Length);
-                       buffer = newbuf;
-               }
-
-               // NOTE this does not advance the position
-               internal int GetInt32AtCurrentPosition()
-               {
-                       return buffer[pos]
-                               + (buffer[pos + 1] << 8)
-                               + (buffer[pos + 2] << 16)
-                               + (buffer[pos + 3] << 24);
-               }
-
-               // NOTE this does not advance the position
-               internal byte GetByteAtCurrentPosition()
-               {
-                       return buffer[pos];
-               }
-
-               // return the number of bytes that the compressed int at the current position takes
-               internal int GetCompressedUIntLength()
-               {
-                       switch (buffer[pos] & 0xC0)
-                       {
-                               default:
-                                       return 1;
-                               case 0x80:
-                                       return 2;
-                               case 0xC0:
-                                       return 4;
-                       }
-               }
-
-               internal void Write(byte[] value)
-               {
-                       if (pos + value.Length > buffer.Length)
-                               Grow(value.Length);
-                       Buffer.BlockCopy(value, 0, buffer, pos, value.Length);
-                       pos += value.Length;
-               }
-
-               internal void Write(byte value)
-               {
-                       if (pos == buffer.Length)
-                               Grow(1);
-                       buffer[pos++] = value;
-               }
-
-               internal void Write(sbyte value)
-               {
-                       Write((byte)value);
-               }
-
-               internal void Write(ushort value)
-               {
-                       Write((short)value);
-               }
-
-               internal void Write(short value)
-               {
-                       if (pos + 2 > buffer.Length)
-                               Grow(2);
-                       buffer[pos++] = (byte)value;
-                       buffer[pos++] = (byte)(value >> 8);
-               }
-
-               internal void Write(uint value)
-               {
-                       Write((int)value);
-               }
-       
-               internal void Write(int value)
-               {
-                       if (pos + 4 > buffer.Length)
-                               Grow(4);
-                       buffer[pos++] = (byte)value;
-                       buffer[pos++] = (byte)(value >> 8);
-                       buffer[pos++] = (byte)(value >> 16);
-                       buffer[pos++] = (byte)(value >> 24);
-               }
-
-               internal void Write(ulong value)
-               {
-                       Write((long)value);
-               }
-
-               internal void Write(long value)
-               {
-                       if (pos + 8 > buffer.Length)
-                               Grow(8);
-                       buffer[pos++] = (byte)value;
-                       buffer[pos++] = (byte)(value >> 8);
-                       buffer[pos++] = (byte)(value >> 16);
-                       buffer[pos++] = (byte)(value >> 24);
-                       buffer[pos++] = (byte)(value >> 32);
-                       buffer[pos++] = (byte)(value >> 40);
-                       buffer[pos++] = (byte)(value >> 48);
-                       buffer[pos++] = (byte)(value >> 56);
-               }
-
-               internal void Write(float value)
-               {
-                       Write(SingleConverter.SingleToInt32Bits(value));
-               }
-
-               internal void Write(double value)
-               {
-                       Write(BitConverter.DoubleToInt64Bits(value));
-               }
-
-               internal void Write(string str)
-               {
-                       if (str == null)
-                       {
-                               Write((byte)0xFF);
-                       }
-                       else
-                       {
-                               byte[] buf = Encoding.UTF8.GetBytes(str);
-                               WriteCompressedUInt(buf.Length);
-                               Write(buf);
-                       }
-               }
-
-               internal void WriteCompressedUInt(int value)
-               {
-                       if (value <= 0x7F)
-                       {
-                               Write((byte)value);
-                       }
-                       else if (value <= 0x3FFF)
-                       {
-                               Write((byte)(0x80 | (value >> 8)));
-                               Write((byte)value);
-                       }
-                       else
-                       {
-                               Write((byte)(0xC0 | (value >> 24)));
-                               Write((byte)(value >> 16));
-                               Write((byte)(value >> 8));
-                               Write((byte)value);
-                       }
-               }
-
-               internal void WriteCompressedInt(int value)
-               {
-                       if (value >= 0)
-                       {
-                               WriteCompressedUInt(value << 1);
-                       }
-                       else if (value >= -64)
-                       {
-                               value = ((value << 1) & 0x7F) | 1;
-                               Write((byte)value);
-                       }
-                       else if (value >= -8192)
-                       {
-                               value = ((value << 1) & 0x3FFF) | 1;
-                               Write((byte)(0x80 | (value >> 8)));
-                               Write((byte)value);
-                       }
-                       else
-                       {
-                               value = ((value << 1) & 0x1FFFFFFF) | 1;
-                               Write((byte)(0xC0 | (value >> 24)));
-                               Write((byte)(value >> 16));
-                               Write((byte)(value >> 8));
-                               Write((byte)value);
-                       }
-               }
-
-               internal void Write(ByteBuffer bb)
-               {
-                       if (pos + bb.Length > buffer.Length)
-                               Grow(bb.Length);
-                       Buffer.BlockCopy(bb.buffer, 0, buffer, pos, bb.Length);
-                       pos += bb.Length;
-               }
-
-               internal void WriteTo(System.IO.Stream stream)
-               {
-                       stream.Write(buffer, 0, this.Length);
-               }
-
-               internal void Clear()
-               {
-                       pos = 0;
-                       __length = 0;
-               }
-
-               internal void Align(int alignment)
-               {
-                       if (pos + alignment > buffer.Length)
-                               Grow(alignment);
-                       int newpos = (pos + alignment - 1) & ~(alignment - 1);
-                       while (pos < newpos)
-                               buffer[pos++] = 0;
-               }
-
-               internal void WriteTypeDefOrRefEncoded(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case TypeDefTable.Index:
-                                       WriteCompressedUInt((token & 0xFFFFFF) << 2 | 0);
-                                       break;
-                               case TypeRefTable.Index:
-                                       WriteCompressedUInt((token & 0xFFFFFF) << 2 | 1);
-                                       break;
-                               case TypeSpecTable.Index:
-                                       WriteCompressedUInt((token & 0xFFFFFF) << 2 | 2);
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-               }
-
-               internal void Write(System.IO.Stream stream)
-               {
-                       const int chunkSize = 8192;
-                       for (; ; )
-                       {
-                               if (pos + chunkSize > buffer.Length)
-                                       Grow(chunkSize);
-                               int read = stream.Read(buffer, pos, chunkSize);
-                               if (read <= 0)
-                               {
-                                       break;
-                               }
-                               pos += read;
-                       }
-               }
-
-               internal byte[] ToArray()
-               {
-                       int len = this.Length;
-                       byte[] buf = new byte[len];
-                       Buffer.BlockCopy(buffer, 0, buf, 0, len);
-                       return buf;
-               }
-
-               internal static ByteBuffer Wrap(byte[] buf)
-               {
-                       return new ByteBuffer(buf, buf.Length);
-               }
-
-               internal static ByteBuffer Wrap(byte[] buf, int length)
-               {
-                       return new ByteBuffer(buf, length);
-               }
-
-               internal bool Match(int pos, ByteBuffer bb2, int pos2, int len)
-               {
-                       for (int i = 0; i < len; i++)
-                       {
-                               if (buffer[pos + i] != bb2.buffer[pos2 + i])
-                               {
-                                       return false;
-                               }
-                       }
-                       return true;
-               }
-
-               internal int Hash()
-               {
-                       int hash = 0;
-                       int len = this.Length;
-                       for (int i = 0; i < len; i++)
-                       {
-                               hash *= 37;
-                               hash ^= buffer[i];
-                       }
-                       return hash;
-               }
-
-               internal IKVM.Reflection.Reader.ByteReader GetBlob(int offset)
-               {
-                       return IKVM.Reflection.Reader.ByteReader.FromBlob(buffer, offset);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/Heaps.cs b/mcs/class/IKVM.Reflection/Writer/Heaps.cs
deleted file mode 100644 (file)
index 54beaa4..0000000
+++ /dev/null
@@ -1,395 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Diagnostics;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Writer
-{
-       abstract class Heap
-       {
-               protected bool frozen;
-               protected int unalignedlength;
-
-               internal void Write(MetadataWriter mw)
-               {
-                       int pos = mw.Position;
-                       WriteImpl(mw);
-                       Debug.Assert(mw.Position == pos + unalignedlength);
-                       int align = Length - unalignedlength;
-                       for (int i = 0; i < align; i++)
-                       {
-                               mw.Write((byte)0);
-                       }
-               }
-
-               internal bool IsBig
-               {
-                       get { return Length > 65535; }
-               }
-
-               internal int Length
-               {
-                       get
-                       {
-                               if (!frozen)
-                                       throw new InvalidOperationException();
-                               return (unalignedlength + 3) & ~3;
-                       }
-               }
-
-               protected abstract void WriteImpl(MetadataWriter mw);
-       }
-
-       abstract class SimpleHeap : Heap
-       {
-               internal void Freeze()
-               {
-                       if (frozen)
-                               throw new InvalidOperationException();
-                       frozen = true;
-                       unalignedlength = GetLength();
-               }
-
-               protected abstract int GetLength();
-       }
-
-       sealed class TableHeap : Heap
-       {
-               internal void Freeze(MetadataWriter mw)
-               {
-                       if (frozen)
-                               throw new InvalidOperationException();
-                       frozen = true;
-                       unalignedlength = GetLength(mw);
-               }
-
-               protected override void WriteImpl(MetadataWriter mw)
-               {
-                       Table[] tables = mw.ModuleBuilder.GetTables();
-                       // Header
-                       mw.Write(0);            // Reserved
-                       int ver = mw.ModuleBuilder.MDStreamVersion;
-                       mw.Write((byte)(ver >> 16));    // MajorVersion
-                       mw.Write((byte)ver);                    // MinorVersion
-                       byte heapSizes = 0;
-                       if (mw.ModuleBuilder.Strings.IsBig)
-                       {
-                               heapSizes |= 0x01;
-                       }
-                       if (mw.ModuleBuilder.Guids.IsBig)
-                       {
-                               heapSizes |= 0x02;
-                       }
-                       if (mw.ModuleBuilder.Blobs.IsBig)
-                       {
-                               heapSizes |= 0x04;
-                       }
-                       mw.Write(heapSizes);// HeapSizes
-                       // LAMESPEC spec says reserved, but .NET 2.0 Ref.Emit sets it to 0x10
-                       mw.Write((byte)0x10);   // Reserved
-                       long bit = 1;
-                       long valid = 0;
-                       foreach (Table table in tables)
-                       {
-                               if (table != null && table.RowCount > 0)
-                               {
-                                       valid |= bit;
-                               }
-                               bit <<= 1;
-                       }
-                       mw.Write(valid);        // Valid
-                       mw.Write(0x0016003301FA00L);    // Sorted
-                       // Rows
-                       foreach (Table table in tables)
-                       {
-                               if (table != null && table.RowCount > 0)
-                               {
-                                       mw.Write(table.RowCount);
-                               }
-                       }
-                       // Tables
-                       foreach (Table table in tables)
-                       {
-                               if (table != null && table.RowCount > 0)
-                               {
-                                       int pos = mw.Position;
-                                       table.Write(mw);
-                                       Debug.Assert(mw.Position - pos == table.GetLength(mw));
-                               }
-                       }
-                       // unexplained extra padding
-                       mw.Write((byte)0);
-               }
-
-               private static int GetLength(MetadataWriter mw)
-               {
-                       int len = 4 + 4 + 8 + 8;
-                       foreach (Table table in mw.ModuleBuilder.GetTables())
-                       {
-                               if (table != null && table.RowCount > 0)
-                               {
-                                       len += 4;       // row count
-                                       len += table.GetLength(mw);
-                               }
-                       }
-                       // note that we pad one extra (unexplained) byte
-                       return len + 1;
-               }
-       }
-
-       sealed class StringHeap : SimpleHeap
-       {
-               private List<string> list = new List<string>();
-               private Dictionary<string, int> strings = new Dictionary<string, int>();
-               private int nextOffset;
-
-               internal StringHeap()
-               {
-                       Add("");
-               }
-
-               internal int Add(string str)
-               {
-                       Debug.Assert(!frozen);
-                       int offset;
-                       if (!strings.TryGetValue(str, out offset))
-                       {
-                               offset = nextOffset;
-                               nextOffset += System.Text.Encoding.UTF8.GetByteCount(str) + 1;
-                               list.Add(str);
-                               strings.Add(str, offset);
-                       }
-                       return offset;
-               }
-
-               internal string Find(int index)
-               {
-                       foreach (KeyValuePair<string, int> kv in strings)
-                       {
-                               if (kv.Value == index)
-                               {
-                                       return kv.Key;
-                               }
-                       }
-                       return null;
-               }
-
-               protected override int GetLength()
-               {
-                       return nextOffset;
-               }
-
-               protected override void WriteImpl(MetadataWriter mw)
-               {
-                       foreach (string str in list)
-                       {
-                               mw.Write(System.Text.Encoding.UTF8.GetBytes(str));
-                               mw.Write((byte)0);
-                       }
-               }
-       }
-
-       sealed class UserStringHeap : SimpleHeap
-       {
-               private List<string> list = new List<string>();
-               private Dictionary<string, int> strings = new Dictionary<string, int>();
-               private int nextOffset;
-
-               internal UserStringHeap()
-               {
-                       nextOffset = 1;
-               }
-
-               internal bool IsEmpty
-               {
-                       get { return nextOffset == 1; }
-               }
-
-               internal int Add(string str)
-               {
-                       Debug.Assert(!frozen);
-                       int offset;
-                       if (!strings.TryGetValue(str, out offset))
-                       {
-                               int length = str.Length * 2 + 1 + MetadataWriter.GetCompressedUIntLength(str.Length * 2 + 1);
-                               if (nextOffset + length > 0xFFFFFF)
-                               {
-                                       throw new FileFormatLimitationExceededException("No logical space left to create more user strings.", FileFormatLimitationExceededException.META_E_STRINGSPACE_FULL);
-                               }
-                               offset = nextOffset;
-                               nextOffset += length;
-                               list.Add(str);
-                               strings.Add(str, offset);
-                       }
-                       return offset;
-               }
-
-               protected override int GetLength()
-               {
-                       return nextOffset;
-               }
-
-               protected override void WriteImpl(MetadataWriter mw)
-               {
-                       mw.Write((byte)0);
-                       foreach (string str in list)
-                       {
-                               mw.WriteCompressedUInt(str.Length * 2 + 1);
-                               byte hasSpecialChars = 0;
-                               foreach (char ch in str)
-                               {
-                                       mw.Write((ushort)ch);
-                                       if (hasSpecialChars == 0 && (ch < 0x20 || ch > 0x7E))
-                                       {
-                                               if (ch > 0x7E
-                                                       || (ch >= 0x01 && ch <= 0x08)
-                                                       || (ch >= 0x0E && ch <= 0x1F)
-                                                       || ch == 0x27
-                                                       || ch == 0x2D)
-                                               {
-                                                       hasSpecialChars = 1;
-                                               }
-                                       }
-                               }
-                               mw.Write(hasSpecialChars);
-                       }
-               }
-       }
-
-       sealed class GuidHeap : SimpleHeap
-       {
-               private List<Guid> list = new List<Guid>();
-
-               internal GuidHeap()
-               {
-               }
-
-               internal int Add(Guid guid)
-               {
-                       Debug.Assert(!frozen);
-                       list.Add(guid);
-                       return list.Count;
-               }
-
-               protected override int GetLength()
-               {
-                       return list.Count * 16;
-               }
-
-               protected override void WriteImpl(MetadataWriter mw)
-               {
-                       foreach (Guid guid in list)
-                       {
-                               mw.Write(guid.ToByteArray());
-                       }
-               }
-       }
-
-       sealed class BlobHeap : SimpleHeap
-       {
-               private Key[] map = new Key[8179];
-               private readonly ByteBuffer buf = new ByteBuffer(32);
-
-               private struct Key
-               {
-                       internal Key[] next;
-                       internal int len;
-                       internal int hash;
-                       internal int offset;
-               }
-
-               internal BlobHeap()
-               {
-                       buf.Write((byte)0);
-               }
-
-               internal int Add(ByteBuffer bb)
-               {
-                       Debug.Assert(!frozen);
-                       int bblen = bb.Length;
-                       if (bblen == 0)
-                       {
-                               return 0;
-                       }
-                       int lenlen = MetadataWriter.GetCompressedUIntLength(bblen);
-                       int hash = bb.Hash();
-                       int index = (hash & 0x7FFFFFFF) % map.Length;
-                       Key[] keys = map;
-                       int last = index;
-                       while (keys[index].offset != 0)
-                       {
-                               if (keys[index].hash == hash
-                                       && keys[index].len == bblen
-                                       && buf.Match(keys[index].offset + lenlen, bb, 0, bblen))
-                               {
-                                       return keys[index].offset;
-                               }
-                               if (index == last)
-                               {
-                                       if (keys[index].next == null)
-                                       {
-                                               keys[index].next = new Key[4];
-                                               keys = keys[index].next;
-                                               index = 0;
-                                               break;
-                                       }
-                                       keys = keys[index].next;
-                                       index = -1;
-                                       last = keys.Length - 1;
-                               }
-                               index++;
-                       }
-                       int offset = buf.Position;
-                       buf.WriteCompressedUInt(bblen);
-                       buf.Write(bb);
-                       keys[index].len = bblen;
-                       keys[index].hash = hash;
-                       keys[index].offset = offset;
-                       return offset;
-               }
-
-               protected override int GetLength()
-               {
-                       return buf.Position;
-               }
-
-               protected override void WriteImpl(MetadataWriter mw)
-               {
-                       mw.Write(buf);
-               }
-
-               internal bool IsEmpty
-               {
-                       get { return buf.Position == 1; }
-               }
-
-               internal IKVM.Reflection.Reader.ByteReader GetBlob(int blobIndex)
-               {
-                       return buf.GetBlob(blobIndex);
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/MetadataWriter.cs b/mcs/class/IKVM.Reflection/Writer/MetadataWriter.cs
deleted file mode 100644 (file)
index 909b1c0..0000000
+++ /dev/null
@@ -1,561 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class MetadataWriter : MetadataRW
-       {
-               private readonly ModuleBuilder moduleBuilder;
-               private readonly Stream stream;
-               private readonly byte[] buffer = new byte[8];
-
-               internal MetadataWriter(ModuleBuilder module, Stream stream)
-                       : base(module, module.Strings.IsBig, module.Guids.IsBig, module.Blobs.IsBig)
-               {
-                       this.moduleBuilder = module;
-                       this.stream = stream;
-               }
-
-               internal ModuleBuilder ModuleBuilder
-               {
-                       get { return moduleBuilder; }
-               }
-
-               internal int Position
-               {
-                       get { return (int)stream.Position; }
-               }
-
-               internal void Write(ByteBuffer bb)
-               {
-                       bb.WriteTo(stream);
-               }
-
-               internal void Write(byte[] value)
-               {
-                       stream.Write(value, 0, value.Length);
-               }
-
-               internal void Write(byte value)
-               {
-                       stream.WriteByte(value);
-               }
-
-               internal void Write(ushort value)
-               {
-                       Write((short)value);
-               }
-
-               internal void Write(short value)
-               {
-                       stream.WriteByte((byte)value);
-                       stream.WriteByte((byte)(value >> 8));
-               }
-
-               internal void Write(uint value)
-               {
-                       Write((int)value);
-               }
-
-               internal void Write(int value)
-               {
-                       buffer[0] = (byte)value;
-                       buffer[1] = (byte)(value >> 8);
-                       buffer[2] = (byte)(value >> 16);
-                       buffer[3] = (byte)(value >> 24);
-                       stream.Write(buffer, 0, 4);
-               }
-
-               internal void Write(ulong value)
-               {
-                       Write((long)value);
-               }
-
-               internal void Write(long value)
-               {
-                       buffer[0] = (byte)value;
-                       buffer[1] = (byte)(value >> 8);
-                       buffer[2] = (byte)(value >> 16);
-                       buffer[3] = (byte)(value >> 24);
-                       buffer[4] = (byte)(value >> 32);
-                       buffer[5] = (byte)(value >> 40);
-                       buffer[6] = (byte)(value >> 48);
-                       buffer[7] = (byte)(value >> 56);
-                       stream.Write(buffer, 0, 8);
-               }
-
-               internal void WriteCompressedUInt(int value)
-               {
-                       if (value <= 0x7F)
-                       {
-                               Write((byte)value);
-                       }
-                       else if (value <= 0x3FFF)
-                       {
-                               Write((byte)(0x80 | (value >> 8)));
-                               Write((byte)value);
-                       }
-                       else
-                       {
-                               Write((byte)(0xC0 | (value >> 24)));
-                               Write((byte)(value >> 16));
-                               Write((byte)(value >> 8));
-                               Write((byte)value);
-                       }
-               }
-
-               internal static int GetCompressedUIntLength(int value)
-               {
-                       if (value <= 0x7F)
-                       {
-                               return 1;
-                       }
-                       else if (value <= 0x3FFF)
-                       {
-                               return 2;
-                       }
-                       else
-                       {
-                               return 4;
-                       }
-               }
-
-               internal void WriteStringIndex(int index)
-               {
-                       if (bigStrings)
-                       {
-                               Write(index);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteGuidIndex(int index)
-               {
-                       if (bigGuids)
-                       {
-                               Write(index);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteBlobIndex(int index)
-               {
-                       if (bigBlobs)
-                       {
-                               Write(index);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteTypeDefOrRef(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case 0:
-                                       break;
-                               case TypeDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 0;
-                                       break;
-                               case TypeRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 1;
-                                       break;
-                               case TypeSpecTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 2;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigTypeDefOrRef)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteEncodedTypeDefOrRef(int encodedToken)
-               {
-                       if (bigTypeDefOrRef)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteHasCustomAttribute(int token)
-               {
-                       int encodedToken = CustomAttributeTable.EncodeHasCustomAttribute(token);
-                       if (bigHasCustomAttribute)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteCustomAttributeType(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case MethodDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 2;
-                                       break;
-                               case MemberRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 3;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigCustomAttributeType)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteField(int index)
-               {
-                       if (bigField)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteMethodDef(int index)
-               {
-                       if (bigMethodDef)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteParam(int index)
-               {
-                       if (bigParam)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteTypeDef(int index)
-               {
-                       if (bigTypeDef)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteEvent(int index)
-               {
-                       if (bigEvent)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteProperty(int index)
-               {
-                       if (bigProperty)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteGenericParam(int index)
-               {
-                       if (bigGenericParam)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteModuleRef(int index)
-               {
-                       if (bigModuleRef)
-                       {
-                               Write(index & 0xFFFFFF);
-                       }
-                       else
-                       {
-                               Write((short)index);
-                       }
-               }
-
-               internal void WriteResolutionScope(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case ModuleTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 0;
-                                       break;
-                               case ModuleRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 1;
-                                       break;
-                               case AssemblyRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 2;
-                                       break;
-                               case TypeRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 3;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigResolutionScope)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteMemberRefParent(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case TypeDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 0;
-                                       break;
-                               case TypeRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 1;
-                                       break;
-                               case ModuleRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 2;
-                                       break;
-                               case MethodDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 3;
-                                       break;
-                               case TypeSpecTable.Index:
-                                       token = (token & 0xFFFFFF) << 3 | 4;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigMemberRefParent)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteMethodDefOrRef(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case MethodDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 1 | 0;
-                                       break;
-                               case MemberRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 1 | 1;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigMethodDefOrRef)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteHasConstant(int token)
-               {
-                       int encodedToken = ConstantTable.EncodeHasConstant(token);
-                       if (bigHasConstant)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteHasSemantics(int encodedToken)
-               {
-                       // NOTE because we've already had to do the encoding (to be able to sort the table)
-                       // here we simple write the value
-                       if (bigHasSemantics)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteImplementation(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case 0:
-                                       break;
-                               case FileTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 0;
-                                       break;
-                               case AssemblyRefTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 1;
-                                       break;
-                               case ExportedTypeTable.Index:
-                                       token = (token & 0xFFFFFF) << 2 | 2;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigImplementation)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteTypeOrMethodDef(int encodedToken)
-               {
-                       // NOTE because we've already had to do the encoding (to be able to sort the table)
-                       // here we simple write the value
-                       if (bigTypeOrMethodDef)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteHasDeclSecurity(int encodedToken)
-               {
-                       // NOTE because we've already had to do the encoding (to be able to sort the table)
-                       // here we simple write the value
-                       if (bigHasDeclSecurity)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-
-               internal void WriteMemberForwarded(int token)
-               {
-                       switch (token >> 24)
-                       {
-                               case FieldTable.Index:
-                                       token = (token & 0xFFFFFF) << 1 | 0;
-                                   break;
-                               case MethodDefTable.Index:
-                                       token = (token & 0xFFFFFF) << 1 | 1;
-                                       break;
-                               default:
-                                       throw new InvalidOperationException();
-                       }
-                       if (bigMemberForwarded)
-                       {
-                               Write(token);
-                       }
-                       else
-                       {
-                               Write((short)token);
-                       }
-               }
-
-               internal void WriteHasFieldMarshal(int token)
-               {
-                       int encodedToken = FieldMarshalTable.EncodeHasFieldMarshal(token);
-                       if (bigHasFieldMarshal)
-                       {
-                               Write(encodedToken);
-                       }
-                       else
-                       {
-                               Write((short)encodedToken);
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/ModuleWriter.cs b/mcs/class/IKVM.Reflection/Writer/ModuleWriter.cs
deleted file mode 100644 (file)
index 6094283..0000000
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Security.Cryptography;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Impl;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Writer
-{
-       static class ModuleWriter
-       {
-               internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
-                       PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
-                       ResourceSection resources, int entryPointToken)
-               {
-                       WriteModule(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, null);
-               }
-
-               internal static void WriteModule(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
-                       PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
-                       ResourceSection resources, int entryPointToken, Stream stream)
-               {
-                       if (stream == null)
-                       {
-                               string fileName = moduleBuilder.FullyQualifiedName;
-                               bool mono = System.Type.GetType("Mono.Runtime") != null;
-                               if (mono)
-                               {
-                                       try
-                                       {
-                                               // Mono mmaps the file, so unlink the previous version since it may be in use
-                                               File.Delete(fileName);
-                                       }
-                                       catch { }
-                               }
-                               using (FileStream fs = new FileStream(fileName, FileMode.Create))
-                               {
-                                       WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, fs);
-                               }
-                               // if we're running on Mono, mark the module as executable by using a Mono private API extension
-                               if (mono)
-                               {
-                                       File.SetAttributes(fileName, (FileAttributes)(unchecked((int)0x80000000)));
-                               }
-                       }
-                       else
-                       {
-                               WriteModuleImpl(keyPair, publicKey, moduleBuilder, fileKind, portableExecutableKind, imageFileMachine, resources, entryPointToken, stream);
-                       }
-               }
-
-               private static void WriteModuleImpl(StrongNameKeyPair keyPair, byte[] publicKey, ModuleBuilder moduleBuilder,
-                       PEFileKinds fileKind, PortableExecutableKinds portableExecutableKind, ImageFileMachine imageFileMachine,
-                       ResourceSection resources, int entryPointToken, Stream stream)
-               {
-                       moduleBuilder.ApplyUnmanagedExports(imageFileMachine);
-                       moduleBuilder.FixupMethodBodyTokens();
-
-                       moduleBuilder.ModuleTable.Add(0, moduleBuilder.Strings.Add(moduleBuilder.moduleName), moduleBuilder.Guids.Add(moduleBuilder.ModuleVersionId), 0, 0);
-
-                       if (moduleBuilder.UserStrings.IsEmpty)
-                       {
-                               // for compat with Ref.Emit, if there aren't any user strings, we add one
-                               moduleBuilder.UserStrings.Add(" ");
-                       }
-
-                       if (resources != null)
-                       {
-                               resources.Finish();
-                       }
-
-                       PEWriter writer = new PEWriter(stream);
-                       writer.Headers.OptionalHeader.FileAlignment = (uint)moduleBuilder.__FileAlignment;
-                       switch (imageFileMachine)
-                       {
-                               case ImageFileMachine.I386:
-                                       writer.Headers.FileHeader.Machine = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386;
-                                       writer.Headers.FileHeader.Characteristics |= IMAGE_FILE_HEADER.IMAGE_FILE_32BIT_MACHINE;
-                                       writer.Headers.OptionalHeader.SizeOfStackReserve = moduleBuilder.GetStackReserve(0x100000);
-                                       break;
-                               case ImageFileMachine.ARM:
-                                       writer.Headers.FileHeader.Machine = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_ARM;
-                                       writer.Headers.FileHeader.Characteristics |= IMAGE_FILE_HEADER.IMAGE_FILE_32BIT_MACHINE;
-                                       writer.Headers.OptionalHeader.SizeOfStackReserve = moduleBuilder.GetStackReserve(0x100000);
-                                       break;
-                               case ImageFileMachine.AMD64:
-                                       writer.Headers.FileHeader.Machine = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64;
-                                       writer.Headers.FileHeader.Characteristics |= IMAGE_FILE_HEADER.IMAGE_FILE_LARGE_ADDRESS_AWARE;
-                                       writer.Headers.FileHeader.SizeOfOptionalHeader = 0xF0;
-                                       writer.Headers.OptionalHeader.Magic = IMAGE_OPTIONAL_HEADER.IMAGE_NT_OPTIONAL_HDR64_MAGIC;
-                                       writer.Headers.OptionalHeader.SizeOfStackReserve = moduleBuilder.GetStackReserve(0x400000);
-                                       writer.Headers.OptionalHeader.SizeOfStackCommit = 0x4000;
-                                       writer.Headers.OptionalHeader.SizeOfHeapCommit = 0x2000;
-                                       break;
-                               case ImageFileMachine.IA64:
-                                       writer.Headers.FileHeader.Machine = IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64;
-                                       writer.Headers.FileHeader.Characteristics |= IMAGE_FILE_HEADER.IMAGE_FILE_LARGE_ADDRESS_AWARE;
-                                       writer.Headers.FileHeader.SizeOfOptionalHeader = 0xF0;
-                                       writer.Headers.OptionalHeader.Magic = IMAGE_OPTIONAL_HEADER.IMAGE_NT_OPTIONAL_HDR64_MAGIC;
-                                       writer.Headers.OptionalHeader.SizeOfStackReserve = moduleBuilder.GetStackReserve(0x400000);
-                                       writer.Headers.OptionalHeader.SizeOfStackCommit = 0x4000;
-                                       writer.Headers.OptionalHeader.SizeOfHeapCommit = 0x2000;
-                                       break;
-                               default:
-                                       throw new ArgumentOutOfRangeException("imageFileMachine");
-                       }
-                       if (fileKind == PEFileKinds.Dll)
-                       {
-                               writer.Headers.FileHeader.Characteristics |= IMAGE_FILE_HEADER.IMAGE_FILE_DLL;
-                       }
-
-                       switch (fileKind)
-                       {
-                               case PEFileKinds.WindowApplication:
-                                       writer.Headers.OptionalHeader.Subsystem = IMAGE_OPTIONAL_HEADER.IMAGE_SUBSYSTEM_WINDOWS_GUI;
-                                       break;
-                               default:
-                                       writer.Headers.OptionalHeader.Subsystem = IMAGE_OPTIONAL_HEADER.IMAGE_SUBSYSTEM_WINDOWS_CUI;
-                                       break;
-                       }
-                       writer.Headers.OptionalHeader.DllCharacteristics = (ushort)moduleBuilder.__DllCharacteristics;
-
-                       CliHeader cliHeader = new CliHeader();
-                       cliHeader.Cb = 0x48;
-                       cliHeader.MajorRuntimeVersion = 2;
-                       cliHeader.MinorRuntimeVersion = moduleBuilder.MDStreamVersion < 0x20000 ? (ushort)0 : (ushort)5;
-                       if ((portableExecutableKind & PortableExecutableKinds.ILOnly) != 0)
-                       {
-                               cliHeader.Flags |= CliHeader.COMIMAGE_FLAGS_ILONLY;
-                       }
-                       if ((portableExecutableKind & PortableExecutableKinds.Required32Bit) != 0)
-                       {
-                               cliHeader.Flags |= CliHeader.COMIMAGE_FLAGS_32BITREQUIRED;
-                       }
-                       if ((portableExecutableKind & PortableExecutableKinds.Preferred32Bit) != 0)
-                       {
-                               cliHeader.Flags |= CliHeader.COMIMAGE_FLAGS_32BITREQUIRED | CliHeader.COMIMAGE_FLAGS_32BITPREFERRED;
-                       }
-                       if (keyPair != null)
-                       {
-                               cliHeader.Flags |= CliHeader.COMIMAGE_FLAGS_STRONGNAMESIGNED;
-                       }
-                       if (ModuleBuilder.IsPseudoToken(entryPointToken))
-                       {
-                               entryPointToken = moduleBuilder.ResolvePseudoToken(entryPointToken);
-                       }
-                       cliHeader.EntryPointToken = (uint)entryPointToken;
-
-                       moduleBuilder.Strings.Freeze();
-                       moduleBuilder.UserStrings.Freeze();
-                       moduleBuilder.Guids.Freeze();
-                       moduleBuilder.Blobs.Freeze();
-                       MetadataWriter mw = new MetadataWriter(moduleBuilder, stream);
-                       moduleBuilder.Tables.Freeze(mw);
-                       TextSection code = new TextSection(writer, cliHeader, moduleBuilder, ComputeStrongNameSignatureLength(publicKey));
-
-                       // Export Directory
-                       if (code.ExportDirectoryLength != 0)
-                       {
-                               writer.Headers.OptionalHeader.DataDirectory[0].VirtualAddress = code.ExportDirectoryRVA;
-                               writer.Headers.OptionalHeader.DataDirectory[0].Size = code.ExportDirectoryLength;
-                       }
-
-                       // Import Directory
-                       if (code.ImportDirectoryLength != 0)
-                       {
-                               writer.Headers.OptionalHeader.DataDirectory[1].VirtualAddress = code.ImportDirectoryRVA;
-                               writer.Headers.OptionalHeader.DataDirectory[1].Size = code.ImportDirectoryLength;
-                       }
-
-                       // Import Address Table Directory
-                       if (code.ImportAddressTableLength != 0)
-                       {
-                               writer.Headers.OptionalHeader.DataDirectory[12].VirtualAddress = code.ImportAddressTableRVA;
-                               writer.Headers.OptionalHeader.DataDirectory[12].Size = code.ImportAddressTableLength;
-                       }
-
-                       // COM Descriptor Directory
-                       writer.Headers.OptionalHeader.DataDirectory[14].VirtualAddress = code.ComDescriptorRVA;
-                       writer.Headers.OptionalHeader.DataDirectory[14].Size = code.ComDescriptorLength;
-
-                       // Debug Directory
-                       if (code.DebugDirectoryLength != 0)
-                       {
-                               writer.Headers.OptionalHeader.DataDirectory[6].VirtualAddress = code.DebugDirectoryRVA;
-                               writer.Headers.OptionalHeader.DataDirectory[6].Size = code.DebugDirectoryLength;
-                       }
-
-                       // we need to start by computing the number of sections, because code.PointerToRawData depends on that
-                       writer.Headers.FileHeader.NumberOfSections = 1;
-
-                       if (moduleBuilder.initializedData.Length != 0)
-                       {
-                               // .sdata
-                               writer.Headers.FileHeader.NumberOfSections++;
-                       }
-
-                       if (resources != null)
-                       {
-                               // .rsrc
-                               writer.Headers.FileHeader.NumberOfSections++;
-                       }
-
-                       if (imageFileMachine != ImageFileMachine.ARM)
-                       {
-                               // .reloc
-                               writer.Headers.FileHeader.NumberOfSections++;
-                       }
-
-                       SectionHeader text = new SectionHeader();
-                       text.Name = ".text";
-                       text.VirtualAddress = code.BaseRVA;
-                       text.VirtualSize = (uint)code.Length;
-                       text.PointerToRawData = code.PointerToRawData;
-                       text.SizeOfRawData = writer.ToFileAlignment((uint)code.Length);
-                       text.Characteristics = SectionHeader.IMAGE_SCN_CNT_CODE | SectionHeader.IMAGE_SCN_MEM_EXECUTE | SectionHeader.IMAGE_SCN_MEM_READ;
-
-                       SectionHeader sdata = new SectionHeader();
-                       sdata.Name = ".sdata";
-                       sdata.VirtualAddress = text.VirtualAddress + writer.ToSectionAlignment(text.VirtualSize);
-                       sdata.VirtualSize = (uint)moduleBuilder.initializedData.Length;
-                       sdata.PointerToRawData = text.PointerToRawData + text.SizeOfRawData;
-                       sdata.SizeOfRawData = writer.ToFileAlignment((uint)moduleBuilder.initializedData.Length);
-                       sdata.Characteristics = SectionHeader.IMAGE_SCN_CNT_INITIALIZED_DATA | SectionHeader.IMAGE_SCN_MEM_READ | SectionHeader.IMAGE_SCN_MEM_WRITE;
-
-                       SectionHeader rsrc = new SectionHeader();
-                       rsrc.Name = ".rsrc";
-                       rsrc.VirtualAddress = sdata.VirtualAddress + writer.ToSectionAlignment(sdata.VirtualSize);
-                       rsrc.PointerToRawData = sdata.PointerToRawData + sdata.SizeOfRawData;
-                       rsrc.VirtualSize = resources == null ? 0 : (uint)resources.Length;
-                       rsrc.SizeOfRawData = writer.ToFileAlignment(rsrc.VirtualSize);
-                       rsrc.Characteristics = SectionHeader.IMAGE_SCN_MEM_READ | SectionHeader.IMAGE_SCN_CNT_INITIALIZED_DATA;
-
-                       if (rsrc.SizeOfRawData != 0)
-                       {
-                               // Resource Directory
-                               writer.Headers.OptionalHeader.DataDirectory[2].VirtualAddress = rsrc.VirtualAddress;
-                               writer.Headers.OptionalHeader.DataDirectory[2].Size = rsrc.VirtualSize;
-                       }
-
-                       SectionHeader reloc = new SectionHeader();
-                       reloc.Name = ".reloc";
-                       reloc.VirtualAddress = rsrc.VirtualAddress + writer.ToSectionAlignment(rsrc.VirtualSize);
-                       if (imageFileMachine != ImageFileMachine.ARM)
-                       {
-                               reloc.VirtualSize = ((uint)moduleBuilder.unmanagedExports.Count + 1) * 12;
-                       }
-                       reloc.PointerToRawData = rsrc.PointerToRawData + rsrc.SizeOfRawData;
-                       reloc.SizeOfRawData = writer.ToFileAlignment(reloc.VirtualSize);
-                       reloc.Characteristics = SectionHeader.IMAGE_SCN_MEM_READ | SectionHeader.IMAGE_SCN_CNT_INITIALIZED_DATA | SectionHeader.IMAGE_SCN_MEM_DISCARDABLE;
-
-                       if (reloc.SizeOfRawData != 0)
-                       {
-                               // Base Relocation Directory
-                               writer.Headers.OptionalHeader.DataDirectory[5].VirtualAddress = reloc.VirtualAddress;
-                               writer.Headers.OptionalHeader.DataDirectory[5].Size = reloc.VirtualSize;
-                       }
-
-                       writer.Headers.OptionalHeader.SizeOfCode = text.SizeOfRawData;
-                       writer.Headers.OptionalHeader.SizeOfInitializedData = sdata.SizeOfRawData + rsrc.SizeOfRawData + reloc.SizeOfRawData;
-                       writer.Headers.OptionalHeader.SizeOfUninitializedData = 0;
-                       writer.Headers.OptionalHeader.SizeOfImage = reloc.VirtualAddress + writer.ToSectionAlignment(reloc.VirtualSize);
-                       writer.Headers.OptionalHeader.SizeOfHeaders = text.PointerToRawData;
-                       writer.Headers.OptionalHeader.BaseOfCode = code.BaseRVA;
-                       writer.Headers.OptionalHeader.BaseOfData = sdata.VirtualAddress;
-                       writer.Headers.OptionalHeader.ImageBase = (ulong)moduleBuilder.__ImageBase;
-
-                       if (imageFileMachine == ImageFileMachine.IA64)
-                       {
-                               // apparently for IA64 AddressOfEntryPoint points to the address of the entry point
-                               // (i.e. there is an additional layer of indirection), so we add the offset to the pointer
-                               writer.Headers.OptionalHeader.AddressOfEntryPoint = code.StartupStubRVA + 0x20;
-                       }
-                       else if (imageFileMachine != ImageFileMachine.ARM)
-                       {
-                               writer.Headers.OptionalHeader.AddressOfEntryPoint = code.StartupStubRVA;
-                       }
-
-                       writer.WritePEHeaders();
-                       writer.WriteSectionHeader(text);
-                       if (sdata.SizeOfRawData != 0)
-                       {
-                               writer.WriteSectionHeader(sdata);
-                       }
-                       if (rsrc.SizeOfRawData != 0)
-                       {
-                               writer.WriteSectionHeader(rsrc);
-                       }
-                       if (reloc.SizeOfRawData != 0)
-                       {
-                               writer.WriteSectionHeader(reloc);
-                       }
-
-                       stream.Seek(text.PointerToRawData, SeekOrigin.Begin);
-                       code.Write(mw, sdata.VirtualAddress);
-
-                       if (sdata.SizeOfRawData != 0)
-                       {
-                               stream.Seek(sdata.PointerToRawData, SeekOrigin.Begin);
-                               mw.Write(moduleBuilder.initializedData);
-                       }
-
-                       if (rsrc.SizeOfRawData != 0)
-                       {
-                               stream.Seek(rsrc.PointerToRawData, SeekOrigin.Begin);
-                               resources.Write(mw, rsrc.VirtualAddress);
-                       }
-
-                       if (reloc.SizeOfRawData != 0)
-                       {
-                               stream.Seek(reloc.PointerToRawData, SeekOrigin.Begin);
-                               code.WriteRelocations(mw);
-                       }
-
-                       // file alignment
-                       stream.SetLength(reloc.PointerToRawData + reloc.SizeOfRawData);
-
-                       // do the strong naming
-                       if (keyPair != null)
-                       {
-                               StrongName(stream, keyPair, writer.HeaderSize, text.PointerToRawData, code.StrongNameSignatureRVA - text.VirtualAddress + text.PointerToRawData, code.StrongNameSignatureLength);
-                       }
-
-                       if (moduleBuilder.symbolWriter != null)
-                       {
-                               moduleBuilder.WriteSymbolTokenMap();
-                               moduleBuilder.symbolWriter.Close();
-                       }
-               }
-
-               private static int ComputeStrongNameSignatureLength(byte[] publicKey)
-               {
-                       if (publicKey == null)
-                       {
-                               return 0;
-                       }
-                       else if (publicKey.Length == 16)
-                       {
-                               // it must be the ECMA pseudo public key, we don't know the key size of the real key, but currently both Mono and Microsoft use a 1024 bit key size
-                               return 128;
-                       }
-                       else
-                       {
-                               // for the supported strong naming algorithms, the signature size is the same as the key size
-                               // (we have to subtract 32 for the header)
-                               return publicKey.Length - 32;
-                       }
-               }
-
-               private static void StrongName(Stream stream, StrongNameKeyPair keyPair, uint headerLength, uint textSectionFileOffset, uint strongNameSignatureFileOffset, uint strongNameSignatureLength)
-               {
-                       SHA1Managed hash = new SHA1Managed();
-                       using (CryptoStream cs = new CryptoStream(Stream.Null, hash, CryptoStreamMode.Write))
-                       {
-                               stream.Seek(0, SeekOrigin.Begin);
-                               byte[] buf = new byte[8192];
-                               HashChunk(stream, cs, buf, (int)headerLength);
-                               stream.Seek(textSectionFileOffset, SeekOrigin.Begin);
-                               HashChunk(stream, cs, buf, (int)(strongNameSignatureFileOffset - textSectionFileOffset));
-                               stream.Seek(strongNameSignatureLength, SeekOrigin.Current);
-                               HashChunk(stream, cs, buf, (int)(stream.Length - (strongNameSignatureFileOffset + strongNameSignatureLength)));
-                       }
-                       using (RSA rsa = keyPair.CreateRSA())
-                       {
-                               RSAPKCS1SignatureFormatter sign = new RSAPKCS1SignatureFormatter(rsa);
-                               byte[] signature = sign.CreateSignature(hash);
-                               Array.Reverse(signature);
-                               if (signature.Length != strongNameSignatureLength)
-                               {
-                                       throw new InvalidOperationException("Signature length mismatch");
-                               }
-                               stream.Seek(strongNameSignatureFileOffset, SeekOrigin.Begin);
-                               stream.Write(signature, 0, signature.Length);
-                       }
-
-                       // compute the PE checksum
-                       stream.Seek(0, SeekOrigin.Begin);
-                       int count = (int)stream.Length / 4;
-                       BinaryReader br = new BinaryReader(stream);
-                       long sum = 0;
-                       for (int i = 0; i < count; i++)
-                       {
-                               sum += br.ReadUInt32();
-                               int carry = (int)(sum >> 32);
-                               sum &= 0xFFFFFFFFU;
-                               sum += carry;
-                       }
-                       while ((sum >> 16) != 0)
-                       {
-                               sum = (sum & 0xFFFF) + (sum >> 16);
-                       }
-                       sum += stream.Length;
-
-                       // write the PE checksum, note that it is always at offset 0xD8 in the file
-                       ByteBuffer bb = new ByteBuffer(4);
-                       bb.Write((int)sum);
-                       stream.Seek(0xD8, SeekOrigin.Begin);
-                       bb.WriteTo(stream);
-               }
-
-               internal static void HashChunk(Stream stream, CryptoStream cs, byte[] buf, int length)
-               {
-                       while (length > 0)
-                       {
-                               int read = stream.Read(buf, 0, Math.Min(buf.Length, length));
-                               cs.Write(buf, 0, read);
-                               length -= read;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/PEWriter.cs b/mcs/class/IKVM.Reflection/Writer/PEWriter.cs
deleted file mode 100644 (file)
index 665296e..0000000
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.IO;
-using BYTE = System.Byte;
-using WORD = System.UInt16;
-using DWORD = System.UInt32;
-using ULONGLONG = System.UInt64;
-using IMAGE_DATA_DIRECTORY = IKVM.Reflection.Reader.IMAGE_DATA_DIRECTORY;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class PEWriter
-       {
-               private readonly BinaryWriter bw;
-               private readonly IMAGE_NT_HEADERS hdr = new IMAGE_NT_HEADERS();
-
-               internal PEWriter(Stream stream)
-               {
-                       bw = new BinaryWriter(stream);
-                       WriteMSDOSHeader();
-               }
-
-               public IMAGE_NT_HEADERS Headers
-               {
-                       get { return hdr; }
-               }
-
-               public uint HeaderSize
-               {
-                       get
-                       {
-                               return (uint)
-                                       ((8 * 16) +     // MSDOS header
-                                       4 +                             // signature
-                                       20 +                    // IMAGE_FILE_HEADER
-                                       hdr.FileHeader.SizeOfOptionalHeader +
-                                       hdr.FileHeader.NumberOfSections * 40);
-                       }
-               }
-
-               private void WriteMSDOSHeader()
-               {
-                       bw.Write(new byte[] {
-                               0x4D, 0x5A, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00,
-                               0x04, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
-                               0xB8, 0x00, 0x00, 0x00, 0x00, 0x00,     0x00, 0x00,
-                               0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                               0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
-                               0x0E, 0x1F, 0xBA, 0x0E, 0x00, 0xB4, 0x09, 0xCD,
-                               0x21, 0xB8, 0x01, 0x4C, 0xCD, 0x21, 0x54, 0x68,
-                               0x69, 0x73, 0x20, 0x70, 0x72, 0x6F, 0x67, 0x72,
-                               0x61, 0x6D, 0x20, 0x63, 0x61, 0x6E, 0x6E, 0x6F,
-                               0x74, 0x20, 0x62, 0x65, 0x20, 0x72, 0x75, 0x6E,
-                               0x20, 0x69, 0x6E, 0x20, 0x44, 0x4F, 0x53, 0x20,
-                               0x6D, 0x6F, 0x64, 0x65, 0x2E, 0x0D, 0x0D, 0x0A,
-                               0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-                       });
-               }
-
-               internal void WritePEHeaders()
-               {
-                       bw.Write(hdr.Signature);
-
-                       // IMAGE_FILE_HEADER
-                       bw.Write(hdr.FileHeader.Machine);
-                       bw.Write(hdr.FileHeader.NumberOfSections);
-                       bw.Write(hdr.FileHeader.TimeDateStamp);
-                       bw.Write(hdr.FileHeader.PointerToSymbolTable);
-                       bw.Write(hdr.FileHeader.NumberOfSymbols);
-                       bw.Write(hdr.FileHeader.SizeOfOptionalHeader);
-                       bw.Write(hdr.FileHeader.Characteristics);
-
-                       // IMAGE_OPTIONAL_HEADER
-                       hdr.OptionalHeader.Write(bw);
-               }
-
-               internal void WriteSectionHeader(SectionHeader sectionHeader)
-               {
-                       byte[] name = new byte[8];
-                       System.Text.Encoding.UTF8.GetBytes(sectionHeader.Name, 0, sectionHeader.Name.Length, name, 0);
-                       bw.Write(name);
-                       bw.Write(sectionHeader.VirtualSize);
-                       bw.Write(sectionHeader.VirtualAddress);
-                       bw.Write(sectionHeader.SizeOfRawData);
-                       bw.Write(sectionHeader.PointerToRawData);
-                       bw.Write(sectionHeader.PointerToRelocations);
-                       bw.Write(sectionHeader.PointerToLinenumbers);
-                       bw.Write(sectionHeader.NumberOfRelocations);
-                       bw.Write(sectionHeader.NumberOfLinenumbers);
-                       bw.Write(sectionHeader.Characteristics);
-               }
-
-               internal uint ToFileAlignment(uint p)
-               {
-                       return (p + (Headers.OptionalHeader.FileAlignment - 1)) & ~(Headers.OptionalHeader.FileAlignment - 1);
-               }
-
-               internal uint ToSectionAlignment(uint p)
-               {
-                       return (p + (Headers.OptionalHeader.SectionAlignment - 1)) & ~(Headers.OptionalHeader.SectionAlignment - 1);
-               }
-       }
-
-       sealed class IMAGE_NT_HEADERS
-       {
-               public DWORD Signature = 0x00004550;    // "PE\0\0"
-               public IMAGE_FILE_HEADER FileHeader = new IMAGE_FILE_HEADER();
-               public IMAGE_OPTIONAL_HEADER OptionalHeader = new IMAGE_OPTIONAL_HEADER();
-       }
-
-       sealed class IMAGE_FILE_HEADER
-       {
-               public const WORD IMAGE_FILE_MACHINE_I386 = 0x014c;
-               public const WORD IMAGE_FILE_MACHINE_ARM = 0x01c4;
-               public const WORD IMAGE_FILE_MACHINE_IA64 = 0x0200;
-               public const WORD IMAGE_FILE_MACHINE_AMD64 = 0x8664;
-
-               public const WORD IMAGE_FILE_32BIT_MACHINE = 0x0100;
-               public const WORD IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002;
-               public const WORD IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020;
-               public const WORD IMAGE_FILE_DLL = 0x2000;
-
-               public WORD Machine;
-               public WORD NumberOfSections;
-               public DWORD TimeDateStamp = (uint)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
-               public DWORD PointerToSymbolTable = 0;
-               public DWORD NumberOfSymbols = 0;
-               public WORD SizeOfOptionalHeader = 0xE0;
-               public WORD Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE;
-       }
-
-       sealed class IMAGE_OPTIONAL_HEADER
-       {
-               public const WORD IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b;
-               public const WORD IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b;
-
-               public const WORD IMAGE_SUBSYSTEM_WINDOWS_GUI = 2;
-               public const WORD IMAGE_SUBSYSTEM_WINDOWS_CUI = 3;
-
-               public WORD Magic = IMAGE_NT_OPTIONAL_HDR32_MAGIC;
-               public BYTE MajorLinkerVersion = 8;
-               public BYTE MinorLinkerVersion = 0;
-               public DWORD SizeOfCode;
-               public DWORD SizeOfInitializedData;
-               public DWORD SizeOfUninitializedData;
-               public DWORD AddressOfEntryPoint;
-               public DWORD BaseOfCode;
-               public DWORD BaseOfData;
-               public ULONGLONG ImageBase;
-               public DWORD SectionAlignment = 0x2000;
-               public DWORD FileAlignment;
-               public WORD MajorOperatingSystemVersion = 4;
-               public WORD MinorOperatingSystemVersion = 0;
-               public WORD MajorImageVersion = 0;
-               public WORD MinorImageVersion = 0;
-               public WORD MajorSubsystemVersion = 4;
-               public WORD MinorSubsystemVersion = 0;
-               public DWORD Win32VersionValue = 0;
-               public DWORD SizeOfImage;
-               public DWORD SizeOfHeaders;
-               public DWORD CheckSum = 0;
-               public WORD Subsystem;
-               public WORD DllCharacteristics;
-               public ULONGLONG SizeOfStackReserve;
-               public ULONGLONG SizeOfStackCommit = 0x1000;
-               public ULONGLONG SizeOfHeapReserve = 0x100000;
-               public ULONGLONG SizeOfHeapCommit = 0x1000;
-               public DWORD LoaderFlags = 0;
-               public DWORD NumberOfRvaAndSizes = 16;
-               public IMAGE_DATA_DIRECTORY[] DataDirectory = new IMAGE_DATA_DIRECTORY[16];
-
-               internal void Write(BinaryWriter bw)
-               {
-                       bw.Write(Magic);
-                       bw.Write(MajorLinkerVersion);
-                       bw.Write(MinorLinkerVersion);
-                       bw.Write(SizeOfCode);
-                       bw.Write(SizeOfInitializedData);
-                       bw.Write(SizeOfUninitializedData);
-                       bw.Write(AddressOfEntryPoint);
-                       bw.Write(BaseOfCode);
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               bw.Write(BaseOfData);
-                               bw.Write((DWORD)ImageBase);
-                       }
-                       else
-                       {
-                               bw.Write(ImageBase);
-                       }
-                       bw.Write(SectionAlignment);
-                       bw.Write(FileAlignment);
-                       bw.Write(MajorOperatingSystemVersion);
-                       bw.Write(MinorOperatingSystemVersion);
-                       bw.Write(MajorImageVersion);
-                       bw.Write(MinorImageVersion);
-                       bw.Write(MajorSubsystemVersion);
-                       bw.Write(MinorSubsystemVersion);
-                       bw.Write(Win32VersionValue);
-                       bw.Write(SizeOfImage);
-                       bw.Write(SizeOfHeaders);
-                       bw.Write(CheckSum);
-                       bw.Write(Subsystem);
-                       bw.Write(DllCharacteristics);
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               bw.Write((DWORD)SizeOfStackReserve);
-                       }
-                       else
-                       {
-                               bw.Write(SizeOfStackReserve);
-                       }
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               bw.Write((DWORD)SizeOfStackCommit);
-                       }
-                       else
-                       {
-                               bw.Write(SizeOfStackCommit);
-                       }
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               bw.Write((DWORD)SizeOfHeapReserve);
-                       }
-                       else
-                       {
-                               bw.Write(SizeOfHeapReserve);
-                       }
-                       if (Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
-                       {
-                               bw.Write((DWORD)SizeOfHeapCommit);
-                       }
-                       else
-                       {
-                               bw.Write(SizeOfHeapCommit);
-                       }
-                       bw.Write(LoaderFlags);
-                       bw.Write(NumberOfRvaAndSizes);
-                       for (int i = 0; i < DataDirectory.Length; i++)
-                       {
-                               bw.Write(DataDirectory[i].VirtualAddress);
-                               bw.Write(DataDirectory[i].Size);
-                       }
-               }
-       }
-
-       class SectionHeader
-       {
-               public const DWORD IMAGE_SCN_CNT_CODE = 0x00000020;
-               public const DWORD IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040;
-               public const DWORD IMAGE_SCN_MEM_DISCARDABLE = 0x02000000;
-               public const DWORD IMAGE_SCN_MEM_EXECUTE = 0x20000000;
-               public const DWORD IMAGE_SCN_MEM_READ = 0x40000000;
-               public const DWORD IMAGE_SCN_MEM_WRITE = 0x80000000;
-
-               public string Name;             // 8 byte UTF8 encoded 0-padded
-               public DWORD VirtualSize;
-               public DWORD VirtualAddress;
-               public DWORD SizeOfRawData;
-               public DWORD PointerToRawData;
-#pragma warning disable 649 // the follow fields are never assigned to
-               public DWORD PointerToRelocations;
-               public DWORD PointerToLinenumbers;
-               public WORD NumberOfRelocations;
-               public WORD NumberOfLinenumbers;
-#pragma warning restore 649
-               public DWORD Characteristics;
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/ResourceSection.cs b/mcs/class/IKVM.Reflection/Writer/ResourceSection.cs
deleted file mode 100644 (file)
index 3789ca2..0000000
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
-  Copyright (C) 2010-2012 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Text;
-using IKVM.Reflection.Reader;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class ResourceSection
-       {
-               private const int RT_ICON = 3;
-               private const int RT_GROUP_ICON = 14;
-               private const int RT_VERSION = 16;
-               private const int RT_MANIFEST = 24;
-               private ResourceDirectoryEntry root = new ResourceDirectoryEntry(new OrdinalOrName("root"));
-               private ByteBuffer bb;
-               private List<int> linkOffsets;
-
-               internal void AddVersionInfo(ByteBuffer versionInfo)
-               {
-                       root[new OrdinalOrName(RT_VERSION)][new OrdinalOrName(1)][new OrdinalOrName(0)].Data = versionInfo;
-               }
-
-               internal void AddIcon(byte[] iconFile)
-               {
-                       BinaryReader br = new BinaryReader(new MemoryStream(iconFile));
-                       ushort idReserved = br.ReadUInt16();
-                       ushort idType = br.ReadUInt16();
-                       ushort idCount = br.ReadUInt16();
-                       if (idReserved != 0 || idType != 1)
-                       {
-                               throw new ArgumentException("The supplied byte array is not a valid .ico file.");
-                       }
-                       ByteBuffer group = new ByteBuffer(6 + 14 * idCount);
-                       group.Write(idReserved);
-                       group.Write(idType);
-                       group.Write(idCount);
-                       for (int i = 0; i < idCount; i++)
-                       {
-                               byte bWidth = br.ReadByte();
-                               byte bHeight = br.ReadByte();
-                               byte bColorCount = br.ReadByte();
-                               byte bReserved = br.ReadByte();
-                               ushort wPlanes = br.ReadUInt16();
-                               ushort wBitCount = br.ReadUInt16();
-                               uint dwBytesInRes = br.ReadUInt32();
-                               uint dwImageOffset = br.ReadUInt32();
-
-                               // we start the icon IDs at 2
-                               ushort id = (ushort)(2 + i);
-
-                               group.Write(bWidth);
-                               group.Write(bHeight);
-                               group.Write(bColorCount);
-                               group.Write(bReserved);
-                               group.Write(wPlanes);
-                               group.Write(wBitCount);
-                               group.Write(dwBytesInRes);
-                               group.Write(id);
-
-                               byte[] icon = new byte[dwBytesInRes];
-                               Buffer.BlockCopy(iconFile, (int)dwImageOffset, icon, 0, icon.Length);
-                               root[new OrdinalOrName(RT_ICON)][new OrdinalOrName(id)][new OrdinalOrName(0)].Data = ByteBuffer.Wrap(icon);
-                       }
-                       root[new OrdinalOrName(RT_GROUP_ICON)][new OrdinalOrName(32512)][new OrdinalOrName(0)].Data = group;
-               }
-
-               internal void AddManifest(byte[] manifest, ushort resourceID)
-               {
-                       root[new OrdinalOrName(RT_MANIFEST)][new OrdinalOrName(resourceID)][new OrdinalOrName(0)].Data = ByteBuffer.Wrap(manifest);
-               }
-
-               internal void ExtractResources(byte[] buf)
-               {
-                       ByteReader br = new ByteReader(buf, 0, buf.Length);
-                       while (br.Length >= 32)
-                       {
-                               br.Align(4);
-                               RESOURCEHEADER hdr = new RESOURCEHEADER(br);
-                               if (hdr.DataSize != 0)
-                               {
-                                       root[hdr.TYPE][hdr.NAME][new OrdinalOrName(hdr.LanguageId)].Data = ByteBuffer.Wrap(br.ReadBytes(hdr.DataSize));
-                               }
-                       }
-               }
-
-               internal void Finish()
-               {
-                       if (bb != null)
-                       {
-                               throw new InvalidOperationException();
-                       }
-                       bb = new ByteBuffer(1024);
-                       linkOffsets = new List<int>();
-                       root.Write(bb, linkOffsets);
-                       root = null;
-               }
-
-               internal int Length
-               {
-                       get { return bb.Length; }
-               }
-
-               internal void Write(MetadataWriter mw, uint rva)
-               {
-                       foreach (int offset in linkOffsets)
-                       {
-                               bb.Position = offset;
-                               bb.Write(bb.GetInt32AtCurrentPosition() + (int)rva);
-                       }
-                       mw.Write(bb);
-               }
-       }
-
-       sealed class ResourceDirectoryEntry
-       {
-               internal readonly OrdinalOrName OrdinalOrName;
-               internal ByteBuffer Data;
-               private int namedEntries;
-               private readonly List<ResourceDirectoryEntry> entries = new List<ResourceDirectoryEntry>();
-
-               internal ResourceDirectoryEntry(OrdinalOrName id)
-               {
-                       this.OrdinalOrName = id;
-               }
-
-               internal ResourceDirectoryEntry this[OrdinalOrName id]
-               {
-                       get
-                       {
-                               foreach (ResourceDirectoryEntry entry in entries)
-                               {
-                                       if (entry.OrdinalOrName.IsEqual(id))
-                                       {
-                                               return entry;
-                                       }
-                               }
-                               // the entries must be sorted
-                               ResourceDirectoryEntry newEntry = new ResourceDirectoryEntry(id);
-                               if (id.Name == null)
-                               {
-                                       for (int i = namedEntries; i < entries.Count; i++)
-                                       {
-                                               if (entries[i].OrdinalOrName.IsGreaterThan(id))
-                                               {
-                                                       entries.Insert(i, newEntry);
-                                                       return newEntry;
-                                               }
-                                       }
-                                       entries.Add(newEntry);
-                                       return newEntry;
-                               }
-                               else
-                               {
-                                       for (int i = 0; i < namedEntries; i++)
-                                       {
-                                               if (entries[i].OrdinalOrName.IsGreaterThan(id))
-                                               {
-                                                       entries.Insert(i, newEntry);
-                                                       namedEntries++;
-                                                       return newEntry;
-                                               }
-                                       }
-                                       entries.Insert(namedEntries++, newEntry);
-                                       return newEntry;
-                               }
-                       }
-               }
-
-               private int DirectoryLength
-               {
-                       get
-                       {
-                               if (Data != null)
-                               {
-                                       return 16;
-                               }
-                               else
-                               {
-                                       int length = 16 + entries.Count * 8;
-                                       foreach (ResourceDirectoryEntry entry in entries)
-                                       {
-                                               length += entry.DirectoryLength;
-                                       }
-                                       return length;
-                               }
-                       }
-               }
-
-               internal void Write(ByteBuffer bb, List<int> linkOffsets)
-               {
-                       if (entries.Count != 0)
-                       {
-                               int stringTableOffset = this.DirectoryLength;
-                               Dictionary<string, int> strings = new Dictionary<string, int>();
-                               ByteBuffer stringTable = new ByteBuffer(16);
-                               int offset = 16 + entries.Count * 8;
-                               for (int pass = 0; pass < 3; pass++)
-                               {
-                                       Write(bb, pass, 0, ref offset, strings, ref stringTableOffset, stringTable);
-                               }
-                               // the pecoff spec says that the string table is between the directory entries and the data entries,
-                               // but the windows linker puts them after the data entries, so we do too.
-                               stringTable.Align(4);
-                               offset += stringTable.Length;
-                               WriteResourceDataEntries(bb, linkOffsets, ref offset);
-                               bb.Write(stringTable);
-                               WriteData(bb);
-                       }
-               }
-
-               private void WriteResourceDataEntries(ByteBuffer bb, List<int> linkOffsets, ref int offset)
-               {
-                       foreach (ResourceDirectoryEntry entry in entries)
-                       {
-                               if (entry.Data != null)
-                               {
-                                       linkOffsets.Add(bb.Position);
-                                       bb.Write(offset);
-                                       bb.Write(entry.Data.Length);
-                                       bb.Write(0);    // code page
-                                       bb.Write(0);    // reserved
-                                       offset += (entry.Data.Length + 3) & ~3;
-                               }
-                               else
-                               {
-                                       entry.WriteResourceDataEntries(bb, linkOffsets, ref offset);
-                               }
-                       }
-               }
-
-               private void WriteData(ByteBuffer bb)
-               {
-                       foreach (ResourceDirectoryEntry entry in entries)
-                       {
-                               if (entry.Data != null)
-                               {
-                                       bb.Write(entry.Data);
-                                       bb.Align(4);
-                               }
-                               else
-                               {
-                                       entry.WriteData(bb);
-                               }
-                       }
-               }
-
-               private void Write(ByteBuffer bb, int writeDepth, int currentDepth, ref int offset, Dictionary<string, int> strings, ref int stringTableOffset, ByteBuffer stringTable)
-               {
-                       if (currentDepth == writeDepth)
-                       {
-                               // directory header
-                               bb.Write(0);    // Characteristics
-                               bb.Write(0);    // Time/Date Stamp
-                               bb.Write(0);    // Version (Major / Minor)
-                               bb.Write((ushort)namedEntries);
-                               bb.Write((ushort)(entries.Count - namedEntries));
-                       }
-                       foreach (ResourceDirectoryEntry entry in entries)
-                       {
-                               if (currentDepth == writeDepth)
-                               {
-                                       entry.WriteEntry(bb, ref offset, strings, ref stringTableOffset, stringTable);
-                               }
-                               else
-                               {
-                                       entry.Write(bb, writeDepth, currentDepth + 1, ref offset, strings, ref stringTableOffset, stringTable);
-                               }
-                       }
-               }
-
-               private void WriteEntry(ByteBuffer bb, ref int offset, Dictionary<string, int> strings, ref int stringTableOffset, ByteBuffer stringTable)
-               {
-                       WriteNameOrOrdinal(bb, OrdinalOrName, strings, ref stringTableOffset, stringTable);
-                       if (Data == null)
-                       {
-                               bb.Write(0x80000000U | (uint)offset);
-                       }
-                       else
-                       {
-                               bb.Write(offset);
-                       }
-                       offset += 16 + entries.Count * 8;
-               }
-
-               private static void WriteNameOrOrdinal(ByteBuffer bb, OrdinalOrName id, Dictionary<string, int> strings, ref int stringTableOffset, ByteBuffer stringTable)
-               {
-                       if (id.Name == null)
-                       {
-                               bb.Write((int)id.Ordinal);
-                       }
-                       else
-                       {
-                               int stringOffset;
-                               if (!strings.TryGetValue(id.Name, out stringOffset))
-                               {
-                                       stringOffset = stringTableOffset;
-                                       strings.Add(id.Name, stringOffset);
-                                       stringTableOffset += id.Name.Length * 2 + 2;
-                                       stringTable.Write((ushort)id.Name.Length);
-                                       foreach (char c in id.Name)
-                                       {
-                                               stringTable.Write((short)c);
-                                       }
-                               }
-                               bb.Write(0x80000000U | (uint)stringOffset);
-                       }
-               }
-       }
-
-       struct OrdinalOrName
-       {
-               internal readonly ushort Ordinal;
-               internal readonly string Name;
-
-               internal OrdinalOrName(ushort value)
-               {
-                       Ordinal = value;
-                       Name = null;
-               }
-
-               internal OrdinalOrName(string value)
-               {
-                       Ordinal = 0xFFFF;
-                       Name = value;
-               }
-
-               internal bool IsGreaterThan(OrdinalOrName other)
-               {
-                       return this.Name == null
-                               ? this.Ordinal > other.Ordinal
-                               : String.Compare(this.Name, other.Name, StringComparison.OrdinalIgnoreCase) > 0;
-               }
-
-               internal bool IsEqual(OrdinalOrName other)
-               {
-                       return this.Name == null
-                               ? this.Ordinal == other.Ordinal
-                               : String.Compare(this.Name, other.Name, StringComparison.OrdinalIgnoreCase) == 0;
-               }
-       }
-
-       struct RESOURCEHEADER
-       {
-               internal int DataSize;
-               internal int HeaderSize;
-               internal OrdinalOrName TYPE;
-               internal OrdinalOrName NAME;
-               internal int DataVersion;
-               internal ushort MemoryFlags;
-               internal ushort LanguageId;
-               internal int Version;
-               internal int Characteristics;
-
-               internal RESOURCEHEADER(ByteReader br)
-               {
-                       DataSize = br.ReadInt32();
-                       HeaderSize = br.ReadInt32();
-                       TYPE = ReadOrdinalOrName(br);
-                       NAME = ReadOrdinalOrName(br);
-                       br.Align(4);
-                       DataVersion = br.ReadInt32();
-                       MemoryFlags = br.ReadUInt16();
-                       LanguageId = br.ReadUInt16();
-                       Version = br.ReadInt32();
-                       Characteristics = br.ReadInt32();
-               }
-
-               private static OrdinalOrName ReadOrdinalOrName(ByteReader br)
-               {
-                       char c = br.ReadChar();
-                       if (c == 0xFFFF)
-                       {
-                               return new OrdinalOrName(br.ReadUInt16());
-                       }
-                       else
-                       {
-                               StringBuilder sb = new StringBuilder();
-                               while (c != 0)
-                               {
-                                       sb.Append(c);
-                                       c = br.ReadChar();
-                               }
-                               return new OrdinalOrName(sb.ToString());
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/TextSection.cs b/mcs/class/IKVM.Reflection/Writer/TextSection.cs
deleted file mode 100644 (file)
index a8b4785..0000000
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
-  Copyright (C) 2008-2011 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using IKVM.Reflection.Emit;
-using IKVM.Reflection.Impl;
-using IKVM.Reflection.Metadata;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class TextSection
-       {
-               private readonly PEWriter peWriter;
-               private readonly CliHeader cliHeader;
-               private readonly ModuleBuilder moduleBuilder;
-               private readonly uint strongNameSignatureLength;
-               private readonly ExportTables exportTables;
-
-               internal TextSection(PEWriter peWriter, CliHeader cliHeader, ModuleBuilder moduleBuilder, int strongNameSignatureLength)
-               {
-                       this.peWriter = peWriter;
-                       this.cliHeader = cliHeader;
-                       this.moduleBuilder = moduleBuilder;
-                       this.strongNameSignatureLength = (uint)strongNameSignatureLength;
-                       if (moduleBuilder.unmanagedExports.Count != 0)
-                       {
-                               this.exportTables = new ExportTables(this);
-                       }
-               }
-
-               internal uint PointerToRawData
-               {
-                       get { return peWriter.ToFileAlignment(peWriter.HeaderSize); }
-               }
-
-               internal uint BaseRVA
-               {
-                       get { return 0x2000; }
-               }
-
-               internal uint ImportAddressTableRVA
-               {
-                       get { return BaseRVA; }
-               }
-
-               internal uint ImportAddressTableLength
-               {
-                       get
-                       {
-                               switch (peWriter.Headers.FileHeader.Machine)
-                               {
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                               return 8;
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_ARM:
-                                               return 0;
-                                       default:
-                                               return 16;
-                               }
-                       }
-               }
-
-               internal uint ComDescriptorRVA
-               {
-                       get { return ImportAddressTableRVA + ImportAddressTableLength; }
-               }
-
-               internal uint ComDescriptorLength
-               {
-                       get { return cliHeader.Cb; }
-               }
-
-               internal uint MethodBodiesRVA
-               {
-                       get { return (ComDescriptorRVA + ComDescriptorLength + 7) & ~7U; }
-               }
-
-               private uint MethodBodiesLength
-               {
-                       get { return (uint)moduleBuilder.methodBodies.Length; }
-               }
-
-               private uint ResourcesRVA
-               {
-                       get
-                       {
-                               switch (peWriter.Headers.FileHeader.Machine)
-                               {
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_ARM:
-                                               return (MethodBodiesRVA + MethodBodiesLength + 3) & ~3U;
-                                       default:
-                                               return (MethodBodiesRVA + MethodBodiesLength + 15) & ~15U;
-                               }
-                       }
-               }
-
-               private uint ResourcesLength
-               {
-                       get { return (uint)moduleBuilder.manifestResources.Length; }
-               }
-
-               internal uint StrongNameSignatureRVA
-               {
-                       get
-                       {
-                               return (ResourcesRVA + ResourcesLength + 3) & ~3U;
-                       }
-               }
-
-               internal uint StrongNameSignatureLength
-               {
-                       get
-                       {
-                               return strongNameSignatureLength;
-                       }
-               }
-
-               private uint MetadataRVA
-               {
-                       get
-                       {
-                               return (StrongNameSignatureRVA + StrongNameSignatureLength + 3) & ~3U;
-                       }
-               }
-
-               private uint MetadataLength
-               {
-                       get { return (uint)moduleBuilder.MetadataLength; }
-               }
-
-               private uint VTableFixupsRVA
-               {
-                       get { return (MetadataRVA + MetadataLength + 7) & ~7U; }
-               }
-
-               private uint VTableFixupsLength
-               {
-                       get { return (uint)moduleBuilder.vtablefixups.Count * 8; }
-               }
-
-               internal uint DebugDirectoryRVA
-               {
-                       get { return VTableFixupsRVA + VTableFixupsLength; }
-               }
-
-               internal uint DebugDirectoryLength
-               {
-                       get
-                       {
-                               if (DebugDirectoryContentsLength != 0)
-                               {
-                                       return 28;
-                               }
-                               return 0;
-                       }
-               }
-
-               private uint DebugDirectoryContentsLength
-               {
-                       get
-                       {
-                               if (moduleBuilder.symbolWriter != null)
-                               {
-                                       IMAGE_DEBUG_DIRECTORY idd = new IMAGE_DEBUG_DIRECTORY();
-                                       return (uint)SymbolSupport.GetDebugInfo(moduleBuilder.symbolWriter, ref idd).Length;
-                               }
-                               return 0;
-                       }
-               }
-
-               internal uint ExportDirectoryRVA
-               {
-                       get { return (DebugDirectoryRVA + DebugDirectoryLength + DebugDirectoryContentsLength + 15) & ~15U; }
-               }
-
-               internal uint ExportDirectoryLength
-               {
-                       get { return moduleBuilder.unmanagedExports.Count == 0 ? 0U : 40U; }
-               }
-
-               private uint ExportTablesRVA
-               {
-                       get { return ExportDirectoryRVA + ExportDirectoryLength; }
-               }
-
-               private uint ExportTablesLength
-               {
-                       get { return exportTables == null ? 0U : exportTables.Length; }
-               }
-
-               internal uint ImportDirectoryRVA
-               {
-                       // on AMD64 (and probably IA64) the import directory needs to be 16 byte aligned (on I386 4 byte alignment is sufficient)
-                       get { return (ExportTablesRVA + ExportTablesLength + 15) & ~15U; }
-               }
-
-               internal uint ImportDirectoryLength
-               {
-                       get
-                       {
-                               switch (peWriter.Headers.FileHeader.Machine)
-                               {
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_ARM:
-                                               return 0;
-                                       default:
-                                               return (ImportHintNameTableRVA - ImportDirectoryRVA) + 27;
-                               }
-                       }
-               }
-
-               private uint ImportHintNameTableRVA
-               {
-                       get
-                       {
-                               if (peWriter.Headers.FileHeader.Machine == IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386)
-                               {
-                                       return (ImportDirectoryRVA + 48 + 15) & ~15U;
-                               }
-                               else
-                               {
-                                       return (ImportDirectoryRVA + 48 + 4 + 15) & ~15U;
-                               }
-                       }
-               }
-
-               internal uint StartupStubRVA
-               {
-                       get
-                       {
-                               if (peWriter.Headers.FileHeader.Machine == IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64)
-                               {
-                                       // note that the alignment is driven by the requirement that the two relocation fixups are in a single page
-                                       return (ImportDirectoryRVA + ImportDirectoryLength + 15U) & ~15U;
-                               }
-                               else
-                               {
-                                       // the additional 2 bytes padding are to align the address in the jump (which is a relocation fixup)
-                                       return 2 + ((ImportDirectoryRVA + ImportDirectoryLength + 3U) & ~3U);
-                               }
-                       }
-               }
-
-               internal uint StartupStubLength
-               {
-                       get
-                       {
-                               switch (peWriter.Headers.FileHeader.Machine)
-                               {
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                               return 6;
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                                               return 12;
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64:
-                                               return 48;
-                                       default:
-                                               return 0;
-                               }
-                       }
-               }
-
-               private void WriteRVA(MetadataWriter mw, uint rva)
-               {
-                       switch (peWriter.Headers.FileHeader.Machine)
-                       {
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_ARM:
-                                       mw.Write(rva);
-                                       break;
-                               default:
-                                       mw.Write((ulong)rva);
-                                       break;
-                       }
-               }
-
-               internal void Write(MetadataWriter mw, uint sdataRVA)
-               {
-                       // Now that we're ready to start writing, we need to do some fix ups
-                       moduleBuilder.TypeRef.Fixup(moduleBuilder);
-                       moduleBuilder.MethodDef.Fixup(this);
-                       moduleBuilder.MethodImpl.Fixup(moduleBuilder);
-                       moduleBuilder.MethodSemantics.Fixup(moduleBuilder);
-                       moduleBuilder.InterfaceImpl.Fixup();
-                       moduleBuilder.ResolveInterfaceImplPseudoTokens();
-                       moduleBuilder.MemberRef.Fixup(moduleBuilder);
-                       moduleBuilder.Constant.Fixup(moduleBuilder);
-                       moduleBuilder.FieldMarshal.Fixup(moduleBuilder);
-                       moduleBuilder.DeclSecurity.Fixup(moduleBuilder);
-                       moduleBuilder.GenericParam.Fixup(moduleBuilder);
-                       moduleBuilder.CustomAttribute.Fixup(moduleBuilder);
-                       moduleBuilder.FieldLayout.Fixup(moduleBuilder);
-                       moduleBuilder.FieldRVA.Fixup(moduleBuilder, (int)sdataRVA, (int)this.MethodBodiesRVA);
-                       moduleBuilder.ImplMap.Fixup(moduleBuilder);
-                       moduleBuilder.ExportedType.Fixup(moduleBuilder);
-                       moduleBuilder.ManifestResource.Fixup(moduleBuilder);
-                       moduleBuilder.MethodSpec.Fixup(moduleBuilder);
-                       moduleBuilder.GenericParamConstraint.Fixup(moduleBuilder);
-
-                       // Import Address Table
-                       AssertRVA(mw, ImportAddressTableRVA);
-                       if (ImportAddressTableLength != 0)
-                       {
-                               WriteRVA(mw, ImportHintNameTableRVA);
-                               WriteRVA(mw, 0);
-                       }
-
-                       // CLI Header
-                       AssertRVA(mw, ComDescriptorRVA);
-                       cliHeader.MetaData.VirtualAddress = MetadataRVA;
-                       cliHeader.MetaData.Size = MetadataLength;
-                       if (ResourcesLength != 0)
-                       {
-                               cliHeader.Resources.VirtualAddress = ResourcesRVA;
-                               cliHeader.Resources.Size = ResourcesLength;
-                       }
-                       if (StrongNameSignatureLength != 0)
-                       {
-                               cliHeader.StrongNameSignature.VirtualAddress = StrongNameSignatureRVA;
-                               cliHeader.StrongNameSignature.Size = StrongNameSignatureLength;
-                       }
-                       if (VTableFixupsLength != 0)
-                       {
-                               cliHeader.VTableFixups.VirtualAddress = VTableFixupsRVA;
-                               cliHeader.VTableFixups.Size = VTableFixupsLength;
-                       }
-                       cliHeader.Write(mw);
-
-                       // alignment padding
-                       for (int i = (int)(MethodBodiesRVA - (ComDescriptorRVA + ComDescriptorLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Method Bodies
-                       mw.Write(moduleBuilder.methodBodies);
-
-                       // alignment padding
-                       for (int i = (int)(ResourcesRVA - (MethodBodiesRVA + MethodBodiesLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Resources
-                       mw.Write(moduleBuilder.manifestResources);
-
-                       // The strong name signature live here (if it exists), but it will written later
-                       // and the following alignment padding will take care of reserving the space.
-
-                       // alignment padding
-                       for (int i = (int)(MetadataRVA - (ResourcesRVA + ResourcesLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Metadata
-                       AssertRVA(mw, MetadataRVA);
-                       moduleBuilder.WriteMetadata(mw);
-
-                       // alignment padding
-                       for (int i = (int)(VTableFixupsRVA - (MetadataRVA + MetadataLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // VTableFixups
-                       AssertRVA(mw, VTableFixupsRVA);
-                       WriteVTableFixups(mw, sdataRVA);
-
-                       // Debug Directory
-                       AssertRVA(mw, DebugDirectoryRVA);
-                       WriteDebugDirectory(mw);
-
-                       // alignment padding
-                       for (int i = (int)(ExportDirectoryRVA - (DebugDirectoryRVA + DebugDirectoryLength + DebugDirectoryContentsLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Export Directory
-                       AssertRVA(mw, ExportDirectoryRVA);
-                       WriteExportDirectory(mw);
-
-                       // Export Tables
-                       AssertRVA(mw, ExportTablesRVA);
-                       WriteExportTables(mw, sdataRVA);
-       
-                       // alignment padding
-                       for (int i = (int)(ImportDirectoryRVA - (ExportTablesRVA + ExportTablesLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Import Directory
-                       AssertRVA(mw, ImportDirectoryRVA);
-                       if (ImportDirectoryLength != 0)
-                       {
-                               WriteImportDirectory(mw);
-                       }
-
-                       // alignment padding
-                       for (int i = (int)(StartupStubRVA - (ImportDirectoryRVA + ImportDirectoryLength)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Startup Stub
-                       AssertRVA(mw, StartupStubRVA);
-                       if (peWriter.Headers.FileHeader.Machine == IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64)
-                       {
-                               /*
-                                *   48 A1 00 20 40 00 00 00 00 00        mov         rax,qword ptr [0000000000402000h]
-                                *   FF E0                                jmp         rax
-                                */
-                               mw.Write((ushort)0xA148);
-                               mw.Write(peWriter.Headers.OptionalHeader.ImageBase + ImportAddressTableRVA);
-                               mw.Write((ushort)0xE0FF);
-                       }
-                       else if (peWriter.Headers.FileHeader.Machine == IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64)
-                       {
-                               mw.Write(new byte[] {
-                                               0x0B, 0x48, 0x00, 0x02, 0x18, 0x10, 0xA0, 0x40, 0x24, 0x30, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00,
-                                               0x10, 0x08, 0x00, 0x12, 0x18, 0x10, 0x60, 0x50, 0x04, 0x80, 0x03, 0x00, 0x60, 0x00, 0x80, 0x00
-                                       });
-                               mw.Write(peWriter.Headers.OptionalHeader.ImageBase + StartupStubRVA);
-                               mw.Write(peWriter.Headers.OptionalHeader.ImageBase + BaseRVA);
-                       }
-                       else if (peWriter.Headers.FileHeader.Machine == IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386)
-                       {
-                               mw.Write((ushort)0x25FF);
-                               mw.Write((uint)peWriter.Headers.OptionalHeader.ImageBase + ImportAddressTableRVA);
-                       }
-               }
-
-               [Conditional("DEBUG")]
-               private void AssertRVA(MetadataWriter mw, uint rva)
-               {
-                       Debug.Assert(mw.Position - PointerToRawData + BaseRVA == rva);
-               }
-
-               private void WriteVTableFixups(MetadataWriter mw, uint sdataRVA)
-               {
-                       foreach (ModuleBuilder.VTableFixups fixups in moduleBuilder.vtablefixups)
-                       {
-                               mw.Write(fixups.initializedDataOffset + sdataRVA);
-                               mw.Write(fixups.count);
-                               mw.Write(fixups.type);
-                       }
-               }
-
-               private void WriteDebugDirectory(MetadataWriter mw)
-               {
-                       if (DebugDirectoryLength != 0)
-                       {
-                               IMAGE_DEBUG_DIRECTORY idd = new IMAGE_DEBUG_DIRECTORY();
-                               idd.Characteristics = 0;
-                               idd.TimeDateStamp = peWriter.Headers.FileHeader.TimeDateStamp;
-                               byte[] buf = SymbolSupport.GetDebugInfo(moduleBuilder.symbolWriter, ref idd);
-                               idd.PointerToRawData = (DebugDirectoryRVA - BaseRVA) + DebugDirectoryLength + PointerToRawData;
-                               idd.AddressOfRawData = DebugDirectoryRVA + DebugDirectoryLength;
-                               mw.Write(idd.Characteristics);
-                               mw.Write(idd.TimeDateStamp);
-                               mw.Write(idd.MajorVersion);
-                               mw.Write(idd.MinorVersion);
-                               mw.Write(idd.Type);
-                               mw.Write(idd.SizeOfData);
-                               mw.Write(idd.AddressOfRawData);
-                               mw.Write(idd.PointerToRawData);
-                               mw.Write(buf);
-                       }
-               }
-
-               private sealed class ExportTables
-               {
-                       private readonly TextSection text;
-                       internal readonly uint entries;
-                       internal readonly uint ordinalBase;
-                       internal readonly uint nameCount;
-                       internal readonly uint namesLength;
-                       internal readonly uint exportAddressTableRVA;
-                       internal readonly uint exportNamePointerTableRVA;
-                       internal readonly uint exportOrdinalTableRVA;
-                       internal readonly uint namesRVA;
-                       internal readonly uint stubsRVA;
-                       private readonly uint stubLength;
-
-                       internal ExportTables(TextSection text)
-                       {
-                               this.text = text;
-                               ordinalBase = GetOrdinalBase(out entries);
-                               namesLength = GetExportNamesLength(out nameCount);
-                               exportAddressTableRVA = text.ExportTablesRVA;
-                               exportNamePointerTableRVA = exportAddressTableRVA + 4 * entries;
-                               exportOrdinalTableRVA = exportNamePointerTableRVA + 4 * nameCount;
-                               namesRVA = exportOrdinalTableRVA + 2 * nameCount;
-                               stubsRVA = (namesRVA + namesLength + 15) & ~15U;
-                               // note that we align the stubs to avoid having to deal with the relocation crossing a page boundary
-                               switch (text.peWriter.Headers.FileHeader.Machine)
-                               {
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                               stubLength = 8;
-                                               break;
-                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                                               stubLength = 16;
-                                               break;
-                                       default:
-                                               throw new NotImplementedException();
-                               }
-                       }
-
-                       internal uint Length
-                       {
-                               get { return (stubsRVA + stubLength * (uint)text.moduleBuilder.unmanagedExports.Count) - text.ExportTablesRVA; }
-                       }
-
-                       private uint GetOrdinalBase(out uint entries)
-                       {
-                               uint min = uint.MaxValue;
-                               uint max = uint.MinValue;
-                               foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
-                               {
-                                       uint ordinal = (uint)exp.ordinal;
-                                       min = Math.Min(min, ordinal);
-                                       max = Math.Max(max, ordinal);
-                               }
-                               entries = 1 + (max - min);
-                               return min;
-                       }
-
-                       private uint GetExportNamesLength(out uint nameCount)
-                       {
-                               nameCount = 0;
-                               // the first name in the names list is the module name (the Export Directory contains a name of the current module)
-                               uint length = (uint)text.moduleBuilder.fileName.Length + 1;
-                               foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
-                               {
-                                       if (exp.name != null)
-                                       {
-                                               nameCount++;
-                                               length += (uint)exp.name.Length + 1;
-                                       }
-                               }
-                               return length;
-                       }
-
-                       internal void Write(MetadataWriter mw, uint sdataRVA)
-                       {
-                               // sort the exports by ordinal
-                               text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportOrdinals);
-
-                               // Now write the Export Address Table
-                               text.AssertRVA(mw, exportAddressTableRVA);
-                               for (int i = 0, pos = 0; i < entries; i++)
-                               {
-                                       if (text.moduleBuilder.unmanagedExports[pos].ordinal == i + ordinalBase)
-                                       {
-                                               mw.Write(stubsRVA + (uint)pos * stubLength);
-                                               pos++;
-                                       }
-                                       else
-                                       {
-                                               mw.Write(0);
-                                       }
-                               }
-
-                               // sort the exports by name
-                               text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportNames);
-
-                               // Now write the Export Name Pointer Table
-                               text.AssertRVA(mw, exportNamePointerTableRVA);
-                               uint nameOffset = (uint)text.moduleBuilder.fileName.Length + 1;
-                               foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
-                               {
-                                       if (exp.name != null)
-                                       {
-                                               mw.Write(namesRVA + nameOffset);
-                                               nameOffset += (uint)exp.name.Length + 1;
-                                       }
-                               }
-
-                               // Now write the Export Ordinal Table
-                               text.AssertRVA(mw, exportOrdinalTableRVA);
-                               foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
-                               {
-                                       if (exp.name != null)
-                                       {
-                                               mw.Write((ushort)(exp.ordinal - ordinalBase));
-                                       }
-                               }
-
-                               // Now write the actual names
-                               text.AssertRVA(mw, namesRVA);
-                               mw.Write(Encoding.ASCII.GetBytes(text.moduleBuilder.fileName));
-                               mw.Write((byte)0);
-                               foreach (UnmanagedExport exp in text.moduleBuilder.unmanagedExports)
-                               {
-                                       if (exp.name != null)
-                                       {
-                                               mw.Write(Encoding.ASCII.GetBytes(exp.name));
-                                               mw.Write((byte)0);
-                                       }
-                               }
-                               text.AssertRVA(mw, namesRVA + namesLength);
-
-                               // alignment padding
-                               for (int i = (int)(stubsRVA - (namesRVA + namesLength)); i > 0; i--)
-                               {
-                                       mw.Write((byte)0);
-                               }
-
-                               // sort the exports by ordinal
-                               text.moduleBuilder.unmanagedExports.Sort(CompareUnmanagedExportOrdinals);
-
-                               // Now write the stubs
-                               text.AssertRVA(mw, stubsRVA);
-
-                               for (int i = 0, pos = 0; i < entries; i++)
-                               {
-                                       if (text.moduleBuilder.unmanagedExports[pos].ordinal == i + ordinalBase)
-                                       {
-                                               switch (text.peWriter.Headers.FileHeader.Machine)
-                                               {
-                                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                                               mw.Write((byte)0xFF);
-                                                               mw.Write((byte)0x25);
-                                                               mw.Write((uint)text.peWriter.Headers.OptionalHeader.ImageBase + text.moduleBuilder.unmanagedExports[pos].rva.initializedDataOffset + sdataRVA);
-                                                               mw.Write((short)0);     // alignment
-                                                               break;
-                                                       case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                                                               mw.Write((byte)0x48);
-                                                               mw.Write((byte)0xA1);
-                                                               mw.Write(text.peWriter.Headers.OptionalHeader.ImageBase + text.moduleBuilder.unmanagedExports[pos].rva.initializedDataOffset + sdataRVA);
-                                                               mw.Write((byte)0xFF);
-                                                               mw.Write((byte)0xE0);
-                                                               mw.Write(0); // alignment
-                                                               break;
-                                                       default:
-                                                               throw new NotImplementedException();
-                                               }
-                                               pos++;
-                                       }
-                               }
-                       }
-
-                       private static int CompareUnmanagedExportNames(UnmanagedExport x, UnmanagedExport y)
-                       {
-                               if (x.name == null)
-                               {
-                                       return y.name == null ? 0 : 1;
-                               }
-                               if (y.name == null)
-                               {
-                                       return -1;
-                               }
-                               return x.name.CompareTo(y.name);
-                       }
-
-                       private static int CompareUnmanagedExportOrdinals(UnmanagedExport x, UnmanagedExport y)
-                       {
-                               return x.ordinal.CompareTo(y.ordinal);
-                       }
-
-                       internal void WriteRelocations(MetadataWriter mw)
-                       {
-                               // we assume that unmanagedExports is still sorted by ordinal
-                               for (int i = 0, pos = 0; i < entries; i++)
-                               {
-                                       if (text.moduleBuilder.unmanagedExports[pos].ordinal == i + ordinalBase)
-                                       {
-                                               // both I386 and AMD64 have the address at offset 2
-                                               text.WriteRelocationBlock(mw, stubsRVA + 2 + (uint)pos * stubLength);
-                                               pos++;
-                                       }
-                               }
-                       }
-               }
-
-               private uint GetOrdinalBase(out uint entries)
-               {
-                       uint min = uint.MaxValue;
-                       uint max = uint.MinValue;
-                       foreach (UnmanagedExport exp in moduleBuilder.unmanagedExports)
-                       {
-                               uint ordinal = (uint)exp.ordinal;
-                               min = Math.Min(min, ordinal);
-                               max = Math.Max(max, ordinal);
-                       }
-                       entries = 1 + (max - min);
-                       return min;
-               }
-
-               private uint GetExportNamesLength(out uint nameCount)
-               {
-                       nameCount = 0;
-                       uint length = 0;
-                       foreach (UnmanagedExport exp in moduleBuilder.unmanagedExports)
-                       {
-                               if (exp.name != null)
-                               {
-                                       nameCount++;
-                                       length += (uint)exp.name.Length + 1;
-                               }
-                       }
-                       return length;
-               }
-
-               private void WriteExportDirectory(MetadataWriter mw)
-               {
-                       if (ExportDirectoryLength != 0)
-                       {
-                               // Flags
-                               mw.Write(0);
-                               // Date/Time Stamp
-                               mw.Write(peWriter.Headers.FileHeader.TimeDateStamp);
-                               // Major Version
-                               mw.Write((short)0);
-                               // Minor Version
-                               mw.Write((short)0);
-                               // Name RVA
-                               mw.Write(exportTables.namesRVA);
-                               // Ordinal Base
-                               mw.Write(exportTables.ordinalBase);
-                               // Address Table Entries
-                               mw.Write(exportTables.entries);
-                               // Number of Name Pointers
-                               mw.Write(exportTables.nameCount);
-                               // Export Address Table RVA
-                               mw.Write(exportTables.exportAddressTableRVA);
-                               // Name Pointer RVA
-                               mw.Write(exportTables.exportNamePointerTableRVA);
-                               // Ordinal Table RVA
-                               mw.Write(exportTables.exportOrdinalTableRVA);
-                       }
-               }
-
-               private void WriteExportTables(MetadataWriter mw, uint sdataRVA)
-               {
-                       if (exportTables != null)
-                       {
-                               exportTables.Write(mw, sdataRVA);
-                       }
-               }
-
-               private void WriteImportDirectory(MetadataWriter mw)
-               {
-                       mw.Write(ImportDirectoryRVA + 40);              // ImportLookupTable
-                       mw.Write(0);                                                    // DateTimeStamp
-                       mw.Write(0);                                                    // ForwarderChain
-                       mw.Write(ImportHintNameTableRVA + 14);  // Name
-                       mw.Write(ImportAddressTableRVA);
-                       mw.Write(new byte[20]);
-                       // Import Lookup Table
-                       mw.Write(ImportHintNameTableRVA);               // Hint/Name Table RVA
-                       int size = 48;
-                       if (peWriter.Headers.FileHeader.Machine != IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386)
-                       {
-                               size += 4;
-                               mw.Write(0);
-                       }
-                       mw.Write(0);
-
-                       // alignment padding
-                       for (int i = (int)(ImportHintNameTableRVA - (ImportDirectoryRVA + size)); i > 0; i--)
-                       {
-                               mw.Write((byte)0);
-                       }
-
-                       // Hint/Name Table
-                       AssertRVA(mw, ImportHintNameTableRVA);
-                       mw.Write((ushort)0);            // Hint
-                       if ((peWriter.Headers.FileHeader.Characteristics & IMAGE_FILE_HEADER.IMAGE_FILE_DLL) != 0)
-                       {
-                               mw.Write(System.Text.Encoding.ASCII.GetBytes("_CorDllMain"));
-                       }
-                       else
-                       {
-                               mw.Write(System.Text.Encoding.ASCII.GetBytes("_CorExeMain"));
-                       }
-                       mw.Write((byte)0);
-                       // Name
-                       mw.Write(System.Text.Encoding.ASCII.GetBytes("mscoree.dll"));
-                       mw.Write((ushort)0);
-               }
-
-               internal int Length
-               {
-                       get { return (int)(StartupStubRVA - BaseRVA + StartupStubLength); }
-               }
-
-               internal void WriteRelocations(MetadataWriter mw)
-               {
-                       uint relocAddress = this.StartupStubRVA;
-                       switch (peWriter.Headers.FileHeader.Machine)
-                       {
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                                       relocAddress += 2;
-                                       break;
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64:
-                                       relocAddress += 0x20;
-                                       break;
-                       }
-                       WriteRelocationBlock(mw, relocAddress);
-                       if (exportTables != null)
-                       {
-                               exportTables.WriteRelocations(mw);
-                       }
-               }
-
-               // note that we're lazy and write a new relocation block for every relocation
-               // even if they are in the same page (since there is typically only one anyway)
-               private void WriteRelocationBlock(MetadataWriter mw, uint relocAddress)
-               {
-                       uint pageRVA = relocAddress & ~0xFFFU;
-                       mw.Write(pageRVA);      // PageRVA
-                       mw.Write(0x000C);       // Block Size
-                       switch (peWriter.Headers.FileHeader.Machine)
-                       {
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_I386:
-                                       mw.Write(0x3000 + relocAddress - pageRVA);                              // Type / Offset
-                                       break;
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_AMD64:
-                                       mw.Write(0xA000 + relocAddress - pageRVA);                              // Type / Offset
-                                       break;
-                               case IMAGE_FILE_HEADER.IMAGE_FILE_MACHINE_IA64:
-                                       // on IA64 the StartupStubRVA is 16 byte aligned, so these two addresses won't cross a page boundary
-                                       mw.Write((short)(0xA000 + relocAddress - pageRVA));             // Type / Offset
-                                       mw.Write((short)(0xA000 + relocAddress - pageRVA + 8)); // Type / Offset
-                                       break;
-                       }
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/Writer/VersionInfo.cs b/mcs/class/IKVM.Reflection/Writer/VersionInfo.cs
deleted file mode 100644 (file)
index 4c76b49..0000000
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
-  Copyright (C) 2008 Jeroen Frijters
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-
-  Jeroen Frijters
-  jeroen@frijters.net
-  
-*/
-using System;
-using System.Globalization;
-using IKVM.Reflection.Emit;
-
-namespace IKVM.Reflection.Writer
-{
-       sealed class VersionInfo
-       {
-               private AssemblyName name;
-               private string fileName;
-               internal string copyright;
-               internal string trademark;
-               internal string product;
-               internal string company;
-               private string description;
-               private string title;
-               internal string informationalVersion;
-               private string fileVersion;
-
-               internal void SetName(AssemblyName name)
-               {
-                       this.name = name;
-               }
-
-               internal void SetFileName(string assemblyFileName)
-               {
-                       this.fileName = assemblyFileName;
-               }
-
-               internal void SetAttribute(CustomAttributeBuilder cab)
-               {
-                       Universe u = cab.Constructor.Module.universe;
-                       Type type = cab.Constructor.DeclaringType;
-                       if (copyright == null && type == u.System_Reflection_AssemblyCopyrightAttribute)
-                       {
-                               copyright = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (trademark == null && type == u.System_Reflection_AssemblyTrademarkAttribute)
-                       {
-                               trademark = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (product == null && type == u.System_Reflection_AssemblyProductAttribute)
-                       {
-                               product = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (company == null && type == u.System_Reflection_AssemblyCompanyAttribute)
-                       {
-                               company = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (description == null && type == u.System_Reflection_AssemblyDescriptionAttribute)
-                       {
-                               description = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (title == null && type == u.System_Reflection_AssemblyTitleAttribute)
-                       {
-                               title = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (informationalVersion == null && type == u.System_Reflection_AssemblyInformationalVersionAttribute)
-                       {
-                               informationalVersion = (string)cab.GetConstructorArgument(0);
-                       }
-                       else if (fileVersion == null && type == u.System_Reflection_AssemblyFileVersionAttribute)
-                       {
-                               fileVersion = (string)cab.GetConstructorArgument(0);
-                       }
-               }
-
-               internal void Write(ByteBuffer bb)
-               {
-                       if (fileVersion == null)
-                       {
-                               if (name.Version != null)
-                               {
-                                       fileVersion = name.Version.ToString();
-                               }
-                               else
-                               {
-                                       fileVersion = "0.0.0.0";
-                               }
-                       }
-
-                       int codepage = 1200;    // Unicode codepage
-                       int lcid = 0x7f;
-                       try
-                       {
-                               if (name.CultureInfo != null)
-                               {
-                                       lcid = name.CultureInfo.LCID;
-                               }
-                       }
-                       catch (ArgumentException)
-                       {
-                               // AssemblyName.CultureInfo throws an ArgumentException if AssemblyBuilder.__SetAssemblyCulture() was used to specify a non-existing culture
-                       }
-
-                       Version filever = ParseVersionRobust(fileVersion);
-                       int fileVersionMajor = filever.Major;
-                       int fileVersionMinor = filever.Minor;
-                       int fileVersionBuild = filever.Build;
-                       int fileVersionRevision = filever.Revision;
-
-                       int productVersionMajor = fileVersionMajor;
-                       int productVersionMinor = fileVersionMinor;
-                       int productVersionBuild = fileVersionBuild;
-                       int productVersionRevision = fileVersionRevision;
-                       if (informationalVersion != null)
-                       {
-                               Version productver = ParseVersionRobust(informationalVersion);
-                               productVersionMajor = productver.Major;
-                               productVersionMinor = productver.Minor;
-                               productVersionBuild = productver.Build;
-                               productVersionRevision = productver.Revision;
-                       }
-
-                       ByteBuffer stringTable = new ByteBuffer(512);
-                       stringTable.Write((short)0);    // wLength (placeholder)
-                       stringTable.Write((short)0);    // wValueLength
-                       stringTable.Write((short)1);    // wType
-                       WriteUTF16Z(stringTable, string.Format("{0:x4}{1:x4}", lcid, codepage));
-                       stringTable.Align(4);
-
-                       WriteString(stringTable, "Comments", description);
-                       WriteString(stringTable, "CompanyName", company);
-                       WriteString(stringTable, "FileDescription", title);
-                       WriteString(stringTable, "FileVersion", fileVersion);
-                       WriteString(stringTable, "InternalName", name.Name);
-                       WriteString(stringTable, "LegalCopyright", copyright);
-                       WriteString(stringTable, "LegalTrademarks", trademark);
-                       WriteString(stringTable, "OriginalFilename", fileName);
-                       WriteString(stringTable, "ProductName", product);
-                       WriteString(stringTable, "ProductVersion", informationalVersion);
-
-                       stringTable.Position = 0;
-                       stringTable.Write((short)stringTable.Length);
-
-                       ByteBuffer stringFileInfo = new ByteBuffer(512);
-                       stringFileInfo.Write((short)0); // wLength (placeholder)
-                       stringFileInfo.Write((short)0); // wValueLength
-                       stringFileInfo.Write((short)1); // wType
-                       WriteUTF16Z(stringFileInfo, "StringFileInfo");
-                       stringFileInfo.Align(4);
-                       stringFileInfo.Write(stringTable);
-                       stringFileInfo.Position = 0;
-                       stringFileInfo.Write((short)stringFileInfo.Length);
-
-                       byte[] preamble1 = new byte[] {
-                         // VS_VERSIONINFO (platform SDK)
-                         0x34, 0x00,                           // wValueLength
-                         0x00, 0x00,                           // wType
-                         0x56, 0x00, 0x53, 0x00, 0x5F, 0x00, 0x56, 0x00, 0x45, 0x00, 0x52, 0x00, 0x53, 0x00, 0x49, 0x00, 0x4F, 0x00, 0x4E, 0x00, 0x5F, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x46, 0x00, 0x4F, 0x00, 0x00, 0x00,  // "VS_VERSION_INFO\0"
-                         0x00, 0x00,                           // Padding1 (32 bit alignment)
-                         // VS_FIXEDFILEINFO starts
-                         0xBD, 0x04, 0xEF, 0xFE,       // dwSignature (0xFEEF04BD)
-                         0x00, 0x00, 0x01, 0x00,       // dwStrucVersion
-                       };
-                       byte[] preamble2 = new byte[] {
-                         0x3F, 0x00, 0x00, 0x00,       // dwFileFlagsMask (??)
-                         0x00, 0x00, 0x00, 0x00,       // dwFileFlags (??)
-                         0x04, 0x00, 0x00, 0x00,       // dwFileOS
-                         0x02, 0x00, 0x00, 0x00,       // dwFileType
-                         0x00, 0x00, 0x00, 0x00,       // dwFileSubtype
-                         0x00, 0x00, 0x00, 0x00,       // dwFileDateMS
-                         0x00, 0x00, 0x00, 0x00,       // dwFileDateLS
-                                                                               // Padding2 (32 bit alignment)
-                         // VarFileInfo
-                         0x44, 0x00,                           // wLength
-                         0x00, 0x00,                           // wValueLength
-                         0x01, 0x00,                           // wType
-                         0x56, 0x00, 0x61, 0x00, 0x72, 0x00, 0x46, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x49, 0x00, 0x6E, 0x00, 0x66, 0x00, 0x6F, 0x00, 0x00, 0x00,       // "VarFileInfo\0"
-                         0x00, 0x00,                           // Padding
-                         // Var
-                         0x24, 0x00,                           // wLength
-                         0x04, 0x00,                           // wValueLength
-                         0x00, 0x00,                           // wType
-                         0x54, 0x00, 0x72, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x00, 0x00,       // "Translation\0"
-                         0x00, 0x00,                           // Padding (32 bit alignment)
-                       };
-                       bb.Write((short)(2 + preamble1.Length + 8 + 8 + preamble2.Length + 4 + stringFileInfo.Length));
-                       bb.Write(preamble1);
-                       bb.Write((short)fileVersionMinor);
-                       bb.Write((short)fileVersionMajor);
-                       bb.Write((short)fileVersionRevision);
-                       bb.Write((short)fileVersionBuild);
-                       bb.Write((short)productVersionMinor);
-                       bb.Write((short)productVersionMajor);
-                       bb.Write((short)productVersionRevision);
-                       bb.Write((short)productVersionBuild);
-                       bb.Write(preamble2);
-                       bb.Write((short)lcid);
-                       bb.Write((short)codepage);
-                       bb.Write(stringFileInfo);
-               }
-
-               private static void WriteUTF16Z(ByteBuffer bb, string str)
-               {
-                       foreach (char c in str)
-                       {
-                               bb.Write((short)c);
-                       }
-                       bb.Write((short)0);
-               }
-
-               private static void WriteString(ByteBuffer bb, string name, string value)
-               {
-                       value = value ?? " ";
-                       int pos = bb.Position;
-                       bb.Write((short)0);                                     // wLength (placeholder)
-                       bb.Write((short)(value.Length + 1));// wValueLength
-                       bb.Write((short)1);                                     // wType
-                       WriteUTF16Z(bb, name);
-                       bb.Align(4);
-                       WriteUTF16Z(bb, value);
-                       bb.Align(4);
-                       int savedPos = bb.Position;
-                       bb.Position = pos;
-                       bb.Write((short)(savedPos - pos));
-                       bb.Position = savedPos;
-               }
-
-               private static Version ParseVersionRobust(string ver)
-               {
-                       int index = 0;
-                       ushort major = ParseVersionPart(ver, ref index);
-                       ushort minor = ParseVersionPart(ver, ref index);
-                       ushort build = ParseVersionPart(ver, ref index);
-                       ushort revision = ParseVersionPart(ver, ref index);
-                       return new Version(major, minor, build, revision);
-               }
-
-               private static ushort ParseVersionPart(string str, ref int pos)
-               {
-                       ushort value = 0;
-                       while (pos < str.Length)
-                       {
-                               char c = str[pos];
-                               if (c == '.')
-                               {
-                                       pos++;
-                                       break;
-                               }
-                               else if (c >= '0' && c <= '9')
-                               {
-                                       value *= 10;
-                                       value += (ushort)(c - '0');
-                                       pos++;
-                               }
-                               else
-                               {
-                                       break;
-                               }
-                       }
-                       return value;
-               }
-       }
-}
diff --git a/mcs/class/IKVM.Reflection/reflect.build b/mcs/class/IKVM.Reflection/reflect.build
deleted file mode 100644 (file)
index 2689fba..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-<?xml version="1.0"?>
-<project name="reflect" default="IKVM.Reflection">
-    <target name="IKVM.Reflection">
-        <property name="defs" value="TRACE" />
-        <if test="${framework::exists('mono-2.0')}">
-            <property name="defs" value="${defs};MONO" />
-        </if>
-        <if test="${property::exists('signed')}">
-            <property name="defs" value="${defs};${signed}" />
-        </if>
-        <if test="${version::get-major(framework::get-version(framework::get-target-framework() )) == 4}">
-            <property name="defs" value="${defs};NET_4_0" />
-        </if>
-        <!-- workaround for the fact that <include if="${framework::exists('mono-2.0')} ...> still insists on evaluating the name attribute -->
-        <property name="MonoSymbolWriter" value="dummy.dll" />
-        <if test="${framework::exists('mono-2.0')}">
-            <property name="MonoSymbolWriter" value="${path::combine(framework::get-assembly-directory('mono-2.0'), 'Mono.CompilerServices.SymbolWriter.dll')}" />
-        </if>
-        <csc target="library" output="../bin/IKVM.Reflection.dll" optimize="true" define="${defs}">
-            <sources>
-                <include name="../CommonAssemblyInfo.cs" />
-                <include name="AmbiguousMatchException.cs" />
-                <include name="Assembly.cs" />
-                <include name="AssemblyName.cs" />
-                <include name="BadImageFormatException.cs" />
-                <include name="Binder.cs" />
-                <include name="ConstructorInfo.cs" />
-                <include name="CustomAttributeData.cs" />
-                <include name="CustomAttributeNamedArgument.cs" />
-                <include name="CustomAttributeTypedArgument.cs" />
-                <include name="CustomModifiers.cs" />
-                <include name="Enums.cs" />
-                <include name="EventInfo.cs" />
-                <include name="ExceptionHandlingClause.cs" />
-                <include name="FieldInfo.cs" />
-                <include name="FieldSignature.cs" />
-                <include name="Fusion.cs" />
-                <include name="GenericWrappers.cs" />
-                <include name="InterfaceMapping.cs" />
-                <include name="LocalVariableInfo.cs" />
-                <include name="ManifestResourceInfo.cs" />
-                <include name="MarshalSpec.cs" />
-                <include name="MemberInfo.cs" />
-                <include name="MethodBase.cs" />
-                <include name="MethodBody.cs" />
-                <include name="MethodImplMap.cs" />
-                <include name="MethodInfo.cs" />
-                <include name="MethodSignature.cs" />
-                <include name="Missing.cs" />
-                <include name="Module.cs" />
-                <include name="ParameterInfo.cs" />
-                <include name="ParameterModifier.cs" />
-                <include name="PropertyInfo.cs" />
-                <include name="PropertySignature.cs" />
-                <include name="Signature.cs" />
-                <include name="StandAloneMethodSig.cs" />
-                <include name="StrongNameKeyPair.cs" />
-                <include name="Type.cs" />
-                <include name="TypeInfo.cs" />
-                <include name="TypeNameParser.cs" />
-                <include name="Universe.cs" />
-                <include name="Util.cs" />
-                <include name="Emit\AssemblyBuilder.cs" />
-                <include name="Emit\ConstructorBuilder.cs" />
-                <include name="Emit\CustomAttributeBuilder.cs" />
-                <include name="Emit\CustomModifiersBuilder.cs" />
-                <include name="Emit\EnumBuilder.cs" />
-                <include name="Emit\Enums.cs" />
-                <include name="Emit\ExceptionHandler.cs" />
-                <include name="Emit\EventBuilder.cs" />
-                <include name="Emit\FieldBuilder.cs" />
-                <include name="Emit\ILGenerator.cs" />
-                <include name="Emit\MethodBuilder.cs" />
-                <include name="Emit\ModuleBuilder.cs" />
-                <include name="Emit\OpCode.cs" />
-                <include name="Emit\OpCodes.cs" />
-                <include name="Emit\ParameterBuilder.cs" />
-                <include name="Emit\PropertyBuilder.cs" />
-                <include name="Emit\SignatureHelper.cs" />
-                <include name="Emit\Tokens.cs" />
-                <include name="Emit\TypeBuilder.cs" />
-                <include name="Impl\ITypeOwner.cs" />
-                <include name="Impl\MdbWriter.cs" />
-                <include name="Impl\PdbWriter.cs" />
-                <include name="Impl\SymbolSupport.cs" />
-                <include name="Metadata\CliHeader.cs" />
-                <include name="Metadata\MetadataRW.cs" />
-                <include name="Metadata\Tables.cs" />
-                <include name="Properties\AssemblyInfo.cs" />
-                <include name="Reader\AssemblyReader.cs" />
-                <include name="Reader\Authenticode.cs" />
-                <include name="Reader\ByteReader.cs" />
-                <include name="Reader\EventInfoImpl.cs" />
-                <include name="Reader\Field.cs" />
-                <include name="Reader\GenericTypeParameter.cs" />
-                <include name="Reader\MetadataReader.cs" />
-                <include name="Reader\Method.cs" />
-                <include name="Reader\ModuleReader.cs" />
-                <include name="Reader\PEReader.cs" />
-                <include name="Reader\PropertyInfoImpl.cs" />
-                <include name="Reader\ResourceModule.cs" />
-                <include name="Reader\TypeDefImpl.cs" />
-                <include name="Writer\ByteBuffer.cs" />
-                <include name="Writer\Heaps.cs" />
-                <include name="Writer\MetadataWriter.cs" />
-                <include name="Writer\ModuleWriter.cs" />
-                <include name="Writer\PEWriter.cs" />
-                <include name="Writer\ResourceSection.cs" />
-                <include name="Writer\TextSection.cs" />
-                <include name="Writer\VersionInfo.cs" />
-            </sources>
-            <references>
-                <include if="${framework::exists('mono-2.0')}" name="${MonoSymbolWriter}" />
-            </references>
-        </csc>
-    </target>
-</project>
index 4f9c0d5ed6286f8a75a01e4a8a68b1da8af4a957..cadc5870aba1327a80834a30483a6b80935986f5 100644 (file)
@@ -269,7 +269,7 @@ include ../build/rules.make
 
 SUBDIRS = $(common_dirs) $(net_2_0_dirs) $(net_2_0_only_dirs) $(net_3_5_only_dirs) $(moonlight_raw_dirs) $(mobile_dirs) $(net_4_0_dirs) $(net_4_0_only_dirs) $(net_4_5_dirs)
 
-DIST_ONLY_SUBDIRS = dlr IKVM.Reflection aot-compiler
+DIST_ONLY_SUBDIRS = dlr aot-compiler
 
 # No new makefiles for: System.Messaging, System.Web.Mobile,
 # System.ServiceProcess
index e45aeb008f90fbd847861b39c29c82458cf97233..bc52a7bcdeb6fb23474dee7348813afd7d85f5ed 100644 (file)
@@ -22,7 +22,7 @@ the_libdir = $(topdir)/class/lib/build/
 LOCAL_MCS_FLAGS += -lib:$(topdir)/class/lib/build -debug
 endif
 
-LOCAL_MCS_FLAGS += -d:STATIC,NO_SYMBOL_WRITER
+LOCAL_MCS_FLAGS += -d:STATIC,NO_SYMBOL_WRITER,NO_AUTHENTICODE
 
 PROGRAM_INSTALL_DIR = $(mono_libdir)/mono/4.5
 
index fc0167fcf929d6eb17f39c523cfd1571c4ae35de..900e678997004a0467f40af1c40f176220493a84 100644 (file)
@@ -574,7 +574,7 @@ namespace Mono.CSharp
 
                public override void SetFlags (uint flags, Location loc)
                {
-                       builder.__SetAssemblyFlags ((AssemblyNameFlags) flags);
+                       builder.__AssemblyFlags = (AssemblyNameFlags) flags;
                }
 
                public override void SetVersion (Version version, Location loc)
index 9f9d00e4a07703ceb4c5954332894c0ea035c8d0..74609d1947ee3bac08d5cf63e13e562eb34942d4 100644 (file)
@@ -18,7 +18,7 @@
     <DebugType>full</DebugType>\r
     <Optimize>False</Optimize>\r
     <OutputPath>.</OutputPath>\r
-    <DefineConstants>TRACE;DEBUG;NET_4_0;STATIC;NO_SYMBOL_WRITER</DefineConstants>\r
+    <DefineConstants>TRACE;DEBUG;NET_4_0;STATIC;NO_SYMBOL_WRITER;NO_AUTHENTICODE</DefineConstants>\r
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
     <UseVSHostingProcess>false</UseVSHostingProcess>\r
@@ -26,7 +26,7 @@
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
     <DebugType>pdbonly</DebugType>\r
     <Optimize>True</Optimize>\r
-    <DefineConstants>TRACE;NET_4_0;STATIC;NO_SYMBOL_WRITER</DefineConstants>\r
+    <DefineConstants>TRACE;NET_4_0;STATIC;NO_SYMBOL_WRITER;NO_AUTHENTICODE</DefineConstants>\r
     <ErrorReport>prompt</ErrorReport>\r
     <ErrorReport>prompt</ErrorReport>\r
     <WarningLevel>4</WarningLevel>\r
@@ -35,7 +35,7 @@
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug - AST|AnyCPU'">\r
     <DebugSymbols>True</DebugSymbols>\r
     <OutputPath>.</OutputPath>\r
-    <DefineConstants>TRACE;DEBUG;NET_4_0;STATIC;NO_SYMBOL_WRITER;FULL_AST</DefineConstants>\r
+    <DefineConstants>TRACE;DEBUG;NET_4_0;STATIC;NO_SYMBOL_WRITER;NO_AUTHENTICODE;FULL_AST</DefineConstants>\r
     <DebugType>full</DebugType>\r
     <CodeAnalysisLogFile>mcs.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>\r
     <CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>\r
     <Compile Include="visit.cs" />\r
   </ItemGroup>\r
   <ItemGroup Label="IKVM.Reflection">\r
-    <Compile Include="..\class\IKVM.Reflection\*.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\*.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Emit\*.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Emit\*.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Metadata\*.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Metadata\*.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Reader\*.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Reader\*.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Writer\*.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Writer\*.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Impl\ITypeOwner.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Impl\ITypeOwner.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
-    <Compile Include="..\class\IKVM.Reflection\Impl\SymbolSupport.cs">\r
+    <Compile Include="..\..\external\ikvm\reflect\Impl\SymbolSupport.cs">\r
       <Visible>False</Visible>\r
     </Compile>\r
   </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
   -->\r
 </Project>
\ No newline at end of file
index 7acf63aeff243704e2a7bfbb4e14e23654d27010..9ac9cb1c1ad4ebef8b45365433abaeaa7ff092cb 100644 (file)
@@ -57,10 +57,10 @@ visit.cs
 ../build/common/Consts.cs
 ../tools/monop/outline.cs
 
-../class/IKVM.Reflection/*.cs
-../class/IKVM.Reflection/Emit/*.cs
-../class/IKVM.Reflection/Metadata/*.cs
-../class/IKVM.Reflection/Reader/*.cs
-../class/IKVM.Reflection/Writer/*.cs
-../class/IKVM.Reflection/Impl/ITypeOwner.cs
-../class/IKVM.Reflection/Impl/SymbolSupport.cs
+../../external/ikvm/reflect/*.cs
+../../external/ikvm/reflect/Emit/*.cs
+../../external/ikvm/reflect/Metadata/*.cs
+../../external/ikvm/reflect/Reader/*.cs
+../../external/ikvm/reflect/Writer/*.cs
+../../external/ikvm/reflect/Impl/ITypeOwner.cs
+../../external/ikvm/reflect/Impl/SymbolSupport.cs