summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs')
-rw-r--r--src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs155
1 files changed, 66 insertions, 89 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs
index 5575e28917..6d9cb0db2f 100644
--- a/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs
+++ b/src/mscorlib/src/System/Reflection/Emit/AssemblyBuilder.cs
@@ -48,11 +48,11 @@ namespace System.Reflection.Emit
None = 0x00000000,
// Security attributes which affect the module security descriptor
- AllCritical = 0x00000001,
- Aptca = 0x00000002,
- Critical = 0x00000004,
- Transparent = 0x00000008,
- TreatAsSafe = 0x00000010,
+ AllCritical = 0x00000001,
+ Aptca = 0x00000002,
+ Critical = 0x00000004,
+ Transparent = 0x00000008,
+ TreatAsSafe = 0x00000010,
}
// When the user calls AppDomain.DefineDynamicAssembly the loader creates a new InternalAssemblyBuilder.
@@ -61,7 +61,7 @@ namespace System.Reflection.Emit
// Assembly to an AssemblyBuilder and emit code with the elevated permissions of the trusted code which
// origionally created the AssemblyBuilder via DefineDynamicAssembly. Today, this can no longer happen
// because the Assembly returned via AssemblyGetAssemblies() will be an InternalAssemblyBuilder.
-
+
// Only the caller of DefineDynamicAssembly will get an AssemblyBuilder.
// There is a 1-1 relationship between InternalAssemblyBuilder and AssemblyBuilder.
// AssemblyBuilder is composed of its InternalAssemblyBuilder.
@@ -94,39 +94,39 @@ namespace System.Reflection.Emit
#region Methods inherited from Assembly
public override String[] GetManifestResourceNames()
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override FileStream GetFile(String name)
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override FileStream[] GetFiles(bool getResourceModules)
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override Stream GetManifestResourceStream(Type type, String name)
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override Stream GetManifestResourceStream(String name)
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override ManifestResourceInfo GetManifestResourceInfo(String resourceName)
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override String Location
{
get
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
}
@@ -134,13 +134,13 @@ namespace System.Reflection.Emit
{
get
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
}
public override Type[] GetExportedTypes()
{
- throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicAssembly"));
+ throw new NotSupportedException(SR.NotSupported_DynamicAssembly);
}
public override String ImageRuntimeVersion
@@ -177,16 +177,12 @@ namespace System.Reflection.Emit
private bool m_fManifestModuleUsedAsDefinedModule;
internal const string MANIFEST_MODULE_NAME = "RefEmit_InMemoryManifestModule";
-#if FEATURE_APPX
- private bool m_profileAPICheck;
-#endif
-
internal ModuleBuilder GetModuleBuilder(InternalModuleBuilder module)
{
Contract.Requires(module != null);
Debug.Assert(this.InternalAssembly == module.Assembly);
- lock(SyncRoot)
+ lock (SyncRoot)
{
// in CoreCLR there is only one module in each dynamic assembly, the manifest module
if (m_manifestModuleBuilder.InternalModule == module)
@@ -216,16 +212,6 @@ namespace System.Reflection.Emit
{
return InternalAssembly.GetNativeHandle();
}
-
-#if FEATURE_APPX
- internal bool ProfileAPICheck
- {
- get
- {
- return m_profileAPICheck;
- }
- }
-#endif
#endregion
#region Constructor
@@ -242,13 +228,10 @@ namespace System.Reflection.Emit
throw new ArgumentNullException(nameof(name));
if (access != AssemblyBuilderAccess.Run
-#if FEATURE_REFLECTION_ONLY_LOAD
- && access != AssemblyBuilderAccess.ReflectionOnly
-#endif // FEATURE_REFLECTION_ONLY_LOAD
&& access != AssemblyBuilderAccess.RunAndCollect
)
{
- throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), nameof(access));
+ throw new ArgumentException(SR.Format(SR.Arg_EnumIllegalVal, (int)access), nameof(access));
}
if (securityContextSource < SecurityContextSource.CurrentAppDomain ||
@@ -304,14 +287,7 @@ namespace System.Reflection.Emit
name.Name,
access,
dir);
-#if FEATURE_APPX
- if (AppDomain.ProfileAPICheck)
- {
- RuntimeAssembly creator = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
- if (creator != null && !creator.IsFrameworkAssembly())
- m_profileAPICheck = true;
- }
-#endif
+
// Make sure that ManifestModule is properly initialized
// We need to do this before setting any CustomAttribute
InitManifestModule();
@@ -331,7 +307,7 @@ namespace System.Reflection.Emit
// because it hasn't been initialized.
// However, it can be used to set the custom attribute on the Assembly
m_manifestModuleBuilder = new ModuleBuilder(this, modBuilder);
-
+
// We are only setting the name in the managed ModuleBuilderData here.
// The name in the underlying metadata will be set when the
// manifest module is created during nCreateDynamicAssembly.
@@ -351,7 +327,7 @@ namespace System.Reflection.Emit
* to have a strong name and a hash will be computed when the assembly
* is saved.
**********************************************/
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public static AssemblyBuilder DefineDynamicAssembly(
AssemblyName name,
AssemblyBuilderAccess access)
@@ -363,7 +339,7 @@ namespace System.Reflection.Emit
null, ref stackMark, null, SecurityContextSource.CurrentAssembly);
}
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public static AssemblyBuilder DefineDynamicAssembly(
AssemblyName name,
AssemblyBuilderAccess access,
@@ -425,9 +401,9 @@ namespace System.Reflection.Emit
* a transient module.
*
**********************************************/
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public ModuleBuilder DefineDynamicModule(
- String name)
+ String name)
{
Contract.Ensures(Contract.Result<ModuleBuilder>() != null);
@@ -435,39 +411,39 @@ namespace System.Reflection.Emit
return DefineDynamicModuleInternal(name, false, ref stackMark);
}
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public ModuleBuilder DefineDynamicModule(
- String name,
- bool emitSymbolInfo) // specify if emit symbol info or not
+ String name,
+ bool emitSymbolInfo) // specify if emit symbol info or not
{
Contract.Ensures(Contract.Result<ModuleBuilder>() != null);
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- return DefineDynamicModuleInternal( name, emitSymbolInfo, ref stackMark );
+ return DefineDynamicModuleInternal(name, emitSymbolInfo, ref stackMark);
}
private ModuleBuilder DefineDynamicModuleInternal(
- String name,
- bool emitSymbolInfo, // specify if emit symbol info or not
+ String name,
+ bool emitSymbolInfo, // specify if emit symbol info or not
ref StackCrawlMark stackMark)
{
- lock(SyncRoot)
+ lock (SyncRoot)
{
return DefineDynamicModuleInternalNoLock(name, emitSymbolInfo, ref stackMark);
}
}
private ModuleBuilder DefineDynamicModuleInternalNoLock(
- String name,
- bool emitSymbolInfo, // specify if emit symbol info or not
+ String name,
+ bool emitSymbolInfo, // specify if emit symbol info or not
ref StackCrawlMark stackMark)
{
if (name == null)
throw new ArgumentNullException(nameof(name));
if (name.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name));
+ throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
if (name[0] == '\0')
- throw new ArgumentException(Environment.GetResourceString("Argument_InvalidName"), nameof(name));
+ throw new ArgumentException(SR.Argument_InvalidName, nameof(name));
Contract.Ensures(Contract.Result<ModuleBuilder>() != null);
Contract.EndContractBlock();
@@ -481,7 +457,7 @@ namespace System.Reflection.Emit
// create the dynamic module- only one ModuleBuilder per AssemblyBuilder can be created
if (m_fManifestModuleUsedAsDefinedModule == true)
- throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoMultiModuleAssembly"));
+ throw new InvalidOperationException(SR.InvalidOperation_NoMultiModuleAssembly);
// Init(...) has already been called on m_manifestModuleBuilder in InitManifestModule()
dynModule = m_manifestModuleBuilder;
@@ -492,7 +468,7 @@ namespace System.Reflection.Emit
writer = SymWrapperCore.SymWriter.CreateSymWriter();
String fileName = "Unused"; // this symfile is never written to disk so filename does not matter.
-
+
// Pass the "real" module to the VM
pInternalSymWriter = ModuleBuilder.nCreateISymWriterForDynamicModule(dynModule.InternalModule, fileName);
@@ -512,14 +488,14 @@ namespace System.Reflection.Emit
return dynModule;
} // DefineDynamicModuleInternalNoLock
-#endregion
+ #endregion
internal void CheckContext(params Type[][] typess)
{
if (typess == null)
return;
-
- foreach(Type[] types in typess)
+
+ foreach (Type[] types in typess)
if (types != null)
CheckContext(types);
}
@@ -528,23 +504,23 @@ namespace System.Reflection.Emit
{
if (types == null)
return;
-
+
foreach (Type type in types)
{
if (type == null)
continue;
if (type.Module == null || type.Module.Assembly == null)
- throw new ArgumentException(Environment.GetResourceString("Argument_TypeNotValid"));
+ throw new ArgumentException(SR.Argument_TypeNotValid);
if (type.Module.Assembly == typeof(object).Module.Assembly)
continue;
if (type.Module.Assembly.ReflectionOnly && !ReflectionOnly)
- throw new InvalidOperationException(Environment.GetResourceString("Arugment_EmitMixedContext1", type.AssemblyQualifiedName));
+ throw new InvalidOperationException(SR.Format(SR.Arugment_EmitMixedContext1, type.AssemblyQualifiedName));
if (!type.Module.Assembly.ReflectionOnly && ReflectionOnly)
- throw new InvalidOperationException(Environment.GetResourceString("Arugment_EmitMixedContext2", type.AssemblyQualifiedName));
+ throw new InvalidOperationException(SR.Format(SR.Arugment_EmitMixedContext2, type.AssemblyQualifiedName));
}
}
@@ -585,27 +561,27 @@ namespace System.Reflection.Emit
{
return InternalAssembly.GetManifestResourceNames();
}
-
+
public override FileStream GetFile(String name)
{
return InternalAssembly.GetFile(name);
}
-
+
public override FileStream[] GetFiles(bool getResourceModules)
{
return InternalAssembly.GetFiles(getResourceModules);
}
-
+
public override Stream GetManifestResourceStream(Type type, String name)
{
return InternalAssembly.GetManifestResourceStream(type, name);
}
-
+
public override Stream GetManifestResourceStream(String name)
{
return InternalAssembly.GetManifestResourceStream(name);
}
-
+
public override ManifestResourceInfo GetManifestResourceInfo(String resourceName)
{
return InternalAssembly.GetManifestResourceInfo(resourceName);
@@ -626,7 +602,7 @@ namespace System.Reflection.Emit
return InternalAssembly.ImageRuntimeVersion;
}
}
-
+
public override String CodeBase
{
get
@@ -637,9 +613,9 @@ namespace System.Reflection.Emit
// Override the EntryPoint method on Assembly.
// This doesn't need to be synchronized because it is simple enough
- public override MethodInfo EntryPoint
+ public override MethodInfo EntryPoint
{
- get
+ get
{
return m_assemblyData.m_entryPointMethod;
}
@@ -721,7 +697,7 @@ namespace System.Reflection.Emit
return InternalAssembly.GetLoadedModules(getResourceModules);
}
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public override Assembly GetSatelliteAssembly(CultureInfo culture)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
@@ -729,7 +705,7 @@ namespace System.Reflection.Emit
}
// Useful for binding to a very specific version of a satellite assembly
- [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
+ [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
public override Assembly GetSatelliteAssembly(CultureInfo culture, Version version)
{
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
@@ -738,7 +714,8 @@ namespace System.Reflection.Emit
public override bool IsDynamic
{
- get {
+ get
+ {
return true;
}
}
@@ -751,28 +728,28 @@ namespace System.Reflection.Emit
*
**********************************************/
public ModuleBuilder GetDynamicModule(
- String name) // the name of module for the look up
+ String name) // the name of module for the look up
{
- lock(SyncRoot)
+ lock (SyncRoot)
{
return GetDynamicModuleNoLock(name);
}
}
private ModuleBuilder GetDynamicModuleNoLock(
- String name) // the name of module for the look up
+ String name) // the name of module for the look up
{
if (name == null)
throw new ArgumentNullException(nameof(name));
if (name.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(name));
+ throw new ArgumentException(SR.Argument_EmptyName, nameof(name));
Contract.EndContractBlock();
BCLDebug.Log("DYNIL", "## DYNIL LOGGING: AssemblyBuilder.GetDynamicModule( " + name + " )");
int size = m_assemblyData.m_moduleBuilderList.Count;
for (int i = 0; i < size; i++)
{
- ModuleBuilder moduleBuilder = (ModuleBuilder) m_assemblyData.m_moduleBuilderList[i];
+ ModuleBuilder moduleBuilder = (ModuleBuilder)m_assemblyData.m_moduleBuilderList[i];
if (moduleBuilder.m_moduleData.m_strModuleName.Equals(name))
{
return moduleBuilder;
@@ -792,8 +769,8 @@ namespace System.Reflection.Emit
if (binaryAttribute == null)
throw new ArgumentNullException(nameof(binaryAttribute));
Contract.EndContractBlock();
-
- lock(SyncRoot)
+
+ lock (SyncRoot)
{
SetCustomAttributeNoLock(con, binaryAttribute);
}
@@ -828,7 +805,7 @@ namespace System.Reflection.Emit
}
Contract.EndContractBlock();
- lock(SyncRoot)
+ lock (SyncRoot)
{
SetCustomAttributeNoLock(customBuilder);
}
@@ -837,7 +814,7 @@ namespace System.Reflection.Emit
private void SetCustomAttributeNoLock(CustomAttributeBuilder customBuilder)
{
customBuilder.CreateCustomAttribute(
- m_manifestModuleBuilder,
+ m_manifestModuleBuilder,
AssemblyBuilderData.m_tkAssembly); // This is the AssemblyDef token
// Track the CA for persistence
@@ -852,11 +829,11 @@ namespace System.Reflection.Emit
* Private methods
*
**********************************************/
-
+
/**********************************************
* Make a private constructor so these cannot be constructed externally.
* @internonly
**********************************************/
- private AssemblyBuilder() {}
+ private AssemblyBuilder() { }
}
}