本文整理汇总了C#中Evaluator.ReferenceAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# Evaluator.ReferenceAssembly方法的具体用法?C# Evaluator.ReferenceAssembly怎么用?C# Evaluator.ReferenceAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Evaluator
的用法示例。
在下文中一共展示了Evaluator.ReferenceAssembly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public ScriptResult Execute(string code, string[] scriptArgs, AssemblyReferences references, IEnumerable<string> namespaces,
ScriptPackSession scriptPackSession)
{
Guard.AgainstNullArgument("references", references);
Guard.AgainstNullArgument("scriptPackSession", scriptPackSession);
references.PathReferences.UnionWith(scriptPackSession.References);
SessionState<Evaluator> sessionState;
if (!scriptPackSession.State.ContainsKey(SessionKey))
{
Logger.Debug("Creating session");
var context = new CompilerContext(new CompilerSettings
{
AssemblyReferences = references.PathReferences.ToList()
}, new ConsoleReportPrinter());
var evaluator = new Evaluator(context);
var allNamespaces = namespaces.Union(scriptPackSession.Namespaces).Distinct();
var host = _scriptHostFactory.CreateScriptHost(new ScriptPackManager(scriptPackSession.Contexts), scriptArgs);
MonoHost.SetHost((ScriptHost)host);
evaluator.ReferenceAssembly(typeof(MonoHost).Assembly);
evaluator.InteractiveBaseClass = typeof(MonoHost);
sessionState = new SessionState<Evaluator>
{
References = new AssemblyReferences(references.PathReferences, references.Assemblies),
Namespaces = new HashSet<string>(),
Session = evaluator
};
ImportNamespaces(allNamespaces, sessionState);
scriptPackSession.State[SessionKey] = sessionState;
}
else
{
Logger.Debug("Reusing existing session");
sessionState = (SessionState<Evaluator>)scriptPackSession.State[SessionKey];
var newReferences = sessionState.References == null ? references : references.Except(sessionState.References);
foreach (var reference in newReferences.PathReferences)
{
Logger.DebugFormat("Adding reference to {0}", reference);
sessionState.Session.LoadAssembly(reference);
}
sessionState.References = new AssemblyReferences(references.PathReferences, references.Assemblies);
var newNamespaces = sessionState.Namespaces == null ? namespaces : namespaces.Except(sessionState.Namespaces);
ImportNamespaces(newNamespaces, sessionState);
}
Logger.Debug("Starting execution");
var result = Execute(code, sessionState.Session);
Logger.Debug("Finished execution");
return result;
}
示例2: StartAgent
public static void StartAgent()
{
Attached = true;
// First, try to detect if Gtk.Application.Run is running,
// to determine whether we need to run a mainloop oursvels or not.
//
// This test is not bullet proof, its just a simple guess.
//
// Thanks to Alan McGovern for this brilliant hack.
//
ManualResetEvent handle = new ManualResetEvent(false);
Gtk.Application.Invoke (delegate { handle.Set (); });
HostHasGtkRunning = handle.WaitOne (3000, true);
InteractiveGraphicsBase.Attached = true;
Gtk.Application.Invoke (delegate {
try {
evaluator = new Evaluator (new CompilerContext (new CompilerSettings (), new ConsoleReportPrinter ()));
} catch {
return;
}
try {
// Add all assemblies loaded later
AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoaded;
// Add all currently loaded assemblies
foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies ())
evaluator.ReferenceAssembly (a);
Start (String.Format ("Attached C# Interactive Shell at Process {0}", Process.GetCurrentProcess ().Id), null);
} finally {
AppDomain.CurrentDomain.AssemblyLoad -= AssemblyLoaded;
}
});
}