本文整理汇总了C#中Repl.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Repl.Execute方法的具体用法?C# Repl.Execute怎么用?C# Repl.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Repl
的用法示例。
在下文中一共展示了Repl.Execute方法的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;
}
示例2: ExecuteLine
private bool ExecuteLine(Repl repl)
{
Console.Write("> ");
var line = Console.ReadLine();
if (line == "")
return false;
repl.Execute(line);
return true;
}
示例3: 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));
}
示例4: ShouldProcessFileIfLineIsALoad
public void ShouldProcessFileIfLineIsALoad()
{
var mocks = new Mocks();
_repl = GetRepl(mocks);
_repl.Execute("#load \"file.csx\"");
mocks.FilePreProcessor.Verify(i => i.ProcessFile(It.Is<string>(x => x == "file.csx")), Times.Once());
}
示例5: 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();
}
示例6: 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);
}
示例7: ShouldReferenceAssemblyBasedOnFullPathIfFileExists
public void ShouldReferenceAssemblyBasedOnFullPathIfFileExists()
{
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.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\"");
mocks.FileSystem.Verify(x => x.FileExists("C:/my.dll"), Times.Once());
}
示例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());
}
示例9: 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());
}
示例10: ShouldReferenceAssemblyBasedOnNameIfFileDoesNotExistBecauseItLooksInGACThen
public void ShouldReferenceAssemblyBasedOnNameIfFileDoesNotExistBecauseItLooksInGACThen()
{
var mocks = new Mocks();
mocks.FileSystem.Setup(i => i.CurrentDirectory).Returns("C:/");
mocks.FileSystem.Setup(i => i.FileExists(It.IsAny<string>())).Returns(false);
_repl = GetRepl(mocks);
_repl.Initialize(Enumerable.Empty<string>(), Enumerable.Empty<IScriptPack>());
_repl.Execute("#r \"PresentationCore\"");
_repl.References.Contains("PresentationCore").ShouldBeTrue();
}
示例11: ExecuteLine
private bool ExecuteLine(Repl repl)
{
_console.Write(string.IsNullOrWhiteSpace(repl.Buffer) ? "> " : "* ");
try
{
var line = _console.ReadLine();
if (!string.IsNullOrWhiteSpace(line))
{
repl.Execute(line);
}
return true;
}
catch
{
return false;
}
}
示例12: 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;
}
示例13: ExecuteLine
private bool ExecuteLine(Repl repl)
{
if (string.IsNullOrWhiteSpace(repl.Buffer))
{
_console.Write("> ");
}
string line = null;
try
{
line = _console.ReadLine();
}
catch
{
return false;
}
if (!string.IsNullOrWhiteSpace(line))
{
repl.Execute(line);
}
return true;
}
示例14: ShouldReferenceAssemblyIfLineIsAReference
public void ShouldReferenceAssemblyIfLineIsAReference()
{
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\"");
//default references = 6, + 1 we just added
_repl.References.Count().ShouldEqual(7);
}
示例15: 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);
}