• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Repl类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Repl的典型用法代码示例。如果您正苦于以下问题:C# Repl类的具体用法?C# Repl怎么用?C# Repl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Repl类属于命名空间,在下文中一共展示了Repl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Execute

        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c to exit)" + Environment.NewLine);
            var repl = new Repl(_scriptArgs, _fileSystem, _scriptEngine, _serializer, _logger, _console, _filePreProcessor, _replCommands);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks = _scriptPackResolver.GetPacks();

            repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            try
            {
                if (!string.IsNullOrWhiteSpace(_scriptName))
                {
                    _logger.Info(string.Format("Loading script: {0}", _scriptName));
                    repl.Execute(string.Format("#load {0}", _scriptName));
                }

                while (ExecuteLine(repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return CommandResult.Error;
            }

            repl.Terminate();
            return CommandResult.Success;
        }
开发者ID:selony,项目名称:scriptcs,代码行数:34,代码来源:ExecuteReplCommand.cs


示例2: ExecuteLine

        private bool ExecuteLine(Repl repl)
        {
            _console.Write("> ");
            var line = _console.ReadLine();
            if (line == "")
                return false;

            repl.Execute(line);
            return true;
        }
开发者ID:7sharp9,项目名称:scriptcs,代码行数:10,代码来源:ExecuteReplCommand.cs


示例3: ExecuteLine

        private bool ExecuteLine(Repl repl)
        {
            if (string.IsNullOrWhiteSpace(repl.Buffer))
                _console.Write("> ");

            var line = _console.ReadLine();
            if (line == string.Empty && string.IsNullOrWhiteSpace(repl.Buffer)) return false;

            repl.Execute(line);
            return true;
        }
开发者ID:johnduhart,项目名称:scriptcs,代码行数:11,代码来源:ExecuteReplCommand.cs


示例4: InstructionWorksEndToEnd

        public void InstructionWorksEndToEnd(SetUp setup, string input,
                                         string expectedOutput)
        {
            var model = new ProgrammingModel();
              var memory = new Memory();
              setup(model, memory);
              var repl = new Repl(model, memory);

              if (!repl.TryRead(input))
            Assert.Fail(string.Format("Unable to read assembly input: '{0}'", input));
              if (!repl.Execute())
            Assert.Fail(string.Format("Unable to execute input: '{0}'", input));
              Assert.That(repl.PrintRegisters(), Is.StringContaining(expectedOutput));
        }
开发者ID:joshpeterson,项目名称:mos,代码行数:14,代码来源:IntegrationTests.cs


示例5: Execute

 public CommandResult Execute()
 {
     _console.WriteLine("scriptcs (ctrl-c or blank to exit)\r\n");
     var repl = new Repl(_fileSystem, _scriptEngine, _logger, _console, _filePreProcessor);
     repl.Initialize(GetAssemblyPaths(_fileSystem.CurrentDirectory), _scriptPackResolver.GetPacks());
     try
     {
         while (ExecuteLine(repl))
         {
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex.Message);
         return CommandResult.Error;
     }
     repl.Terminate();
     return CommandResult.Success;
 }
开发者ID:7sharp9,项目名称:scriptcs,代码行数:19,代码来源:ExecuteReplCommand.cs


示例6: ShouldAliasCommandWithNewName

            public void ShouldAliasCommandWithNewName()
            {
                // arrange
                var currentDir = @"C:\";
                var dummyCommand = new Mock<IReplCommand>();
                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                var fs = new Mock<IFileSystem>();
                fs.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fs.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var console = new Mock<IConsole>();
                var executor = new Repl(null, fs.Object, null, null, null, null, null, new List<IReplCommand> { dummyCommand.Object });

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }
开发者ID:jrusbatch,项目名称:scriptcs,代码行数:23,代码来源:AliasCommandTests.cs


示例7: ShouldAliasCommandWithNewName

            public void ShouldAliasCommandWithNewName(
                Mock<IFileSystem> fileSystem,
                Mock<IScriptEngine> engine,
                Mock<IObjectSerializer> serializer,
                Mock<ILog> logger,
                Mock<IScriptLibraryComposer> composer,
                Mock<IConsole> console,
                Mock<IFilePreProcessor> filePreProcessor)
            {
                // arrange
                var currentDir = @"C:\";
                var dummyCommand = new Mock<IReplCommand>();
                dummyCommand.Setup(x => x.CommandName).Returns("foo");

                fileSystem.Setup(x => x.BinFolder).Returns(Path.Combine(currentDir, "bin"));
                fileSystem.Setup(x => x.DllCacheFolder).Returns(Path.Combine(currentDir, "cache"));

                var executor = new Repl(
                    new string[0],
                    fileSystem.Object,
                    engine.Object,
                    serializer.Object,
                    logger.Object,
                    composer.Object,
                    console.Object,
                    filePreProcessor.Object,
                    new List<IReplCommand> { dummyCommand.Object });

                var cmd = new AliasCommand(console.Object);

                // act
                cmd.Execute(executor, new[] { "foo", "bar" });

                // assert
                executor.Commands.Count.ShouldEqual(2);
                executor.Commands["bar"].ShouldBeSameAs(executor.Commands["foo"]);
            }
开发者ID:nagyistoce,项目名称:scriptcs,代码行数:37,代码来源:AliasCommandTests.cs


示例8: ShouldNotExecuteLoadedFileIfFileDoesNotExist

            public void ShouldNotExecuteLoadedFileIfFileDoesNotExist()
            {
                var mocks = new Mocks();
                mocks.FileSystem.Setup(x => x.FileExists("file.csx")).Returns(false);

                _repl = GetRepl(mocks);
                _repl.Execute("#load \"file.csx\"");

                mocks.ScriptEngine.Verify(i => i.Execute(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()), Times.Never());
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:10,代码来源:ReplTests.cs


示例9: ShouldProcessFileIfLineIsALoad

            public void ShouldProcessFileIfLineIsALoad()
            {
                var mocks = new Mocks();
                mocks.FileSystem.Setup(x => x.FileExists("file.csx")).Returns(true);

                _repl = GetRepl(mocks);
                _repl.Execute("#load \"file.csx\"");

                mocks.FilePreProcessor.Verify(i => i.ProcessScript("#load \"file.csx\""), Times.Once());
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:10,代码来源:ReplTests.cs


示例10: ShouldExecuteLoadedFileIfLineIsALoad

            public void ShouldExecuteLoadedFileIfLineIsALoad()
            {
                var mocks = new Mocks();
                mocks.FilePreProcessor.Setup(x => x.ProcessScript(It.IsAny<string>()))
                     .Returns(new FilePreProcessorResult());
                mocks.FileSystem.Setup(x => x.FileExists("file.csx")).Returns(true);

                _repl = GetRepl(mocks);
                _repl.Execute("#load \"file.csx\"");

                mocks.ScriptEngine.Verify(i => i.Execute(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()), Times.Once());
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:12,代码来源:ReplTests.cs


示例11: ShouldNotExecuteAnythingIfLineIsAReference

            public void ShouldNotExecuteAnythingIfLineIsAReference()
            {
                var mocks = new Mocks();
                mocks.FileSystem.Setup(i => i.CurrentDirectory).Returns("C:/");
                _repl = GetRepl(mocks);
                _repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>());
                _repl.Execute("#r \"my.dll\"");

                mocks.ScriptEngine.Verify(i => i.Execute(It.IsAny<string>(), It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(), It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()), Times.Never());
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:10,代码来源:ReplTests.cs


示例12: ShouldResubmitEverytingIfLineIsNoLongerMultilineConstruct

            public void ShouldResubmitEverytingIfLineIsNoLongerMultilineConstruct()
            {
                var mocks = new Mocks();
                mocks.ScriptEngine.Setup(
                    x =>
                    x.Execute(It.Is<string>(i => i == "class test {}"), It.IsAny<string[]>(), It.IsAny<AssemblyReferences>(),
                              It.IsAny<IEnumerable<string>>(), It.IsAny<ScriptPackSession>()))
                     .Returns(new ScriptResult
                     {
                         IsPendingClosingChar = false
                     });
                mocks.FileSystem.Setup(i => i.CurrentDirectory).Returns("C:/");
                _repl = GetRepl(mocks);
                _repl.Buffer = "class test {";
                _repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>());
                _repl.Execute("}");

                mocks.ScriptEngine.Verify();
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:19,代码来源:ReplTests.cs


示例13: ShouldEvaluateArgs

            public void ShouldEvaluateArgs()
            {
                var dummyObject = new DummyClass { Hello = "World" };
                var helloCommand = new Mock<IReplCommand>();
                helloCommand.SetupGet(x => x.CommandName).Returns("hello");

                var mocks = new Mocks { ReplCommands = new[] { helloCommand } };
                mocks.ScriptEngine.Setup(x => x.Execute(
                        "myObj",
                        It.IsAny<string[]>(),
                        It.IsAny<AssemblyReferences>(),
                        It.IsAny<IEnumerable<string>>(),
                        It.IsAny<ScriptPackSession>()))
                    .Returns(new ScriptResult(returnValue: dummyObject));

                mocks.ScriptEngine.Setup(x => x.Execute(
                        "100",
                        It.IsAny<string[]>(),
                        It.IsAny<AssemblyReferences>(),
                        It.IsAny<IEnumerable<string>>(),
                        It.IsAny<ScriptPackSession>()))
                    .Returns(new ScriptResult(returnValue: 100));

                _repl = GetRepl(mocks);

                _repl.Execute(":hello 100 myObj", null);

                helloCommand.Verify(
                    x => x.Execute(
                        _repl,
                        It.Is<object[]>(i =>
                            i[0].GetType() == typeof(int) &&
                            (int)i[0] == 100 &&
                            i[1].Equals(dummyObject))),
                    Times.Once);
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:36,代码来源:ReplTests.cs


示例14: TheInitializeMethod

 public TheInitializeMethod()
 {
     _mocks = new Mocks();
     _repl = GetRepl(_mocks);
     _mocks.FileSystem.Setup(x => x.CurrentDirectory).Returns(@"c:\");
     var paths = new[] { @"c:\path" };
     _repl.Initialize(paths, new[] { _mocks.ScriptPack.Object });
 }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:8,代码来源:ReplTests.cs


示例15: ShouldReferenceAssemblyIfLineIsAReference

            public void ShouldReferenceAssemblyIfLineIsAReference()
            {
                var mocks = new Mocks();
                mocks.FileSystem.Setup(i => i.CurrentDirectory).Returns("C:/");
                mocks.FileSystem.Setup(i => i.GetFullPath(It.IsAny<string>())).Returns(@"c:/my.dll");
                mocks.FileSystem.Setup(x => x.FileExists("c:/my.dll")).Returns(true);
                mocks.FilePreProcessor.Setup(x => x.ProcessScript(It.IsAny<string>()))
                    .Returns(new FilePreProcessorResult { References = new List<string> { "my.dll" } });

                _repl = GetRepl(mocks);
                _repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>());
                _repl.Execute("#r \"my.dll\"");

                //default references = 6, + 1 we just added
                _repl.References.PathReferences.Count().ShouldEqual(7);
            }
开发者ID:Jaydeep7,项目名称:scriptcs,代码行数:16,代码来源:ReplTests.cs


示例16: ShouldReturnCommandsScriptResultfCommandHasReturnValueThatAlreadyIsScriptResult

            public void ShouldReturnCommandsScriptResultfCommandHasReturnValueThatAlreadyIsScriptResult()
            {
                var returnValue = new ScriptResult("hello world");

                var helloCommand = new Mock<IReplCommand>();
                helloCommand.SetupGet(x => x.CommandName).Returns("hello");
                helloCommand.Setup(x => x.Execute(It.IsAny<IRepl>(), It.IsAny<object[]>()))
                    .Returns(returnValue);

                var mocks = new Mocks { ReplCommands = new[] { helloCommand } };
                mocks.ObjectSerializer.Setup(x => x.Serialize(returnValue.ReturnValue)).Returns("hello world");

                _repl = GetRepl(mocks);

                var result = _repl.Execute(":hello", null);

                mocks.ObjectSerializer.Verify(x => x.Serialize(returnValue.ReturnValue), Times.Once);
                mocks.Console.Verify(x => x.WriteLine("hello world"), Times.Once);
                result.ShouldBeSameAs(returnValue);
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:20,代码来源:ReplTests.cs


示例17: TheInitializeMethod

            public TheInitializeMethod()
            {
                _tempPath = Path.GetTempPath();

                _mocks = new Mocks();
                _repl = GetRepl(_mocks);
                _mocks.FileSystem.Setup(x => x.CurrentDirectory).Returns(_tempPath);
                var paths = new[] { Path.Combine(_tempPath, "path") };
                _repl.Initialize(paths, new[] { _mocks.ScriptPack.Object });
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:10,代码来源:ReplTests.cs


示例18: ShouldPrintTheReturnToConsoleIfCommandHasReturnValue

            public void ShouldPrintTheReturnToConsoleIfCommandHasReturnValue()
            {
                object returnValue = new DummyClass { Hello = "World" };

                var helloCommand = new Mock<IReplCommand>();
                helloCommand.SetupGet(x => x.CommandName).Returns("hello");
                helloCommand.Setup(x => x.Execute(It.IsAny<IRepl>(), It.IsAny<object[]>()))
                    .Returns(returnValue);

                var mocks = new Mocks { ReplCommands = new[] { helloCommand } };
                mocks.ObjectSerializer.Setup(x => x.Serialize(returnValue)).Returns("hello world");

                _repl = GetRepl(mocks);

                _repl.Execute(":hello", null);

                mocks.ObjectSerializer.Verify(x => x.Serialize(returnValue), Times.Once);
                mocks.Console.Verify(x => x.WriteLine("hello world"), Times.Once);
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:19,代码来源:ReplTests.cs


示例19: ShouldSurfaceIncompleteArguments

            public void ShouldSurfaceIncompleteArguments()
            {
                var helloCommand = new Mock<IReplCommand>();
                helloCommand.SetupGet(x => x.CommandName).Returns("hello");

                var mocks = new Mocks { ReplCommands = new[] { helloCommand } };
                mocks.ScriptEngine.Setup(x => x.Execute(
                        It.IsAny<string>(),
                        It.IsAny<string[]>(),
                        It.IsAny<AssemblyReferences>(),
                        It.IsAny<IEnumerable<string>>(),
                        It.IsAny<ScriptPackSession>()))
                        .Returns(ScriptResult.Incomplete);

                _repl = GetRepl(mocks);

                var result = _repl.Execute(":hello foo", null);

                result.ExecuteExceptionInfo.SourceException.Message.ShouldContain(
                    "argument is not a valid expression: foo", StringComparison.OrdinalIgnoreCase);
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:21,代码来源:ReplTests.cs


示例20: ShouldEvaluateStrings

            public void ShouldEvaluateStrings()
            {
                var helloCommand = new Mock<IReplCommand>();
                helloCommand.SetupGet(x => x.CommandName).Returns("hello");

                var mocks = new Mocks { ReplCommands = new[] { helloCommand } };
                mocks.ScriptEngine.Setup(x => x.Execute(
                        "\"world\"",
                        It.IsAny<string[]>(),
                        It.IsAny<AssemblyReferences>(),
                        It.IsAny<IEnumerable<string>>(),
                        It.IsAny<ScriptPackSession>()))
                    .Returns(new ScriptResult(returnValue: "world"));

                _repl = GetRepl(mocks);

                _repl.Execute(":hello \"world\"", null);

                helloCommand.Verify(
                    x => x.Execute(
                        _repl,
                        It.Is<object[]>(i =>
                            i[0].GetType() == typeof(string) &&
                            (string)i[0] == "world")),
                    Times.Once);
            }
开发者ID:AsCloud,项目名称:scriptcs,代码行数:26,代码来源:ReplTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ReplaySubject类代码示例发布时间:2022-05-24
下一篇:
C# RepeaterItemEventArgs类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap