本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder类的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder类的具体用法?C# ModuleBuilder怎么用?C# ModuleBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModuleBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了ModuleBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModuleBuilderData
internal ModuleBuilderData(ModuleBuilder module, string strModuleName, string strFileName, int tkFile)
{
this.m_globalTypeBuilder = new TypeBuilder(module);
this.m_module = module;
this.m_tkFile = tkFile;
this.InitNames(strModuleName, strFileName);
}
示例2: RuntimeTypeProvider
static RuntimeTypeProvider()
{
ModuleBuilder = Thread
.GetDomain()
.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run)
.DefineDynamicModule(AssemblyName.Name);
}
示例3: GetTypeBuilder
private TypeBuilder GetTypeBuilder(Type sourceType, ModuleBuilder moduleBuilder)
{
return moduleBuilder.DefineType(
SnapshotNameGenerator.Generate(sourceType),
TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.Sealed,
SnapshotBaseType);
}
示例4: Scope
public Scope(ModuleBuilder moduleBuilder)
{
_vars = new Dictionary<string, ParameterExpression>();
_types = new Dictionary<string, Type>();
_func = new Dictionary<string, LambdaExpression>();
_moduleBuilder = moduleBuilder;
}
示例5: EmitOwnerMappingType
private TypeBuilder EmitOwnerMappingType(IPropertyMappingProvider map, ModuleBuilder defineDynamicModule, string ownerTypeName)
{
var owner = defineDynamicModule.DefineType(
ownerTypeName,
TypeAttributes.Public | TypeAttributes.Interface | TypeAttributes.Abstract,
null,
new[] { typeof(IRdfListOwner) }).CreateType();
var ownerMapType = typeof(ListOwnerMap<>).MakeGenericType(new[] { owner });
var mapBuilderHelper = defineDynamicModule.DefineType(ownerTypeName + "Map", TypeAttributes.Public, ownerMapType);
var propertyBuilder = mapBuilderHelper.DefineProperty("ListPredicate", PropertyAttributes.None, typeof(Uri), null);
var getMethod = mapBuilderHelper.DefineMethod(
"get_ListPredicate",
MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.HideBySig | MethodAttributes.SpecialName,
typeof(Uri),
Type.EmptyTypes);
propertyBuilder.SetGetMethod(getMethod);
var ilGenerator = getMethod.GetILGenerator();
ilGenerator.Emit(OpCodes.Nop);
ilGenerator.Emit(OpCodes.Ldstr, map.GetTerm(_ontologyProvider).ToString());
ilGenerator.Emit(OpCodes.Newobj, typeof(Uri).GetConstructor(new[] { typeof(string) }));
ilGenerator.Emit(OpCodes.Ret);
return mapBuilderHelper;
}
示例6: GenerateCode
public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
{
LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
Label endLabel = codeGenerator.DefineLabel();
Label trueLabel = codeGenerator.DefineLabel();
if (LeftOperand.ReturnType == StringType.StringInstance)
{
codeGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("CompareTo", new Type[] { typeof(string) }));
codeGenerator.Emit(OpCodes.Ldc_I4_0);
codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
}
else
codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
codeGenerator.Emit(OpCodes.Ldc_I4_0);
codeGenerator.Emit(OpCodes.Br, endLabel);
codeGenerator.MarkLabel(trueLabel);
codeGenerator.Emit(OpCodes.Ldc_I4_1);
codeGenerator.MarkLabel(endLabel);
}
示例7: SerializerEmitter
/// <summary>
/// Initializes a new instance of the <see cref="SerializerEmitter"/> class for enum.
/// </summary>
/// <param name="context">A <see cref="SerializationContext"/>.</param>
/// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
/// <param name="specification">The specification of the serializer.</param>
/// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
public SerializerEmitter( SerializationContext context, ModuleBuilder host, SerializerSpecification specification, bool isDebuggable )
: this( host, specification, typeof( EnumMessagePackSerializer<> ).MakeGenericType( specification.TargetType ), isDebuggable )
{
Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName );
this._defaultEnumSerializationMethod = context.EnumSerializationOptions.SerializationMethod;
}
示例8: Compile
public Type Compile(IMetadataSchema schema, ModuleBuilder module, string @namespace, string typeName)
{
if (schema == null)
{
throw new ArgumentNullException(nameof(schema));
}
if (schema.Definitions == null)
{
throw new ArgumentException("There is no definition is schema.", nameof(schema));
}
if (module == null)
{
throw new ArgumentNullException(nameof(module));
}
if (@namespace == null)
{
throw new ArgumentNullException(nameof(@namespace));
}
if (string.IsNullOrWhiteSpace(@namespace))
{
throw new ArgumentException("namespace cannot be white space.", nameof(@namespace));
}
if (typeName == null)
{
throw new ArgumentNullException(nameof(typeName));
}
if (string.IsNullOrWhiteSpace(typeName))
{
throw new ArgumentException("typeName cannot be white space.", nameof(typeName));
}
ValidateProperties();
return CompileCore(schema, module, @namespace, typeName);
}
示例9: NavigatorProxyBuilder
public NavigatorProxyBuilder(ModuleBuilder moduleBuilder, string className, Type interfaceType, Type innerType)
: base(moduleBuilder, className, interfaceType, innerType)
{
_navigateValues = new List<string>();
_innerNavigateMethod = FindInnerNavigateMethod(innerType);
if (_innerNavigateMethod == null)
{
AddErrorMessage("Cannot find method with signature 'void Navigate(string)' in type {0}", innerType);
}
_innerCanNavigateMethod = FindInnerCanNavigateMethod(innerType);
if (_innerCanNavigateMethod == null)
{
AddErrorMessage("Cannot find method with signature 'bool CanNavigate(string)' in type {0}", innerType);
}
_outerNavigateEnumMethod = FindOuterNavigateEnumMethod(interfaceType);
if (_outerNavigateEnumMethod != null)
{
_navigateValueEnumType = _outerNavigateEnumMethod.GetParameters()[0].ParameterType;
_outerCanNavigateEnumMethod = FindOuterCanNavigateEnumMethod(interfaceType, _navigateValueEnumType);
_navigateValues.AddRange(Enum.GetNames(_navigateValueEnumType));
}
FindEvents();
_outerNavigateMethods = FindOuterNavigateMethods();
_outerCanNavigateProperties = FindOuterCanNavigateProperties();
}
示例10: CreateCallee
private void CreateCallee()
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "EnumAssembly";
_myAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
_myModuleBuilder = TestLibrary.Utilities.GetModuleBuilder(_myAssemblyBuilder, "EnumModule.mod");
}
示例11: AssemblyEmitter
public AssemblyEmitter( string assemblyName, bool canSave )
{
m_AssemblyName = assemblyName;
m_AppDomain = AppDomain.CurrentDomain;
m_AssemblyBuilder = m_AppDomain.DefineDynamicAssembly(
new AssemblyName( assemblyName ),
canSave ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run
);
if ( canSave )
{
m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
assemblyName,
String.Format( "{0}.dll", assemblyName.ToLower() ),
false
);
}
else
{
m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
assemblyName,
false
);
}
}
示例12: SetAccessorFactory
/// <summary>
/// Initializes a new instance of the <see cref="SetAccessorFactory"/> class.
/// </summary>
/// <param name="allowCodeGeneration">if set to <c>true</c> [allow code generation].</param>
public SetAccessorFactory(bool allowCodeGeneration)
{
if (allowCodeGeneration)
{
// Detect runtime environment and create the appropriate factory
if (Environment.Version.Major >= 2)
{
_createPropertySetAccessor = new CreatePropertySetAccessor(CreateDynamicPropertySetAccessor);
_createFieldSetAccessor = new CreateFieldSetAccessor(CreateDynamicFieldSetAccessor);
}
else
{
AssemblyName assemblyName = new AssemblyName();
assemblyName.Name = "iBATIS.FastSetAccessor" + HashCodeProvider.GetIdentityHashCode(this);
// Create a new assembly with one module
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(assemblyName.Name + ".dll");
_createPropertySetAccessor = new CreatePropertySetAccessor(CreatePropertyAccessor);
_createFieldSetAccessor = new CreateFieldSetAccessor(CreateFieldAccessor);
}
}
else
{
_createPropertySetAccessor = new CreatePropertySetAccessor(CreateReflectionPropertySetAccessor);
_createFieldSetAccessor = new CreateFieldSetAccessor(CreateReflectionFieldSetAccessor);
}
}
示例13: PropertyAccessor
static PropertyAccessor()
{
AssemblyName asmName = new AssemblyName();
asmName.Name = "$Assembly.Hprose.IO.PropertyAccessor";
asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
modBuilder = asmBuilder.DefineDynamicModule("$Module.PropertyAccessor");
}
示例14: XmlILModule
static XmlILModule() {
AssemblyName asmName;
AssemblyBuilder asmBldr;
CreateModulePermissionSet = new PermissionSet(PermissionState.None);
// CreateDelegate demands MemberAccess permission
CreateModulePermissionSet.AddPermission(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess));
// DynamicMethod constructor demands ControlEvidence permissions.
// Emitting symbols in DefineDynamicModule (to allow to debug the stylesheet) requires UnmanagedCode permission.
CreateModulePermissionSet.AddPermission(new SecurityPermission(SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.UnmanagedCode));
AssemblyId = 0;
// 1. LRE assembly only needs to execute
// 2. No temp files need be created
// 3. Never allow assembly to Assert permissions
asmName = CreateAssemblyName();
asmBldr = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Run);
try {
CreateModulePermissionSet.Assert();
// Add custom attribute to assembly marking it as security transparent so that Assert will not be allowed
// and link demands will be converted to full demands.
asmBldr.SetCustomAttribute(new CustomAttributeBuilder(XmlILConstructors.Transparent, new object[] {}));
// Store LREModule once. If multiple threads are doing this, then some threads might get different
// modules. This is OK, since it's not mandatory to share, just preferable.
LREModule = asmBldr.DefineDynamicModule("System.Xml.Xsl.CompiledQuery", false);
}
finally {
CodeAccessPermission.RevertAssert();
}
}
示例15: FieldAccessor
static FieldAccessor(){
FieldAccessor.accessorFor = new SimpleHashtable(32);
AssemblyName name = new AssemblyName();
name.Name = "JScript FieldAccessor Assembly";
FieldAccessor.assembly = Thread.GetDomain().DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
FieldAccessor.module = FieldAccessor.assembly.DefineDynamicModule("JScript FieldAccessor Module");
}