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


C# Repl类代码示例

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


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


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