本文整理汇总了C#中Mono.CSharp.DynamicLoader.LoadReferences方法的典型用法代码示例。如果您正苦于以下问题:C# DynamicLoader.LoadReferences方法的具体用法?C# DynamicLoader.LoadReferences怎么用?C# DynamicLoader.LoadReferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.CSharp.DynamicLoader
的用法示例。
在下文中一共展示了DynamicLoader.LoadReferences方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
void Init ()
{
var loader = new DynamicLoader (importer, ctx);
RootContext.ToplevelTypes = module;
//var startup_files = new List<string> ();
//foreach (CompilationUnit file in Location.SourceFiles)
// startup_files.Add (file.Path);
loader.LoadReferences (module);
ctx.BuiltinTypes.CheckDefinitions (module);
module.InitializePredefinedTypes ();
inited = true;
}
示例2: InitAndGetStartupFiles
/// <summary>
/// Optional initialization for the Evaluator.
/// </summary>
/// <remarks>
/// Initializes the Evaluator with the command line
/// options that would be processed by the command
/// line compiler. Only the first call to
/// InitAndGetStartupFiles or Init will work, any future
/// invocations are ignored.
///
/// You can safely avoid calling this method if your application
/// does not need any of the features exposed by the command line
/// interface.
///
/// This method return an array of strings that contains any
/// files that were specified in `args'.
///
/// If the unknownOptionParser is not null, this function is invoked
/// with the current args array and the index of the option that is not
/// known. A value of true means that the value was processed, otherwise
/// it will be reported as an error
/// </remarks>
public static string [] InitAndGetStartupFiles (string [] args, Func<string [], int, int> unknownOptionParser)
{
lock (evaluator_lock){
if (inited)
return new string [0];
CompilerCallableEntryPoint.Reset ();
var crp = new ConsoleReportPrinter ();
driver = Driver.Create (args, false, unknownOptionParser, crp);
if (driver == null)
throw new Exception ("Failed to create compiler driver with the given arguments");
crp.Fatal = driver.fatal_errors;
ctx = driver.ctx;
RootContext.ToplevelTypes = new ModuleContainer (ctx);
var startup_files = new List<string> ();
foreach (CompilationUnit file in Location.SourceFiles)
startup_files.Add (file.Path);
CompilerCallableEntryPoint.PartialReset ();
var importer = new ReflectionImporter (ctx.BuildinTypes);
loader = new DynamicLoader (importer, ctx);
RootContext.ToplevelTypes.SetDeclaringAssembly (new AssemblyDefinitionDynamic (RootContext.ToplevelTypes, "temp"));
loader.LoadReferences (RootContext.ToplevelTypes);
ctx.BuildinTypes.CheckDefinitions (RootContext.ToplevelTypes);
RootContext.ToplevelTypes.InitializePredefinedTypes ();
RootContext.EvalMode = true;
inited = true;
return startup_files.ToArray ();
}
}
示例3: Compile
//.........这里部分代码省略.........
Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
return false;
}
int pos = output_file_name.LastIndexOf ('.');
if (pos > 0)
output_file_name = output_file_name.Substring (0, pos);
output_file_name += settings.TargetExt;
output_file = output_file_name;
} else {
output_file_name = Path.GetFileName (output_file);
}
#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.CreateType ();
importer.AddCompiledAssembly (assembly);
tr.Stop (TimeReporter.TimerType.CreateTypeTotal);
references_loader.LoadReferences (module);
tr.Start (TimeReporter.TimerType.PredefinedTypesInit);
if (!ctx.BuildinTypes.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.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Run))
return false;
module.CreateType ();
loader.LoadModules (assembly, module.GlobalRootNamespace);
#endif
tr.Start (TimeReporter.TimerType.ModuleDefinitionTotal);
module.Define ();
tr.Stop (TimeReporter.TimerType.ModuleDefinitionTotal);
示例4: Compile
//
// Main compilation method
//
public bool Compile ()
{
var module = new ModuleContainer (ctx);
RootContext.ToplevelTypes = module;
if (timestamps) {
stopwatch = Stopwatch.StartNew ();
first_time = DateTime.Now;
}
Parse (module);
ShowTime ("Parsing source files");
if (Report.Errors > 0)
return false;
if (RootContext.TokenizeOnly || RootContext.ParseOnly)
return true;
if (RootContext.ToplevelTypes.NamespaceEntry != null)
throw new InternalErrorException ("who set it?");
//
// Quick hack
//
var output_file = RootContext.OutputFile;
string output_file_name;
if (output_file == null) {
if (first_source == null) {
Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
return false;
}
int pos = first_source.LastIndexOf ('.');
if (pos > 0)
output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
else
output_file = first_source + RootContext.TargetExt;
output_file_name = output_file;
} else {
output_file_name = Path.GetFileName (output_file);
}
//
// Load assemblies required
//
if (timestamps)
stopwatch = Stopwatch.StartNew ();
#if STATIC
var assembly = new AssemblyDefinitionStatic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new StaticImporter ();
assembly.Importer = importer;
var loader = new StaticLoader (importer, ctx);
loader.LoadReferences (module);
ShowTime ("Imporing referenced assemblies");
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
ShowTime ("Initializing predefined types");
if (!assembly.Create (loader))
return false;
// System.Object was not loaded, use compiled assembly as corlib
if (loader.Corlib == null)
loader.Corlib = assembly.Builder;
loader.LoadModules (assembly, module.GlobalRootNamespace);
#else
var assembly = new AssemblyDefinitionDynamic (module, output_file_name, output_file);
module.SetDeclaringAssembly (assembly);
var importer = new ReflectionImporter (ctx.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
ShowTime ("Imporing referenced assemblies");
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
ShowTime ("Initializing predefined types");
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
return false;
loader.LoadModules (assembly, module.GlobalRootNamespace);
//.........这里部分代码省略.........
示例5: Compile
//
// Main compilation method
//
public bool Compile ()
{
var module = new ModuleContainer (ctx);
RootContext.ToplevelTypes = module;
if (timestamps) {
stopwatch = Stopwatch.StartNew ();
first_time = DateTime.Now;
}
Parse (module);
ShowTime ("Parsing source files");
if (Report.Errors > 0)
return false;
if (tokenize || parse_only)
return true;
if (RootContext.ToplevelTypes.NamespaceEntry != null)
throw new InternalErrorException ("who set it?");
//
// Quick hack
//
if (output_file == null){
if (first_source == null){
Report.Error (1562, "If no source files are specified you must specify the output file with -out:");
return false;
}
int pos = first_source.LastIndexOf ('.');
if (pos > 0)
output_file = first_source.Substring (0, pos) + RootContext.TargetExt;
else
output_file = first_source + RootContext.TargetExt;
}
//
// Load assemblies required
//
if (timestamps)
stopwatch = Stopwatch.StartNew ();
var assembly = module.MakeExecutable (output_file, output_file);
var importer = new ReflectionImporter (ctx.BuildinTypes);
assembly.Importer = importer;
var loader = new DynamicLoader (importer, ctx);
loader.LoadReferences (module);
ShowTime ("Imporing referenced assemblies");
if (!ctx.BuildinTypes.CheckDefinitions (module))
return false;
ShowTime ("Initializing predefined types");
if (!assembly.Create (AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
return false;
loader.LoadModules (assembly);
module.Define ();
ShowTime ("Types definition");
if (Report.Errors > 0)
return false;
if (Report.Errors == 0 &&
RootContext.Documentation != null &&
!RootContext.Documentation.OutputDocComment (
output_file, Report))
return false;
//
// Verify using aliases now
//
NamespaceEntry.VerifyAllUsing ();
if (Report.Errors > 0){
return false;
}
assembly.Resolve ();
if (Report.Errors > 0)
return false;
//
// The code generator
//
if (timestamps)
stopwatch = Stopwatch.StartNew ();
//.........这里部分代码省略.........