Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / mscorlib / system / reflection / emit / modulebuilderdata.cs
blob0252f9dbace04858fac36ae5eb8586d50c7a4f8a
1 // ==++==
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // ==--==
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
8 // <OWNER>Microsoft</OWNER>
9 //
11 namespace System.Reflection.Emit
13 using System;
14 using System.Diagnostics.Contracts;
15 using System.Globalization;
16 using System.IO;
17 using System.Reflection;
18 using System.Runtime.Versioning;
20 // This is a package private class. This class hold all of the managed
21 // data member for ModuleBuilder. Note that what ever data members added to
22 // this class cannot be accessed from the EE.
23 [Serializable]
24 internal class ModuleBuilderData
26 [System.Security.SecurityCritical] // auto-generated
27 [ResourceExposure(ResourceScope.Machine)]
28 [ResourceConsumption(ResourceScope.Machine)]
29 internal ModuleBuilderData(ModuleBuilder module, String strModuleName, String strFileName, int tkFile)
31 m_globalTypeBuilder = new TypeBuilder(module);
32 m_module = module;
33 m_tkFile = tkFile;
35 InitNames(strModuleName, strFileName);
38 // Initialize module and file names.
39 [System.Security.SecurityCritical] // auto-generated
40 [ResourceExposure(ResourceScope.Machine)]
41 [ResourceConsumption(ResourceScope.Machine)]
42 private void InitNames(String strModuleName, String strFileName)
44 m_strModuleName = strModuleName;
45 if (strFileName == null)
47 // fake a transient module file name
48 m_strFileName = strModuleName;
50 else
52 String strExtension = Path.GetExtension(strFileName);
53 if (strExtension == null || strExtension == String.Empty)
55 // This is required by our loader. It cannot load module file that does not have file extension.
56 throw new ArgumentException(Environment.GetResourceString("Argument_NoModuleFileExtension", strFileName));
58 m_strFileName = strFileName;
62 // This is a method for changing module and file name of the manifest module (created by default for
63 // each assembly).
64 [System.Security.SecurityCritical] // auto-generated
65 [ResourceExposure(ResourceScope.Machine)]
66 [ResourceConsumption(ResourceScope.Machine)]
67 internal virtual void ModifyModuleName(String strModuleName)
69 Contract.Assert(m_strModuleName == AssemblyBuilder.MANIFEST_MODULE_NAME, "Changing names for non-manifest module");
70 InitNames(strModuleName, null /*strFileName*/);
73 internal int FileToken
75 get
77 // Before save, the scope of m_tkFile is the in-memory assembly manifest
78 // During save, the scope of m_tkFile is the on-disk assembly manifest
79 // For transient modules m_tkFile never change.
81 // Theoretically no one should emit anything after a dynamic assembly has
82 // been saved. So m_tkFile shouldn't used when m_isSaved is true.
83 // But that was never completely enforced: you can still emit everything after
84 // the assembly has been saved (except for public types in persistent modules).
86 return m_tkFile;
89 set
91 m_tkFile = value;
95 internal String m_strModuleName; // scope name (can be different from file name)
96 internal String m_strFileName;
97 internal bool m_fGlobalBeenCreated;
98 internal bool m_fHasGlobal;
99 [NonSerialized]
100 internal TypeBuilder m_globalTypeBuilder;
101 [NonSerialized]
102 internal ModuleBuilder m_module;
104 private int m_tkFile;
105 internal bool m_isSaved;
106 [NonSerialized]
107 internal ResWriterData m_embeddedRes;
108 internal const String MULTI_BYTE_VALUE_CLASS = "$ArrayType$";
109 internal String m_strResourceFileName;
110 internal byte[] m_resourceBytes;
111 } // class ModuleBuilderData