本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder.DefineDocument方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.DefineDocument方法的具体用法?C# ModuleBuilder.DefineDocument怎么用?C# ModuleBuilder.DefineDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.DefineDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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>();
}
示例2: ILDynamicMethodDebugImpl
public ILDynamicMethodDebugImpl(string name, Type delegateType, Type thisType)
{
_delegateType = delegateType;
_expectedLength = 64;
var mi = delegateType.GetMethod("Invoke");
var uniqueName = ILDynamicTypeDebugImpl.UniqueName(name);
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
_symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
_sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
Type[] parameterTypes;
if (thisType != null)
{
parameterTypes = new[] { thisType }.Concat(mi.GetParameters().Select(pi => pi.ParameterType)).ToArray();
}
else
{
parameterTypes = mi.GetParameters().Select(pi => pi.ParameterType).ToArray();
}
_sourceCodeWriter.StartMethod(name, mi.ReturnType, parameterTypes, MethodAttributes.Static);
_typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, typeof(object), Type.EmptyTypes);
_forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
_dynamicMethod = _typeBuilder.DefineMethod("Invoke", MethodAttributes.Public | MethodAttributes.Static, mi.ReturnType, parameterTypes);
for (int i = 0; i < parameterTypes.Length; i++)
{
_dynamicMethod.DefineParameter(i + 1, ParameterAttributes.In, string.Format("arg{0}", i));
}
}
示例3: BeginModule
public void BeginModule(string ifile)
{
appdomain = System.Threading.Thread.GetDomain();
appname = getAssemblyName(filename);
appbuild = appdomain.DefineDynamicAssembly(appname, AssemblyBuilderAccess.Save, ".");
emodule = appbuild.DefineDynamicModule(filename + "_module", io.GetOutputFilename(), io.getGenDebug());
Guid g = System.Guid.Empty;
if (io.getGenDebug()) srcdoc = emodule.DefineDocument(ifile, g, g, g);
}
示例4: ILDynamicTypeDebugImpl
public ILDynamicTypeDebugImpl(string name, Type baseType, Type[] interfaces)
{
_name = name;
var uniqueName = UniqueName(name);
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, "dynamicIL");
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
var sourceCodeFileName = Path.GetFullPath("dynamicIL/" + uniqueName + ".il");
_symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
_sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
_sourceCodeWriter.WriteLine(string.Format("class {0} : {1}{2}", name, baseType.ToSimpleName(), string.Concat(interfaces.Select(i => ", " + i.ToSimpleName()))));
_sourceCodeWriter.OpenScope();
_typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
_forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
}
示例5: ILDynamicTypeDebugImpl
public ILDynamicTypeDebugImpl(string name, Type baseType, Type[] interfaces)
{
_name = name;
var uniqueName = UniqueName(name, 259 - (DynamicILDirectoryPath.DynamicIL.Length + 1 + 4));
_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(uniqueName), AssemblyBuilderAccess.RunAndSave, DynamicILDirectoryPath.DynamicIL);
_moduleBuilder = _assemblyBuilder.DefineDynamicModule(uniqueName + ".dll", true);
var sourceCodeFileName = Path.Combine(DynamicILDirectoryPath.DynamicIL, uniqueName + ".il");
_symbolDocumentWriter = _moduleBuilder.DefineDocument(sourceCodeFileName, SymDocumentType.Text, SymLanguageType.ILAssembly, SymLanguageVendor.Microsoft);
_sourceCodeWriter = new SourceCodeWriter(sourceCodeFileName, _symbolDocumentWriter);
_sourceCodeWriter.WriteLine(
$"class {name} : {baseType.ToSimpleName()}{string.Concat(interfaces.Select(i => ", " + i.ToSimpleName()))}");
_sourceCodeWriter.OpenScope();
_typeBuilder = _moduleBuilder.DefineType(name, TypeAttributes.Public, baseType, interfaces);
_forbidenInstructions = new ILGenForbidenInstructionsCheating(_typeBuilder);
}
示例6: GetParser
public static Parser GetParser(ModuleBuilder mb, LOLProgram prog, string filename, Stream s, CompilerResults cr) {
Parser p = new Parser(new Scanner(s));
p.filename = Path.GetFileName(filename);
if (prog.compileropts.IncludeDebugInformation)
{
p.doc = mb.DefineDocument(p.filename, Guid.Empty, Guid.Empty, Guid.Empty);
}
else
{
//Not a debug build
p.doc = null;
}
p.program = prog;
p.errors = new Errors(cr.Errors);
p.main = prog.methods["Main"];
return p;
}
示例7: Emitter
public Emitter(EmitterOptions options)
{
_options = options;
//// TODO: setup separate app domain with appropriate cache path, shadow copying etc.
//var domainName = "plan" + DateTime.Now.Ticks.ToString();
//var domain = AppDomain.CreateDomain(domainName);
_assemblyName = new AssemblyName(_options.AssemblyName);
_assembly =
AppDomain.CurrentDomain.DefineDynamicAssembly
(
_assemblyName,
_options.DebugOn ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.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<TupleType, System.Type>();
}
示例8: DefineSymbolDocument
internal void DefineSymbolDocument(ModuleBuilder module, string url, Guid language, Guid languageVendor, Guid documentType)
{
symbols = module.DefineDocument(url, language, languageVendor, documentType);
}
示例9: GetDocumentWriterFor
ISymbolDocumentWriter GetDocumentWriterFor(ISymbolDocument doc, ModuleBuilder moduleBuilder)
{
return moduleBuilder.DefineDocument(doc.URL, doc.Language, doc.LanguageVendor, doc.DocumentType);
}
示例10: DefineProgram
/// <summary>
/// set program name and creates AssemblyBuilder, ModuleBuilder and debug Document
/// </summary>
/// <param name="n">N.</param>
public void DefineProgram(string n)
{
this.ProgramName = n.ToUpper();
// create AssemblyBuilder for RunAndSave
AssemblyName aName = new AssemblyName(this.ProgramName);
ab = AppDomain.CurrentDomain.DefineDynamicAssembly( aName,
AssemblyBuilderAccess.RunAndSave );
// mark generated code as debuggable
System.Type daType = typeof(DebuggableAttribute);
ConstructorInfo daCtor = daType.GetConstructor(new System.Type[] { typeof(DebuggableAttribute.DebuggingModes) });
CustomAttributeBuilder daBuilder = new CustomAttributeBuilder(daCtor, new object[] {
DebuggableAttribute.DebuggingModes.DisableOptimizations |
DebuggableAttribute.DebuggingModes.Default });
ab.SetCustomAttribute(daBuilder);
// For a single-module assembly, the module name is usually
// the assembly name plus an extension.
module = ab.DefineDynamicModule(this.ProgramName, this.ProgramName + ".dll", true);
// Tell Emit about the source file that we want to associate this with.
FileInfo info = new FileInfo(this.ProgramName + ".abap");
doc = module.DefineDocument(info.FullName, Guid.Empty, Guid.Empty, Guid.Empty);
}