static TypeGenerator() { var assemblyName = new AssemblyName { Name = "Siege.DynamicTypes" }; AppDomain thisDomain = Thread.GetDomain(); assemblyBuilder = thisDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave); module = assemblyBuilder.DefineDynamicModule(assemblyBuilder.GetName().Name, assemblyBuilder.GetName().Name + ".dll"); }
/// <summary> /// Verifies an assembly based on an <see cref="AssemblyBuilder" /> instance. /// </summary> /// <param name="assemblyBuilder">The <see cref="AssemblyBuilder" /> instance.</param> /// <exception cref="ArgumentNullException">Thrown if <c>assemblyBuilder</c> is <c>null</c>.</exception> /// <exception cref="FileNotFoundException">Thrown if the given file does not exist.</exception> /// <exception cref="VerificationException">Thrown if the assembly has verification errors.</exception> public static void Verify(AssemblyBuilder assemblyBuilder) { var assemblyName = assemblyBuilder.GetName().Name; assemblyName += assemblyBuilder.EntryPoint != null ? ".exe" : ".dll"; var localPath = new Uri(assemblyBuilder.GetName().CodeBase).LocalPath; var directoryName = Path.GetDirectoryName(localPath); if (directoryName != null) InternalVerify(Path.Combine(directoryName, assemblyName)); }
public EmitHelper() { string guid = Guid.NewGuid().ToString(); this.fileName = guid + ".dll"; AssemblyName assemblyName = new AssemblyName(guid); assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save); module = assemblyBuilder.DefineDynamicModule(assemblyBuilder.GetName().Name, fileName, false); }
/// <summary> /// Verifies an assembly based on an <see cref="AssemblyBuilder" /> instance. /// </summary> /// <param name="assemblyBuilder">The <see cref="AssemblyBuilder" /> instance.</param> /// <exception cref="ArgumentNullException">Thrown if <c>assemblyBuilder</c> is <c>null</c>.</exception> /// <exception cref="FileNotFoundException">Thrown if the given file does not exist.</exception> /// <exception cref="VerificationException">Thrown if the assembly has verification errors.</exception> public static void Verify(AssemblyBuilder assemblyBuilder) { //assemblyBuilder.CheckParameterForNull("assemblyBuilder"); string assemblyName = assemblyBuilder.GetName().Name; if(assemblyBuilder.EntryPoint != null) { assemblyName += ".exe"; } else { assemblyName += ".dll"; } AssemblyVerification.InternalVerify(Path.Combine( Path.GetDirectoryName(new Uri(assemblyBuilder.GetName().CodeBase).LocalPath), assemblyName)); }
private void Initialize() { var name = new AssemblyName(outputFilename); assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(name, AssemblyBuilderAccess.RunAndSave); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyBuilder.GetName().Name, outputPath, true); RootContext.InitializeForBuild(moduleBuilder); }
public AlgorithmCompiler(bool IsDecryptState) { this.IsDecryptState = IsDecryptState; lock (GlobalLock) { if(assemblyName == null) { assemblyName = new AssemblyName(); assemblyName.Name = "__AlgorithmCompiler__" + GlobalInitialized++; asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); modBuilder = asmBuilder.DefineDynamicModule(asmBuilder.GetName().Name); } } }
public DynamicAssemblyInfo(string name) { var assemblyName = new AssemblyName( name ); _assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly( assemblyName, AssemblyBuilderAccess.RunAndSave ); _moduleBuilder = _assemblyBuilder.DefineDynamicModule( _assemblyBuilder.GetName().Name, false ); }
public static void Verify(AssemblyBuilder assemblyBuilder) { if (assemblyBuilder == null) { throw new ArgumentNullException("assemblyBuilder"); } var assemblyName = assemblyBuilder.GetName().Name; if (assemblyBuilder.EntryPoint != null) { assemblyName += ".exe"; } else { assemblyName += ".dll"; } AssemblyVerification.Verify(Path.Combine(Directory.GetCurrentDirectory(), assemblyName)); }
/// <summary> /// Initialize static objects /// </summary> private static void InitializeAssembly() { //check to see if we've already instantiated //the static objects if (asmBuilder == null) { //create a new dynamic assembly AssemblyName assembly = new AssemblyName(); assembly.Name = "AnonymousTypeExentions"; //get the current application domain AppDomain domain = Thread.GetDomain(); //get a module builder object asmBuilder = domain.DefineDynamicAssembly(assembly, AssemblyBuilderAccess.Run); modBuilder = asmBuilder.DefineDynamicModule( asmBuilder.GetName().Name, false ); } }
public ModuleBuilder GenerateModuleBuilder(AssemblyBuilder assemblyBuilder) { return assemblyBuilder.DefineDynamicModule(assemblyBuilder.GetName().Name, false); }
private void InitializeCompiler() { lock (_barrier) { if (_asm == null) { try { #if TRACE _asm = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Vault.GetAssemblyName()), AssemblyBuilderAccess.RunAndSave); _mod = _asm.DefineDynamicModule(Vault.GetAssemblyName() + ".dll", true); // do not use DomainUnload here because it never gets fired for default domain AppDomain.CurrentDomain.ProcessExit += (o, e) => { try { if (_asm != null) { _asm.Save(_asm.GetName().Name + ".dll"); } } catch(Exception ex) { MTLog.Say("Asm dumper has faced an unexpected exception: " + ex); } }; #else _asm = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(Vault.GetClassName()), AssemblyBuilderAccess.Run); _mod = _asm.DefineDynamicModule(Vault.GetClassName() + ".dll", false); #endif _asm.SetCustomAttribute(new CustomAttributeBuilder( typeof(GuidAttribute).GetConstructors().Single(), Vault.Id.ToString().MkArray())); } catch (Exception ex) { MTLog.Say("Compiler initialization failed: " + ex); _isPermanentlyBroken = true; } } } GetCompiledAsync(); }
private static ModuleBuilder CreateModule(AssemblyBuilder builder) { var theName = builder.GetName(); return builder.DefineDynamicModule(theName.Name, theName.Name + ".dll"); }
private SerializationMethodGeneratorManager( bool isDebuggable, bool isCollectable, AssemblyBuilder assemblyBuilder ) { this._isDebuggable = isDebuggable; string assemblyName; if ( assemblyBuilder != null ) { assemblyName = #if !NETSTANDARD1_1 && !NETSTANDARD1_3 assemblyBuilder.GetName( false ).Name; #else assemblyBuilder.GetName().Name; #endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 this._assembly = assemblyBuilder; } else { assemblyName = typeof( SerializationMethodGeneratorManager ).Namespace + ".GeneratedSerealizers" + Interlocked.Increment( ref _assemblySequence ); var dedicatedAssemblyBuilder = #if !NETSTANDARD1_1 && !NETSTANDARD1_3 AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName( assemblyName ), isDebuggable ? AssemblyBuilderAccess.RunAndSave #if !NETFX_35 : ( isCollectable ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run ) #else : AssemblyBuilderAccess.Run #endif // !NETFX_35 #if DEBUG , SerializerDebugging.DumpDirectory #endif // DEBUG ); #else AssemblyBuilder.DefineDynamicAssembly( new AssemblyName( assemblyName ), isCollectable ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run ); #endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 SetUpAssemblyBuilderAttributes( dedicatedAssemblyBuilder, isDebuggable ); this._assembly = dedicatedAssemblyBuilder; } #if !NETSTANDARD1_1 && !NETSTANDARD1_3 if ( isDebuggable ) { this._module = this._assembly.DefineDynamicModule( assemblyName, assemblyName + ".dll", true ); } else { this._module = this._assembly.DefineDynamicModule( assemblyName, true ); } #else this._module = this._assembly.DefineDynamicModule( assemblyName ); #endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 }
private static void Save(AssemblyBuilder assembly, ProxyContext context) { if ((context.Access & AssemblyBuilderAccess.Save) == AssemblyBuilderAccess.Save) { assembly.Save(assembly.GetName().Name + ".dll"); if (context.Verify) { AssemblyVerification.Verify(assembly); } } }
private DefaultSerializationMethodGeneratorManager( bool isDebuggable, bool isCollectable, AssemblyBuilder assemblyBuilder ) { this._isDebuggable = isDebuggable; string assemblyName; if ( assemblyBuilder != null ) { assemblyName = assemblyBuilder.GetName( false ).Name; this._assembly = assemblyBuilder; } else { assemblyName = typeof( DefaultSerializationMethodGeneratorManager ).Namespace + ".GeneratedSerealizers" + Interlocked.Increment( ref _assemblySequence ); var dedicatedAssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName( assemblyName ), #if !SILVERLIGHT isDebuggable ? AssemblyBuilderAccess.RunAndSave #if !NETFX_35 : ( isCollectable ? AssemblyBuilderAccess.RunAndCollect : AssemblyBuilderAccess.Run ) #else : AssemblyBuilderAccess.Run #endif #else AssemblyBuilderAccess.Run #endif ); SetUpAssemblyBuilderAttributes( dedicatedAssemblyBuilder, isDebuggable ); this._assembly = dedicatedAssemblyBuilder; } #if SILVERLIGHT this._module = this._assembly.DefineDynamicModule( assemblyName, true ); #else if ( isDebuggable ) { this._module = this._assembly.DefineDynamicModule( assemblyName, assemblyName + ".dll", true ); } else { this._module = this._assembly.DefineDynamicModule( assemblyName, true ); } #endif // else SILVERLIGHT }
private static ModuleBuilder BuildModule(DynamicTypeInfo info, AssemblyBuilder asmBuilder) { // Build the module ModuleBuilder modBuilder; #if !SILVERLIGHT if (info.DynamicTypeShouldSave) { modBuilder = asmBuilder.DefineDynamicModule("DynamicAnonTypeModule_" + info.TypeName, asmBuilder.GetName().Name + ".dll"); } else { modBuilder = asmBuilder.DefineDynamicModule("DynamicAnonTypeModule_" + info.TypeName); } #else modBuilder = asmBuilder.DefineDynamicModule("DynamicAnonTypeModule_" + info.TypeName); #endif return modBuilder; }
private static void GenerateAssemblyAndModule() { if (asmBuilder == null) { AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "XmlTypes"; AppDomain thisDomain = Thread.GetDomain(); asmBuilder = thisDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); modBuilder = asmBuilder.DefineDynamicModule(asmBuilder.GetName().Name, false); iRecordListType = TypeLoader.GetType("EmergeTk.Model.IRecordList`1"); } }