We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- namespace System.Reflection.Emit
- {
- using System;
- using IList = System.Collections.IList;
- using ArrayList = System.Collections.ArrayList;
- using System.Reflection;
- using System.Security;
- using System.Diagnostics;
- using CultureInfo = System.Globalization.CultureInfo;
- using ResourceWriter = System.Resources.ResourceWriter;
- using System.IO;
- using System.Runtime.Versioning;
-
-
-
-
- internal class AssemblyBuilderData
- {
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
- internal AssemblyBuilderData(Assembly assembly, string strAssemblyName, AssemblyBuilderAccess access, string dir)
- {
- m_assembly = assembly;
- m_strAssemblyName = strAssemblyName;
- m_access = access;
- m_moduleBuilderList = new ArrayList();
- m_resWriterList = new ArrayList();
- m_publicComTypeList = null;
- m_CABuilders = null;
- m_CABytes = null;
- m_CACons = null;
- m_iPublicComTypeCount = 0;
- m_iCABuilder = 0;
- m_iCAs = 0;
- m_entryPointModule = null;
- m_isSaved = false;
- if (dir == null && access != AssemblyBuilderAccess.Run)
- m_strDir = Environment.CurrentDirectory;
- else
- m_strDir = dir;
- m_RequiredPset = null;
- m_OptionalPset = null;
- m_RefusedPset = null;
- m_isSynchronized = false;
-
- m_InMemoryAssemblyModule = null;
- m_OnDiskAssemblyModule = null;
- m_peFileKind = PEFileKinds.Dll;
-
- m_entryPointMethod = null;
- m_ISymWrapperAssembly = null;
- }
-
-
- internal void AddModule(ModuleBuilder dynModule)
- {
- m_moduleBuilderList.Add(dynModule);
-
- if (m_assembly != null)
-
- m_assembly.nAddFileToInMemoryFileList(dynModule.m_moduleData.m_strFileName, dynModule);
- }
-
-
- internal void AddResWriter(ResWriterData resData)
- {
- m_resWriterList.Add(resData);
- }
-
-
-
- internal void AddCustomAttribute(CustomAttributeBuilder customBuilder)
- {
-
-
- if (m_CABuilders == null) {
- m_CABuilders = new CustomAttributeBuilder[m_iInitialSize];
- }
- if (m_iCABuilder == m_CABuilders.Length) {
- CustomAttributeBuilder[] tempCABuilders = new CustomAttributeBuilder[m_iCABuilder * 2];
- Array.Copy(m_CABuilders, tempCABuilders, m_iCABuilder);
- m_CABuilders = tempCABuilders;
- }
- m_CABuilders[m_iCABuilder] = customBuilder;
-
- m_iCABuilder++;
- }
-
-
- internal void AddCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
- {
-
-
- if (m_CABytes == null) {
- m_CABytes = new byte[m_iInitialSize][];
- m_CACons = new ConstructorInfo[m_iInitialSize];
- }
- if (m_iCAs == m_CABytes.Length) {
-
- byte[][] temp = new byte[m_iCAs * 2][];
- ConstructorInfo[] tempCon = new ConstructorInfo[m_iCAs * 2];
- for (int i = 0; i < m_iCAs; i++) {
- temp[i] = m_CABytes[i];
- tempCon[i] = m_CACons[i];
- }
- m_CABytes = temp;
- m_CACons = tempCon;
- }
-
- byte[] attrs = new byte[binaryAttribute.Length];
- Array.Copy(binaryAttribute, attrs, binaryAttribute.Length);
- m_CABytes[m_iCAs] = attrs;
- m_CACons[m_iCAs] = con;
- m_iCAs++;
- }
-
-
-
- internal void CheckResNameConflict(string strNewResName)
- {
- int size = m_resWriterList.Count;
- int i;
- for (i = 0; i < size; i++) {
- ResWriterData resWriter = (ResWriterData)m_resWriterList[i];
- if (resWriter.m_strName.Equals(strNewResName)) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateResourceName"));
- }
- }
- }
-
-
-
- [ResourceExposure(ResourceScope.None)]
- [ResourceConsumption(ResourceScope.Assembly, ResourceScope.Assembly)]
- internal void CheckNameConflict(string strNewModuleName)
- {
- int size = m_moduleBuilderList.Count;
- int i;
- for (i = 0; i < size; i++) {
- ModuleBuilder moduleBuilder = (ModuleBuilder)m_moduleBuilderList[i];
- if (moduleBuilder.m_moduleData.m_strModuleName.Equals(strNewModuleName)) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateModuleName"));
- }
- }
-
-
-
- if (!(m_assembly is AssemblyBuilder)) {
- if (m_assembly.GetModule(strNewModuleName) != null) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateModuleName"));
- }
- }
- }
-
-
- internal void CheckTypeNameConflict(string strTypeName, TypeBuilder enclosingType)
- {
- BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilderData.CheckTypeNameConflict( " + strTypeName + " )");
- for (int i = 0; i < m_moduleBuilderList.Count; i++) {
- ModuleBuilder curModule = (ModuleBuilder)m_moduleBuilderList[i];
- for (int j = 0; j < curModule.m_TypeBuilderList.Count; j++) {
- Type curType = (Type)curModule.m_TypeBuilderList[j];
- if (curType.FullName.Equals(strTypeName) && curType.DeclaringType == enclosingType) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateTypeName"));
- }
- }
- }
-
-
-
-
- if ((enclosingType == null) && !(m_assembly is AssemblyBuilder)) {
- if (m_assembly.GetType(strTypeName, false, false) != null) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicateTypeName"));
- }
- }
- }
-
-
-
-
-
-
-
- internal void CheckFileNameConflict(string strFileName)
- {
- int size = m_moduleBuilderList.Count;
- int i;
- for (i = 0; i < size; i++) {
- ModuleBuilder moduleBuilder = (ModuleBuilder)m_moduleBuilderList[i];
- if (moduleBuilder.m_moduleData.m_strFileName != null) {
- if (String.Compare(moduleBuilder.m_moduleData.m_strFileName, strFileName, StringComparison.OrdinalIgnoreCase) == 0) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicatedFileName"));
- }
- }
- }
- size = m_resWriterList.Count;
- for (i = 0; i < size; i++) {
- ResWriterData resWriter = (ResWriterData)m_resWriterList[i];
- if (resWriter.m_strFileName != null) {
- if (String.Compare(resWriter.m_strFileName, strFileName, StringComparison.OrdinalIgnoreCase) == 0) {
-
- throw new ArgumentException(Environment.GetResourceString("Argument_DuplicatedFileName"));
- }
- }
- }
-
- }
-
-
-
-
-
- internal ModuleBuilder FindModuleWithFileName(string strFileName)
- {
- int size = m_moduleBuilderList.Count;
- int i;
- for (i = 0; i < size; i++) {
- ModuleBuilder moduleBuilder = (ModuleBuilder)m_moduleBuilderList[i];
- if (moduleBuilder.m_moduleData.m_strFileName != null) {
- if (String.Compare(moduleBuilder.m_moduleData.m_strFileName, strFileName, StringComparison.OrdinalIgnoreCase) == 0) {
- return moduleBuilder;
- }
- }
- }
- return null;
- }
-
-
-
-
-
- internal ModuleBuilder FindModuleWithName(string strName)
- {
- int size = m_moduleBuilderList.Count;
- int i;
- for (i = 0; i < size; i++) {
- ModuleBuilder moduleBuilder = (ModuleBuilder)m_moduleBuilderList[i];
- if (moduleBuilder.m_moduleData.m_strModuleName != null) {
- if (String.Compare(moduleBuilder.m_moduleData.m_strModuleName, strName, StringComparison.OrdinalIgnoreCase) == 0)
- return moduleBuilder;
- }
- }
- return null;
- }
-
-
-
- internal void AddPublicComType(Type type)
- {
- BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilderData.AddPublicComType( " + type.FullName + " )");
- if (m_isSaved == true) {
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotAlterAssembly"));
- }
- EnsurePublicComTypeCapacity();
- m_publicComTypeList[m_iPublicComTypeCount] = type;
- m_iPublicComTypeCount++;
- }
-
-
- internal void AddPermissionRequests(PermissionSet required, PermissionSet optional, PermissionSet refused)
- {
- BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilderData.AddPermissionRequests");
- if (m_isSaved == true) {
-
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_CannotAlterAssembly"));
- }
- m_RequiredPset = required;
- m_OptionalPset = optional;
- m_RefusedPset = refused;
- }
-
- internal void EnsurePublicComTypeCapacity()
- {
- if (m_publicComTypeList == null) {
- m_publicComTypeList = new Type[m_iInitialSize];
- }
- if (m_iPublicComTypeCount == m_publicComTypeList.Length) {
- Type[] tempTypeList = new Type[m_iPublicComTypeCount * 2];
- Array.Copy(m_publicComTypeList, tempTypeList, m_iPublicComTypeCount);
- m_publicComTypeList = tempTypeList;
- }
- }
-
- internal ModuleBuilder GetInMemoryAssemblyModule()
- {
- if (m_InMemoryAssemblyModule == null) {
- ModuleBuilder modBuilder = m_assembly.nGetInMemoryAssemblyModule();
- modBuilder.Init("RefEmit_InMemoryManifestModule", null, null);
- m_InMemoryAssemblyModule = modBuilder;
- }
- return m_InMemoryAssemblyModule;
- }
-
- internal ModuleBuilder GetOnDiskAssemblyModule()
- {
- if (m_OnDiskAssemblyModule == null) {
- ModuleBuilder modBuilder = m_assembly.nGetOnDiskAssemblyModule();
- modBuilder.Init("RefEmit_OnDiskManifestModule", null, null);
- m_OnDiskAssemblyModule = modBuilder;
- }
- return m_OnDiskAssemblyModule;
- }
-
- internal void SetOnDiskAssemblyModule(ModuleBuilder modBuilder)
- {
- m_OnDiskAssemblyModule = modBuilder;
- }
-
- internal ArrayList m_moduleBuilderList;
- internal ArrayList m_resWriterList;
- internal string m_strAssemblyName;
- internal AssemblyBuilderAccess m_access;
- internal Assembly m_assembly;
-
- internal Type[] m_publicComTypeList;
- internal int m_iPublicComTypeCount;
-
- internal ModuleBuilder m_entryPointModule;
- internal bool m_isSaved;
- internal const int m_iInitialSize = 16;
- internal string m_strDir;
-
-
- internal const int m_tkAssembly = 536870913;
-
-
- internal PermissionSet m_RequiredPset;
- internal PermissionSet m_OptionalPset;
- internal PermissionSet m_RefusedPset;
-
-
- internal bool m_isSynchronized;
-
-
- internal CustomAttributeBuilder[] m_CABuilders;
- internal int m_iCABuilder;
- internal byte[][] m_CABytes;
- internal ConstructorInfo[] m_CACons;
- internal int m_iCAs;
- internal PEFileKinds m_peFileKind;
-
- private ModuleBuilder m_InMemoryAssemblyModule;
- private ModuleBuilder m_OnDiskAssemblyModule;
- internal MethodInfo m_entryPointMethod;
- internal Assembly m_ISymWrapperAssembly;
-
-
- }
-
-
-
- internal class ResWriterData
- {
- internal ResWriterData(ResourceWriter resWriter, Stream memoryStream, string strName, string strFileName, string strFullFileName, ResourceAttributes attribute)
- {
- m_resWriter = resWriter;
- m_memoryStream = memoryStream;
- m_strName = strName;
- m_strFileName = strFileName;
- m_strFullFileName = strFullFileName;
- m_nextResWriter = null;
- m_attribute = attribute;
- }
-
- internal ResourceWriter m_resWriter;
- internal string m_strName;
- internal string m_strFileName;
- internal string m_strFullFileName;
- internal Stream m_memoryStream;
- internal ResWriterData m_nextResWriter;
- internal ResourceAttributes m_attribute;
- }
-
-
- }