modulebuilder.cs

来自「没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没的 没」· CS 代码 · 共 715 行 · 第 1/2 页

CS
715
字号
/* * ModuleBuilder.cs - Implementation of the *		"System.Reflection.Emit.ModuleBuilder" class. * * Copyright (C) 2002  Southern Storm Software, Pty Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */namespace System.Reflection.Emit{#if CONFIG_REFLECTION_EMITusing System;using System.Security;using System.Resources;using System.Reflection;using System.Security.Policy;using System.Diagnostics.SymbolStore;using System.Runtime.InteropServices;using System.Runtime.CompilerServices;public class ModuleBuilder : Module, IDetachItem{	// Internal state.	internal AssemblyBuilder assembly;	private String name;	private bool transient;	private bool emitSymbolInfo;	private TypeBuilder moduleType;	// Constructor.	internal ModuleBuilder(AssemblyBuilder assembly, String name,						   bool transient, bool emitSymbolInfo)			{				// Initialize the fields within this object.				this.assembly = assembly;				this.name = name;				this.transient = transient;				this.emitSymbolInfo = emitSymbolInfo;				// Register this object for detaching.				assembly.AddDetach(this);				// Create a new module within the assembly.				lock(typeof(AssemblyBuilder))				{					privateData = ClrModuleCreate(assembly.privateData, name);				}				// Create the module type for this module.				moduleType = new TypeBuilder(this, "<Module>",											 null, TypeAttributes.NotPublic,											 null, null,											 PackingSize.Unspecified, 0, null);				moduleType.needsDefaultConstructor = false;			}	// Workaround the fact that the Assembly property is non-virtual. 	internal override System.Reflection.Assembly GetAssemblyCore()			{				return assembly;			}	// Get the fully qualified name of this module.	public override String FullyQualifiedName			{				get				{					return name;				}			}	// Start a synchronized operation on this module.	internal void StartSync()			{				assembly.StartSync();			}	// End a synchronized operation on this module.	internal void EndSync()			{				assembly.EndSync();			}	// Create the global functions in this module.	public void CreateGlobalFunctions()			{				moduleType.CreateType();			}	// TODO - debug symbol support	// Define a document for source.	[TODO]	public ISymbolDocumentWriter DefineDocument				(String url, Guid language,				 Guid languageVendor, Guid documentType)			{				// TODO				return null;			}	// Define an enumerated type within this module.	public EnumBuilder DefineEnum(String name, TypeAttributes visibility,								  Type underlyingType)			{				try				{					StartSync();					int index = name.LastIndexOf('.');					String nspace;					if(index != -1)					{						nspace = name.Substring(0, index);						name = name.Substring(index + 1);					}					else					{						nspace = null;					}					return new EnumBuilder(this, name, nspace,										   visibility, underlyingType);				}				finally				{					EndSync();				}			}	// Define a global method within this module.	public MethodBuilder DefineGlobalMethod				(String name, MethodAttributes attributes,				 CallingConventions callingConvention,				 Type returnType, Type[] parameterTypes)			{				try				{					StartSync();					if((attributes & MethodAttributes.Static) == 0)					{						throw new ArgumentException(_("Emit_GlobalNonStatic"));					}					return moduleType.DefineMethod						(name, attributes, callingConvention,						 returnType, parameterTypes);				}				finally				{					EndSync();				}			}	public MethodBuilder DefineGlobalMethod				(String name, MethodAttributes attributes,				 Type returnType, Type[] parameterTypes)			{				return DefineGlobalMethod(name, attributes,										  CallingConventions.Standard,										  returnType, parameterTypes);			}	// Define initialized data as a global field.	public FieldBuilder DefineInitializedData				(String name, byte[] data, FieldAttributes attributes)			{				try				{					StartSync();					return moduleType.DefineInitializedData						(name, data, attributes);				}				finally				{					EndSync();				}			}	// Define a global PInvoke method.	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 MethodBuilder DefinePInvokeMethod				(String name, String dllName,				 MethodAttributes attributes,				 CallingConventions callingConvention,				 Type returnType, Type[] parameterTypes,				 CallingConvention nativeCallConv,				 CharSet nativeCharSet)			{				return moduleType.DefinePInvokeMethod					(name, dllName, name, attributes,				     callingConvention, returnType, parameterTypes,				 	 nativeCallConv, nativeCharSet);			}	// Define a resource within a module.	[TODO]	public IResourceWriter DefineResource				(String name, String description,				 ResourceAttributes attribute)			{				try				{					StartSync();					// TODO					return null;				}				finally				{					EndSync();				}			}	public IResourceWriter DefineResource(String name, String description)			{				return DefineResource(name, description,									  ResourceAttributes.Public);			}	// Define a type witin this module.	private TypeBuilder DefineType(String name, TypeAttributes attr,								   Type parent, Type[] interfaces,								   PackingSize packSize, int typeSize)			{				try				{					StartSync();					int index = name.LastIndexOf('.');					String nspace;					if(index != -1)					{						nspace = name.Substring(0, index);						name = name.Substring(index + 1);					}					else					{						nspace = null;					}					return new TypeBuilder(this, name, nspace, attr,										   parent, interfaces, packSize,										   typeSize, null);				}				finally				{					EndSync();				}			}	public TypeBuilder DefineType(String name)			{				return DefineType(name, TypeAttributes.NotPublic,								  typeof(System.Object), null, 								  PackingSize.Unspecified, 0);			}	public TypeBuilder DefineType(String name, TypeAttributes attr)			{				return DefineType(name, attr, 									(attr & TypeAttributes.Interface)==0 ?										typeof(System.Object) : null ,									null, PackingSize.Unspecified, 0);			}	public TypeBuilder DefineType(String name, TypeAttributes attr,								  Type parent)			{				return DefineType(name, attr, parent, null,								  PackingSize.Unspecified, 0);			}	public TypeBuilder DefineType(String name, TypeAttributes attr,								  Type parent, int typeSize)			{				return DefineType(name, attr, parent, null,								  PackingSize.Unspecified, typeSize);			}	public TypeBuilder DefineType(String name, TypeAttributes attr,								  Type parent, PackingSize packSize)			{				return DefineType(name, attr, parent, null,								  packSize, 0);			}	public TypeBuilder DefineType(String name, TypeAttributes attr,								  Type parent, Type[] interfaces)			{				return DefineType(name, attr, parent, interfaces,								  PackingSize.Unspecified, 0);			}	public TypeBuilder DefineType(String name, TypeAttributes attr,								  Type parent, PackingSize packSize,								  int typeSize)			{				return DefineType(name, attr, parent, null,								  packSize, typeSize);			}	// Define uninitialized data as a global field.	public FieldBuilder DefineUninitializedData				(String name, int size, FieldAttributes attributes)			{				try				{					StartSync();					return moduleType.DefineUninitializedData						(name, size, attributes);				}				finally				{					EndSync();				}			}	// Define an unmanaged resource within this module.	[TODO]	public void DefineUnmanagedResource(byte[] resource)			{				try				{					StartSync();					// TODO				}				finally				{					EndSync();				}			}	[TODO]	public void DefineUnmanagedResource(String resourceFileName)			{				try				{					StartSync();					// TODO				}				finally				{					EndSync();				}			}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?