本文整理汇总了C#中System.Reflection.Emit.AssemblyBuilder类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyBuilder类的具体用法?C# AssemblyBuilder怎么用?C# AssemblyBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyBuilder类属于System.Reflection.Emit命名空间,在下文中一共展示了AssemblyBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Reset
public void Reset()
{
UniqueCounter++;
var CurrentAppDomain = AppDomain.CurrentDomain;
AssemblyBuilder = CurrentAppDomain.DefineDynamicAssembly(new AssemblyName("assembly" + UniqueCounter), AssemblyBuilderAccess.RunAndSave);
ModuleBuilder = AssemblyBuilder.DefineDynamicModule("module" + UniqueCounter);
}
示例2: 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");
}
示例3: 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);
}
}
示例4: NativeCall
static NativeCall() {
// The static constructor is responsible for generating the
// assembly and the methods that implement the IJW thunks.
//
// To do this, we actually use reflection on the INativeCall
// interface (defined below) and generate the required thunk
// code based on the method signatures.
AssemblyName aname = new AssemblyName();
aname.Name = "e__NativeCall_Assembly";
AssemblyBuilderAccess aa = AssemblyBuilderAccess.Run;
aBuilder = Thread.GetDomain().DefineDynamicAssembly(aname, aa);
mBuilder = aBuilder.DefineDynamicModule("e__NativeCall_Module");
TypeAttributes ta = TypeAttributes.Public;
TypeBuilder tBuilder = mBuilder.DefineType("e__NativeCall", ta);
Type iType = typeof(INativeCall);
tBuilder.AddInterfaceImplementation(iType);
// Use reflection to loop over the INativeCall interface methods,
// calling GenerateThunk to create a managed thunk for each one.
foreach (MethodInfo method in iType.GetMethods()) {
GenerateThunk(tBuilder, method);
}
Type theType = tBuilder.CreateType();
Impl = (INativeCall)Activator.CreateInstance(theType);
}
示例5: CreateCallee
private void CreateCallee()
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "EnumAssembly";
_myAssemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
_myModuleBuilder = TestLibrary.Utilities.GetModuleBuilder(_myAssemblyBuilder, "EnumModule.mod");
}
示例6: DynamicAssemblyManager
static DynamicAssemblyManager()
{
#if !SILVERLIGHT
assemblyName = new AssemblyName("NLiteDynamicAssembly");
assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName,
AssemblyBuilderAccess.RunAndSave
);
moduleBuilder = assemblyBuilder.DefineDynamicModule(
assemblyName.Name,
assemblyName.Name + ".dll",
true);
Module = assemblyBuilder.GetModules().FirstOrDefault();
#else
assemblyName = new AssemblyName("EmitMapperAssembly.SL");
assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
assemblyName,
AssemblyBuilderAccess.Run
);
moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, true);
#endif
}
示例7: GetInvokeMethod
public MethodInfo GetInvokeMethod(string methodName, Type returnType, Type[] types)
{
string entryName = methodName;
if (assemblyBuilder == null)
{
AssemblyName assemblyName = new AssemblyName(AssemblyName);
assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
moduleBuilder = assemblyBuilder.DefineDynamicModule(AssemblyName);
}
var defineType = moduleBuilder.DefineType(GetDefineTypeName(methodName));
var methodBuilder = defineType.DefinePInvokeMethod(methodName, dllName, entryName,
MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.PinvokeImpl,
CallingConventions.Standard,
returnType, types,
CallingConvention, CharSet);
if ((returnType != null) && (returnType != typeof(void)))
{
methodBuilder.SetImplementationFlags(MethodImplAttributes.PreserveSig | methodBuilder.GetMethodImplementationFlags());
}
var type = defineType.CreateType();
var method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static);
return method;
}
示例8: Emitter
public Emitter(EmitterOptions options)
{
_options = options;
_assemblyName = new AssemblyName(_options.AssemblyName);
_assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(_assemblyName, AssemblyBuilderAccess.RunAndSave);// TODO: temp for debugging .RunAndCollect);
if (_options.DebugOn)
_assembly.SetCustomAttribute
(
new CustomAttributeBuilder
(
typeof(DebuggableAttribute).GetConstructor
(
new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) }
),
new object[]
{
DebuggableAttribute.DebuggingModes.DisableOptimizations |
DebuggableAttribute.DebuggingModes.Default
}
)
);
_module = _assembly.DefineDynamicModule(_assemblyName.Name, _assemblyName.Name + ".dll", _options.DebugOn);
if (_options.DebugOn)
_symbolWriter = _module.DefineDocument(_options.SourceFileName, Guid.Empty, Guid.Empty, Guid.Empty);
_tupleToNative = new Dictionary<Type.TupleType, System.Type>();
}
示例9: ILDynamicTypeImpl
public ILDynamicTypeImpl(string name, Type baseType, Type[] interfaces)
{
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(name), AssemblyBuilderAccess.RunAndCollect);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(name + ".dll", true);
_typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
_forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
}
示例10: EmitPropertyGetAccessor
/// <summary>
/// Initializes a new instance of the <see cref="EmitPropertyGetAccessor"/> class.
/// </summary>
/// <param name="targetObjectType">Type of the target object.</param>
/// <param name="propertyName">Name of the property.</param>
/// <param name="assemblyBuilder">The <see cref="AssemblyBuilder"/>.</param>
/// <param name="moduleBuilder">The <see cref="ModuleBuilder"/>.</param>
public EmitPropertyGetAccessor(Type targetObjectType, string propertyName, AssemblyBuilder assemblyBuilder, ModuleBuilder moduleBuilder)
{
_targetType = targetObjectType;
_propertyName = propertyName;
// deals with Overriding a property using new and reflection
// http://blogs.msdn.com/thottams/archive/2006/03/17/553376.aspx
PropertyInfo propertyInfo = _targetType.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
if (propertyInfo == null)
{
propertyInfo = _targetType.GetProperty(propertyName);
}
// Make sure the property exists
if(propertyInfo == null)
{
throw new NotSupportedException(
string.Format("Property \"{0}\" does not exist for type "
+ "{1}.", propertyName, _targetType));
}
else
{
this._propertyType = propertyInfo.PropertyType;
_canRead = propertyInfo.CanRead;
this.EmitIL(assemblyBuilder, moduleBuilder);
}
}
示例11: RunTimeCreator
/// <summary>
/// Initializes the runtime compiler and metadata references for dynamic assembly.
/// </summary>
public RunTimeCreator()
{
usedNameDict = new Dictionary<string, int>();
// Set references to runtime compiling
isCompiled = new List<string>();
var t = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
metadataRef = new List<MetadataReference>();
metadataRef.Add(MetadataFileReference.CreateAssemblyReference("mscorlib"));
metadataRef.Add(new MetadataFileReference(typeof(Strategy.MyMogre).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(Strategy.Game).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(GameObjectControl.Game_Objects.StaticGameObjectBox.StaticGameObject).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(Team).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(System.Linq.Enumerable).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(LinkedList<>).Assembly.Location));
metadataRef.Add(new MetadataFileReference(Path.GetFullPath((new Uri(t + "\\\\Mogre.dll")).LocalPath)));
metadataRef.Add(new MetadataFileReference(typeof(PropertyManager).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(GameObjectControl.Game_Objects.StaticGameObjectBox.IStaticGameObject).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(ActionAnswer).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(PropertyEnum).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(XmlLoadException).Assembly.Location));
metadataRef.Add(new MetadataFileReference(typeof(ConstructorFieldAttribute).Assembly.Location));
comilationOption = new CompilationOptions(OutputKind.DynamicallyLinkedLibrary);
assemblyBuilder =
AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("DynamicAssembly" + Guid.NewGuid()),
AssemblyBuilderAccess.RunAndCollect);
moduleBuilder = assemblyBuilder.DefineDynamicModule("DynamicModule");
}
示例12: RegexTypeCompiler
internal RegexTypeCompiler(AssemblyName an, CustomAttributeBuilder[] attribs, string resourceFile)
{
new ReflectionPermission(PermissionState.Unrestricted).Assert();
try
{
List<CustomAttributeBuilder> assemblyAttributes = new List<CustomAttributeBuilder>();
CustomAttributeBuilder item = new CustomAttributeBuilder(typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes), new object[0]);
assemblyAttributes.Add(item);
CustomAttributeBuilder builder2 = new CustomAttributeBuilder(typeof(SecurityRulesAttribute).GetConstructor(new Type[] { typeof(SecurityRuleSet) }), new object[] { SecurityRuleSet.Level2 });
assemblyAttributes.Add(builder2);
this._assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave, assemblyAttributes);
this._module = this._assembly.DefineDynamicModule(an.Name + ".dll");
if (attribs != null)
{
for (int i = 0; i < attribs.Length; i++)
{
this._assembly.SetCustomAttribute(attribs[i]);
}
}
if (resourceFile != null)
{
this._assembly.DefineUnmanagedResource(resourceFile);
}
}
finally
{
CodeAccessPermission.RevertAssert();
}
}
示例13: CreateAssembly
private void CreateAssembly()
{ //to create an assembly programmatically
AssemblyName Name = new AssemblyName("NaiveORM0Classes");
AppDomain Domain = Thread.GetDomain();
_Builder = Domain.DefineDynamicAssembly(Name, AssemblyBuilderAccess.Run);
_Module = _Builder.DefineDynamicModule("NaiveORM0ClassesM");
}
示例14: DynamicAssembly
public DynamicAssembly()
{
int assemblyNumber = Interlocked.Increment(ref _assemblyCount);
_assemblyName = new AssemblyName {
Name = String.Format("Quokka.DynamicAssembly.N{0}", assemblyNumber)
};
string moduleName = AssemblyName.Name;
_dynamicClassNamespace = AssemblyName.Name;
if (CreateFiles)
{
_assemblyBuilder = Thread.GetDomain().DefineDynamicAssembly(
AssemblyName, AssemblyBuilderAccess.RunAndSave);
// Add a debuggable attribute to the assembly saying to disable optimizations
// See http://blogs.msdn.com/rmbyers/archive/2005/06/26/432922.aspx
Type daType = typeof (DebuggableAttribute);
ConstructorInfo daCtor = daType.GetConstructor(new[] {typeof (bool), typeof (bool)});
var daBuilder = new CustomAttributeBuilder(daCtor, new object[] {true, true});
_assemblyBuilder.SetCustomAttribute(daBuilder);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(moduleName);
_canSave = true;
}
else
{
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(AssemblyName, AssemblyBuilderAccess.Run);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(moduleName);
}
}
示例15: WrapFactory
/// <summary>
/// A static constructor.
/// </summary>
static WrapFactory()
{
AssemblyName asmName = new AssemblyName();
asmName.Name = "SqlWrapperDynamicAsm";
m_asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
m_modBuilder = m_asmBuilder.DefineDynamicModule("SqlWrapperDynamicModule");
}