当前位置: 首页>>代码示例>>C#>>正文


C# Evaluator.ReferenceAssembly方法代码示例

本文整理汇总了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;
        }
开发者ID:selony,项目名称:scriptcs,代码行数:60,代码来源:MonoScriptEngine.cs

示例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;
                }

                });
        }
开发者ID:alfredodev,项目名称:mono-tools,代码行数:39,代码来源:Main.cs


注:本文中的Evaluator.ReferenceAssembly方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。