本文整理汇总了C#中Mono.CSharp.ModuleContainer.InitializePredefinedTypes方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleContainer.InitializePredefinedTypes方法的具体用法?C# ModuleContainer.InitializePredefinedTypes怎么用?C# ModuleContainer.InitializePredefinedTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.ModuleContainer
的用法示例。
在下文中一共展示了ModuleContainer.InitializePredefinedTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static DynamicContext Create ()
{
if (dc != null)
return dc;
lock (compiler_initializer) {
if (dc != null)
return dc;
var reporter = new Compiler.Report (ErrorPrinter.Instance) {
WarningLevel = 0
};
var cc = new Compiler.CompilerContext (reporter) {
IsRuntimeBinder = true
};
//IList<Compiler.PredefinedTypeSpec> core_types = null;
//// HACK: To avoid re-initializing static TypeManager types, like string_type
//if (!Compiler.RootContext.EvalMode) {
// core_types = Compiler.TypeManager.InitCoreTypes ();
//}
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer (cc);
var temp = new Compiler.AssemblyDefinitionDynamic (module, "dynamic");
module.SetDeclaringAssembly (temp);
// Import all currently loaded assemblies
var domain = AppDomain.CurrentDomain;
temp.Create (domain, System.Reflection.Emit.AssemblyBuilderAccess.Run);
var importer = new Compiler.ReflectionImporter (cc.BuildinTypes) {
IgnorePrivateMembers = false
};
Compiler.RootContext.ToplevelTypes = module;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
importer.ImportAssembly (a, module.GlobalRootNamespace);
}
if (!Compiler.RootContext.EvalMode) {
cc.BuildinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
}
dc = new DynamicContext (module, importer);
}
return dc;
}
示例2: Compile
//.........这里部分代码省略.........
}
}
#if STATIC
var importer = new StaticImporter (module);
var references_loader = new StaticLoader (importer, ctx);
tr.Start (TimeReporter.TimerType.AssemblyBuilderSetup);
var assembly = new AssemblyDefinitionStatic (module, references_loader, output_file_name, output_file);
assembly.Create (references_loader.Domain);
tr.Stop (TimeReporter.TimerType.AssemblyBuilderSetup);
// Create compiler types first even before any referenced
// assembly is loaded to allow forward referenced types from
// loaded assembly into compiled builder to be resolved
// correctly
tr.Start (TimeReporter.TimerType.CreateTypeTotal);
module.CreateContainer ();
importer.AddCompiledAssembly (assembly);
tr.Stop (TimeReporter.TimerType.CreateTypeTotal);
references_loader.LoadReferences (module);
tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
if (!ctx.BuiltinTypes.CheckDefinitions (module))
return false;
tr.Stop (TimeReporter.TimerType.PredefinedTypesInit);
references_loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new ReflectionImporter (module, ctx.BuiltinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
if (!ctx.BuiltinTypes.CheckDefinitions (module))
return false;
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
return false;
module.CreateContainer ();
loader.LoadModules (assembly, module.GlobalRootNamespace);
#endif
module.InitializePredefinedTypes ();
tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
module.Define ();
tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);
if (Report.Errors > 0)
return false;
if (settings.DocumentationFile != null) {
var doc = new DocumentationBuilder (module);
doc.OutputDocComment (output_file, settings.DocumentationFile);
}
assembly.Resolve ();
if (Report.Errors > 0)
return false;
tr.Start (TimeReporter.TimerType.EmitTotal);
assembly.Emit ();
tr.Stop (TimeReporter.TimerType.EmitTotal);
if (Report.Errors > 0){
return false;
}
tr.Start (TimeReporter.TimerType.CloseTypes);
module.CloseContainer ();
tr.Stop (TimeReporter.TimerType.CloseTypes);
tr.Start (TimeReporter.TimerType.Resouces);
if (!settings.WriteMetadataOnly)
assembly.EmbedResources ();
tr.Stop (TimeReporter.TimerType.Resouces);
if (Report.Errors > 0)
return false;
assembly.Save ();
#if STATIC
references_loader.Dispose ();
#endif
tr.StopTotal ();
tr.ShowStats ();
return Report.Errors == 0;
}
示例3: Create
public static DynamicContext Create ()
{
if (dc != null)
return dc;
lock (compiler_initializer) {
if (dc != null)
return dc;
var settings = new Compiler.CompilerSettings () {
WarningLevel = 0
};
var cc = new Compiler.CompilerContext (settings, ErrorPrinter.Instance) {
IsRuntimeBinder = true
};
//
// Any later loaded assemblies are handled internally by GetAssemblyDefinition
// domain.AssemblyLoad cannot be used as that would be too destructive as we
// would hold all loaded assemblies even if they can be never visited
//
// TODO: Remove this code and rely on GetAssemblyDefinition only
//
var module = new Compiler.ModuleContainer (cc);
module.HasTypesFullyDefined = true;
// Setup fake assembly, it's used mostly to simplify checks like friend-access
var temp = new Compiler.AssemblyDefinitionDynamic (module, "dynamic");
module.SetDeclaringAssembly (temp);
var importer = new Compiler.ReflectionImporter (module, cc.BuiltinTypes) {
IgnorePrivateMembers = false
};
// Import all currently loaded assemblies
// TODO: Rewrite this to populate type cache on-demand, that should greatly
// reduce our start-up cost
var domain = AppDomain.CurrentDomain;
foreach (var a in AppDomain.CurrentDomain.GetAssemblies ()) {
importer.ImportAssembly (a, module.GlobalRootNamespace);
}
cc.BuiltinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
dc = new DynamicContext (module, importer);
}
return dc;
}